Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
seleniumhq
GitHub Repository: seleniumhq/selenium
Path: blob/trunk/third_party/closure/goog/net/channeldebug.js
2868 views
1
// Copyright 2006 The Closure Library Authors. All Rights Reserved.
2
//
3
// Licensed under the Apache License, Version 2.0 (the "License");
4
// you may not use this file except in compliance with the License.
5
// You may obtain a copy of the License at
6
//
7
// http://www.apache.org/licenses/LICENSE-2.0
8
//
9
// Unless required by applicable law or agreed to in writing, software
10
// distributed under the License is distributed on an "AS-IS" BASIS,
11
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
// See the License for the specific language governing permissions and
13
// limitations under the License.
14
15
/**
16
* @fileoverview Definition of the ChannelDebug class. ChannelDebug provides
17
* a utility for tracing and debugging the BrowserChannel requests.
18
*
19
*/
20
21
22
/**
23
* Namespace for BrowserChannel
24
*/
25
goog.provide('goog.net.ChannelDebug');
26
27
goog.require('goog.json');
28
goog.require('goog.log');
29
30
31
32
/**
33
* Logs and keeps a buffer of debugging info for the Channel.
34
*
35
* @constructor
36
*/
37
goog.net.ChannelDebug = function() {
38
/**
39
* The logger instance.
40
* @const
41
* @private {?goog.debug.Logger}
42
*/
43
this.logger_ = goog.log.getLogger('goog.net.BrowserChannel');
44
};
45
46
47
/**
48
* Gets the logger used by this ChannelDebug.
49
* @return {goog.debug.Logger} The logger used by this ChannelDebug.
50
*/
51
goog.net.ChannelDebug.prototype.getLogger = function() {
52
return this.logger_;
53
};
54
55
56
/**
57
* Logs that the browser went offline during the lifetime of a request.
58
* @param {goog.Uri} url The URL being requested.
59
*/
60
goog.net.ChannelDebug.prototype.browserOfflineResponse = function(url) {
61
this.info('BROWSER_OFFLINE: ' + url);
62
};
63
64
65
/**
66
* Logs an XmlHttp request..
67
* @param {string} verb The request type (GET/POST).
68
* @param {goog.Uri} uri The request destination.
69
* @param {string|number|undefined} id The request id.
70
* @param {number} attempt Which attempt # the request was.
71
* @param {?string} postData The data posted in the request.
72
*/
73
goog.net.ChannelDebug.prototype.xmlHttpChannelRequest = function(
74
verb, uri, id, attempt, postData) {
75
this.info(
76
'XMLHTTP REQ (' + id + ') [attempt ' + attempt + ']: ' + verb + '\n' +
77
uri + '\n' + this.maybeRedactPostData_(postData));
78
};
79
80
81
/**
82
* Logs the meta data received from an XmlHttp request.
83
* @param {string} verb The request type (GET/POST).
84
* @param {goog.Uri} uri The request destination.
85
* @param {string|number|undefined} id The request id.
86
* @param {number} attempt Which attempt # the request was.
87
* @param {goog.net.XmlHttp.ReadyState} readyState The ready state.
88
* @param {number} statusCode The HTTP status code.
89
*/
90
goog.net.ChannelDebug.prototype.xmlHttpChannelResponseMetaData = function(
91
verb, uri, id, attempt, readyState, statusCode) {
92
this.info(
93
'XMLHTTP RESP (' + id + ') [ attempt ' + attempt + ']: ' + verb + '\n' +
94
uri + '\n' + readyState + ' ' + statusCode);
95
};
96
97
98
/**
99
* Logs the response data received from an XmlHttp request.
100
* @param {string|number|undefined} id The request id.
101
* @param {?string} responseText The response text.
102
* @param {?string=} opt_desc Optional request description.
103
*/
104
goog.net.ChannelDebug.prototype.xmlHttpChannelResponseText = function(
105
id, responseText, opt_desc) {
106
this.info(
107
'XMLHTTP TEXT (' + id + '): ' + this.redactResponse_(responseText) +
108
(opt_desc ? ' ' + opt_desc : ''));
109
};
110
111
112
/**
113
* Logs a Trident ActiveX request.
114
* @param {string} verb The request type (GET/POST).
115
* @param {goog.Uri} uri The request destination.
116
* @param {string|number|undefined} id The request id.
117
* @param {number} attempt Which attempt # the request was.
118
*/
119
goog.net.ChannelDebug.prototype.tridentChannelRequest = function(
120
verb, uri, id, attempt) {
121
this.info(
122
'TRIDENT REQ (' + id + ') [ attempt ' + attempt + ']: ' + verb + '\n' +
123
uri);
124
};
125
126
127
/**
128
* Logs the response text received from a Trident ActiveX request.
129
* @param {string|number|undefined} id The request id.
130
* @param {string} responseText The response text.
131
*/
132
goog.net.ChannelDebug.prototype.tridentChannelResponseText = function(
133
id, responseText) {
134
this.info('TRIDENT TEXT (' + id + '): ' + this.redactResponse_(responseText));
135
};
136
137
138
/**
139
* Logs the done response received from a Trident ActiveX request.
140
* @param {string|number|undefined} id The request id.
141
* @param {boolean} successful Whether the request was successful.
142
*/
143
goog.net.ChannelDebug.prototype.tridentChannelResponseDone = function(
144
id, successful) {
145
this.info('TRIDENT TEXT (' + id + '): ' + successful ? 'success' : 'failure');
146
};
147
148
149
/**
150
* Logs a request timeout.
151
* @param {goog.Uri} uri The uri that timed out.
152
*/
153
goog.net.ChannelDebug.prototype.timeoutResponse = function(uri) {
154
this.info('TIMEOUT: ' + uri);
155
};
156
157
158
/**
159
* Logs a debug message.
160
* @param {string} text The message.
161
*/
162
goog.net.ChannelDebug.prototype.debug = function(text) {
163
this.info(text);
164
};
165
166
167
/**
168
* Logs an exception
169
* @param {Error} e The error or error event.
170
* @param {string=} opt_msg The optional message, defaults to 'Exception'.
171
*/
172
goog.net.ChannelDebug.prototype.dumpException = function(e, opt_msg) {
173
this.severe((opt_msg || 'Exception') + e);
174
};
175
176
177
/**
178
* Logs an info message.
179
* @param {string} text The message.
180
*/
181
goog.net.ChannelDebug.prototype.info = function(text) {
182
goog.log.info(this.logger_, text);
183
};
184
185
186
/**
187
* Logs a warning message.
188
* @param {string} text The message.
189
*/
190
goog.net.ChannelDebug.prototype.warning = function(text) {
191
goog.log.warning(this.logger_, text);
192
};
193
194
195
/**
196
* Logs a severe message.
197
* @param {string} text The message.
198
*/
199
goog.net.ChannelDebug.prototype.severe = function(text) {
200
goog.log.error(this.logger_, text);
201
};
202
203
204
/**
205
* Removes potentially private data from a response so that we don't
206
* accidentally save private and personal data to the server logs.
207
* @param {?string} responseText A JSON response to clean.
208
* @return {?string} The cleaned response.
209
* @private
210
*/
211
goog.net.ChannelDebug.prototype.redactResponse_ = function(responseText) {
212
// first check if it's not JS - the only non-JS should be the magic cookie
213
if (!responseText ||
214
responseText == goog.net.ChannelDebug.MAGIC_RESPONSE_COOKIE) {
215
return responseText;
216
}
217
218
try {
219
var responseArray = JSON.parse(responseText);
220
if (responseArray) {
221
for (var i = 0; i < responseArray.length; i++) {
222
if (goog.isArray(responseArray[i])) {
223
this.maybeRedactArray_(responseArray[i]);
224
}
225
}
226
}
227
228
return goog.json.serialize(responseArray);
229
} catch (e) {
230
this.debug('Exception parsing expected JS array - probably was not JS');
231
return responseText;
232
}
233
};
234
235
236
/**
237
* Removes data from a response array that may be sensitive.
238
* @param {Array<?>} array The array to clean.
239
* @private
240
*/
241
goog.net.ChannelDebug.prototype.maybeRedactArray_ = function(array) {
242
if (array.length < 2) {
243
return;
244
}
245
var dataPart = array[1];
246
if (!goog.isArray(dataPart)) {
247
return;
248
}
249
if (dataPart.length < 1) {
250
return;
251
}
252
253
var type = dataPart[0];
254
if (type != 'noop' && type != 'stop') {
255
// redact all fields in the array
256
for (var i = 1; i < dataPart.length; i++) {
257
dataPart[i] = '';
258
}
259
}
260
};
261
262
263
/**
264
* Removes potentially private data from a request POST body so that we don't
265
* accidentally save private and personal data to the server logs.
266
* @param {?string} data The data string to clean.
267
* @return {?string} The data string with sensitive data replaced by 'redacted'.
268
* @private
269
*/
270
goog.net.ChannelDebug.prototype.maybeRedactPostData_ = function(data) {
271
if (!data) {
272
return null;
273
}
274
var out = '';
275
var params = data.split('&');
276
for (var i = 0; i < params.length; i++) {
277
var param = params[i];
278
var keyValue = param.split('=');
279
if (keyValue.length > 1) {
280
var key = keyValue[0];
281
var value = keyValue[1];
282
283
var keyParts = key.split('_');
284
if (keyParts.length >= 2 && keyParts[1] == 'type') {
285
out += key + '=' + value + '&';
286
} else {
287
out += key + '=' +
288
'redacted' +
289
'&';
290
}
291
}
292
}
293
return out;
294
};
295
296
297
/**
298
* The normal response for forward channel requests.
299
* Used only before version 8 of the protocol.
300
* @const
301
*/
302
goog.net.ChannelDebug.MAGIC_RESPONSE_COOKIE = 'y2f%';
303
304