light-my-request
Advanced tools
Comparing version 5.5.1 to 5.6.0
@@ -48,2 +48,8 @@ 'use strict' | ||
// Express.js detection | ||
if (dispatchFunc.request && dispatchFunc.request.app === dispatchFunc) { | ||
Object.setPrototypeOf(Object.getPrototypeOf(dispatchFunc.request), RequestConstructor.prototype) | ||
Object.setPrototypeOf(Object.getPrototypeOf(dispatchFunc.response), Response.prototype) | ||
} | ||
if (typeof callback === 'function') { | ||
@@ -50,0 +56,0 @@ const req = new RequestConstructor(options) |
@@ -166,3 +166,3 @@ 'use strict' | ||
// Set the content-length for the corresponding payload if none set | ||
if (payload && !payloadResume && !this.headers.hasOwnProperty('content-length')) { | ||
if (payload && !payloadResume && !Object.prototype.hasOwnProperty.call(this.headers, 'content-length')) { | ||
this.headers['content-length'] = (Buffer.isBuffer(payload) ? payload.length : Buffer.byteLength(payload)).toString() | ||
@@ -169,0 +169,0 @@ } |
@@ -65,4 +65,13 @@ 'use strict' | ||
copyHeaders(this) | ||
this._lightMyRequest.headers = Object.assign({}, this.getHeaders()) | ||
// Add raw headers | ||
;['Date', 'Connection', 'Transfer-Encoding'].forEach((name) => { | ||
const regex = new RegExp('\\r\\n' + name + ': ([^\\r]*)\\r\\n') | ||
const field = this._header.match(regex) | ||
if (field) { | ||
this._lightMyRequest.headers[name.toLowerCase()] = field[1] | ||
} | ||
}) | ||
return result | ||
@@ -113,5 +122,2 @@ } | ||
function generatePayload (response) { | ||
if (response._lightMyRequest.headers === null) { | ||
copyHeaders(response) | ||
} | ||
// Prepare response object | ||
@@ -160,15 +166,2 @@ const res = { | ||
function copyHeaders (response) { | ||
response._lightMyRequest.headers = Object.assign({}, response.getHeaders()) | ||
// Add raw headers | ||
;['Date', 'Connection', 'Transfer-Encoding'].forEach((name) => { | ||
const regex = new RegExp('\\r\\n' + name + ': ([^\\r]*)\\r\\n') | ||
const field = response._header.match(regex) | ||
if (field) { | ||
response._lightMyRequest.headers[name.toLowerCase()] = field[1] | ||
} | ||
}) | ||
} | ||
module.exports = Response |
{ | ||
"name": "light-my-request", | ||
"version": "5.5.1", | ||
"version": "5.6.0", | ||
"description": "Fake HTTP injection library", | ||
@@ -24,3 +24,3 @@ "main": "index.js", | ||
"tap": "^16.0.0", | ||
"tsd": "^0.22.0" | ||
"tsd": "^0.23.0" | ||
}, | ||
@@ -27,0 +27,0 @@ "scripts": { |
@@ -7,3 +7,5 @@ import * as http from 'http' | ||
const dispatch = function (req: http.IncomingMessage, res: http.ServerResponse) { | ||
const dispatch: http.RequestListener = function (req, res) { | ||
expectAssignable<http.IncomingMessage>(req) | ||
expectAssignable<http.ServerResponse>(res) | ||
expectType<boolean>(isInjection(req)) | ||
@@ -10,0 +12,0 @@ expectType<boolean>(isInjection(res)) |
@@ -1952,1 +1952,17 @@ 'use strict' | ||
}) | ||
test("passes payload when using express' send", (t) => { | ||
t.plan(3) | ||
const app = express() | ||
app.get('/hello', (req, res) => { | ||
res.send('some text') | ||
}) | ||
inject(app, { method: 'GET', url: 'http://example.com:8080/hello' }, (err, res) => { | ||
t.error(err) | ||
t.equal(res.headers['content-length'], '9') | ||
t.equal(res.payload, 'some text') | ||
}) | ||
}) |
116635
3531