Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions __tests__/unit.js
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,14 @@ test('getRequestResponse: without headers', async () => {
})
})

test('ServerlessRequest socket exposes EventEmitter methods', async () => {
const { request } = await getReqRes()
expect(typeof request.socket.on).toBe('function')
expect(typeof request.socket.once).toBe('function')
expect(typeof request.socket.emit).toBe('function')
expect(typeof request.socket.removeListener).toBe('function')
})

describe('respondToEventSourceWithError', () => {
test('responds with 500 status', () => {
return new Promise(
Expand Down
16 changes: 8 additions & 8 deletions src/request.js
Original file line number Diff line number Diff line change
@@ -1,19 +1,19 @@
// ATTRIBUTION: https://github.com/dougmoscrop/serverless-http

const http = require('http')
const { PassThrough } = require('stream')

const HTTPS_PORT = 443

module.exports = class ServerlessRequest extends http.IncomingMessage {
constructor ({ method, url, headers, body, remoteAddress }) {
super({
encrypted: true,
readable: true,
remoteAddress,
address: () => ({ port: HTTPS_PORT }),
end: Function.prototype,
destroy: Function.prototype
})
const socket = new PassThrough()
socket.encrypted = true
socket.readable = true
socket.remoteAddress = remoteAddress
socket.address = () => ({ port: HTTPS_PORT })

super(socket)

// IncomingMessage has a lot of logic for when to lowercase or alias well-known header names,
// so we delegate to that logic here
Expand Down