lib/request.js
'use strict';
const http = require('http');
module.exports = class ServerlessRequest extends http.IncomingMessage {
constructor({ method, url, headers, body, remoteAddress }) {
super({
encrypted: true,
readable: false,
remoteAddress,
address: () => ({ port: 443 }),
end: Function.prototype,
destroy: Function.prototype
});
if (typeof headers['content-length'] === 'undefined') {
headers['content-length'] = Buffer.byteLength(body);
}
Object.assign(this, {
ip: remoteAddress,
complete: true,
httpVersion: '1.1',
httpVersionMajor: '1',
httpVersionMinor: '1',
method,
headers,
body,
url,
});
this._read = () => {
this.push(body);
this.push(null);
};
}
}