Adding abort, webRequest interception and creation tests.
This commit is contained in:
parent
b731ca50bc
commit
a5c508d2d7
2 changed files with 387 additions and 51 deletions
|
@ -98,7 +98,7 @@ URLRequest.prototype._emitRequestEvent = function (async, ...rest) {
|
|||
URLRequest.prototype._emitResponseEvent = function (async, ...rest) {
|
||||
if (async) {
|
||||
process.nextTick(() => {
|
||||
this._request.emit.apply(this._request, rest)
|
||||
this._request.emit.apply(this._response, rest)
|
||||
})
|
||||
} else {
|
||||
this._response.emit.apply(this._response, rest)
|
||||
|
@ -141,6 +141,7 @@ class ClientRequest extends EventEmitter {
|
|||
}
|
||||
}
|
||||
|
||||
|
||||
if (options.path && / /.test(options.path)) {
|
||||
// The actual regex is more like /[^A-Za-z0-9\-._~!$&'()*+,;=/:@]/
|
||||
// with an additional rule for ignoring percentage-escaped characters
|
||||
|
@ -149,10 +150,11 @@ class ClientRequest extends EventEmitter {
|
|||
// why it only scans for spaces because those are guaranteed to create
|
||||
// an invalid request.
|
||||
throw new TypeError('Request path contains unescaped characters.')
|
||||
}
|
||||
urlObj.pathname = options.pathname || '/'
|
||||
urlObj.search = options.search
|
||||
urlObj.hash = options.hash
|
||||
}
|
||||
let pathObj = url.parse(options.path || '/')
|
||||
urlObj.pathname = pathObj.pathname
|
||||
urlObj.search = pathObj.search
|
||||
urlObj.hash = pathObj.hash
|
||||
urlStr = url.format(urlObj)
|
||||
}
|
||||
|
||||
|
@ -167,6 +169,11 @@ class ClientRequest extends EventEmitter {
|
|||
this._url_request = urlRequest
|
||||
urlRequest._request = this
|
||||
|
||||
// This is a copy of the extra headers structure held by the native
|
||||
// net::URLRequest. The main reason is to keep the getHeader API synchronous
|
||||
// after the request starts.
|
||||
this._extra_headers = {}
|
||||
|
||||
if (options.headers) {
|
||||
const keys = Object.keys(options.headers)
|
||||
for (let i = 0, l = keys.length; i < l; i++) {
|
||||
|
@ -179,11 +186,6 @@ class ClientRequest extends EventEmitter {
|
|||
// to true only once and never set back to false.
|
||||
this._chunkedEncoding = false
|
||||
|
||||
// This is a copy of the extra headers structure held by the native
|
||||
// net::URLRequest. The main reason is to keep the getHeader API synchronous
|
||||
// after the request starts.
|
||||
this._extra_headers = {}
|
||||
|
||||
urlRequest.on('response', () => {
|
||||
const response = new IncomingMessage(urlRequest)
|
||||
urlRequest._response = response
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue