@@ -24,9 +24,9 @@ if(! ('_object' in (new XHR)))
24
24
25
25
module . exports = request
26
26
request . XMLHttpRequest = XHR
27
+ request . log = getLogger ( )
27
28
28
29
var DEFAULT_TIMEOUT = 3 * 60 * 1000 // 3 minutes
29
- , LOG = getLogger ( )
30
30
31
31
//
32
32
// request
@@ -129,7 +129,7 @@ function run_xhr(options) {
129
129
er . code = 'ETIMEDOUT'
130
130
er . duration = options . timeout
131
131
132
- LOG . error ( 'Timeout' , { 'id' :xhr . _id , 'milliseconds' :options . timeout } )
132
+ request . log . error ( 'Timeout' , { 'id' :xhr . _id , 'milliseconds' :options . timeout } )
133
133
return options . callback ( er , xhr )
134
134
}
135
135
@@ -145,12 +145,12 @@ function run_xhr(options) {
145
145
146
146
function on_state_change ( event ) {
147
147
if ( timed_out )
148
- return LOG . debug ( 'Ignoring timed out state change' , { 'state' :xhr . readyState , 'id' :xhr . id } )
148
+ return request . log . debug ( 'Ignoring timed out state change' , { 'state' :xhr . readyState , 'id' :xhr . id } )
149
149
150
- LOG . debug ( 'State change' , { 'state' :xhr . readyState , 'id' :xhr . id , 'timed_out' :timed_out } )
150
+ request . log . debug ( 'State change' , { 'state' :xhr . readyState , 'id' :xhr . id , 'timed_out' :timed_out } )
151
151
152
152
if ( xhr . readyState === XHR . OPENED ) {
153
- LOG . debug ( 'Request started' , { 'id' :xhr . id } )
153
+ request . log . debug ( 'Request started' , { 'id' :xhr . id } )
154
154
for ( var key in options . headers )
155
155
xhr . setRequestHeader ( key , options . headers [ key ] )
156
156
}
@@ -175,7 +175,7 @@ function run_xhr(options) {
175
175
return
176
176
177
177
did . response = true
178
- LOG . debug ( 'Got response' , { 'id' :xhr . id , 'status' :xhr . status } )
178
+ request . log . debug ( 'Got response' , { 'id' :xhr . id , 'status' :xhr . status } )
179
179
clearTimeout ( xhr . timeoutTimer )
180
180
xhr . statusCode = xhr . status // Node request compatibility
181
181
@@ -199,7 +199,7 @@ function run_xhr(options) {
199
199
return
200
200
201
201
did . loading = true
202
- LOG . debug ( 'Response body loading' , { 'id' :xhr . id } )
202
+ request . log . debug ( 'Response body loading' , { 'id' :xhr . id } )
203
203
// TODO: Maybe simulate "data" events by watching xhr.responseText
204
204
}
205
205
@@ -208,7 +208,7 @@ function run_xhr(options) {
208
208
return
209
209
210
210
did . end = true
211
- LOG . debug ( 'Request done' , { 'id' :xhr . id } )
211
+ request . log . debug ( 'Request done' , { 'id' :xhr . id } )
212
212
213
213
xhr . body = xhr . responseText
214
214
if ( options . json ) {
0 commit comments