Adding basic http tests, fixing issues in ClientRequest constructor.

This commit is contained in:
ali.ibrahim 2016-10-07 11:07:49 +02:00
parent 046f48db51
commit 9b94dfcbdc
2 changed files with 202 additions and 42 deletions

View file

@ -59,6 +59,14 @@ class IncomingMessage extends Readable {
return this._url_request.rawResponseHeaders
}
get rawTrailers() {
throw (new Error('HTTP trailers are not supported.'))
}
get trailers() {
throw (new Error('HTTP trailers are not supported.'))
}
_storeInternalData(chunk) {
this._data.push(chunk)
}
@ -113,7 +121,7 @@ class ClientRequest extends EventEmitter {
if (!urlStr) {
let urlObj = {}
const protocol = options.protocol || 'http'
const protocol = options.protocol || 'http:'
if (!kSupportedProtocols.has(protocol)) {
throw new Error('Protocol "' + protocol + '" not supported. ')
}
@ -133,7 +141,6 @@ class ClientRequest extends EventEmitter {
}
}
const path = options.path || '/'
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
@ -143,7 +150,9 @@ class ClientRequest extends EventEmitter {
// an invalid request.
throw new TypeError('Request path contains unescaped characters.')
}
urlObj.path = path
urlObj.pathname = options.pathname || '/'
urlObj.search = options.search
urlObj.hash = options.hash
urlStr = url.format(urlObj)
}
@ -252,10 +261,6 @@ class ClientRequest extends EventEmitter {
chunk = Buffer.from(chunk, encoding)
}
// Headers are assumed to be sent on first call to _writeBuffer,
// i.e. after the first call to write or end.
let result = this._url_request.write(chunk, isLast)
// Since writing to the network is asynchronous, we conservatively
// assume that request headers are written after delivering the first
// buffer to the network IO thread.
@ -263,6 +268,10 @@ class ClientRequest extends EventEmitter {
this._url_request.setChunkedUpload(this.chunkedEncoding)
}
// Headers are assumed to be sent on first call to _writeBuffer,
// i.e. after the first call to write or end.
let result = this._url_request.write(chunk, isLast)
// The write callback is fired asynchronously to mimic Node.js.
if (callback) {
process.nextTick(callback)