From bae652f46d3f40dd6db2f86e13f24804acb4bc80 Mon Sep 17 00:00:00 2001 From: David Sanders Date: Tue, 30 Oct 2018 12:37:49 -0600 Subject: [PATCH] docs: http protocol handlers can access headers (#15431) * test: check http protocol handlers can access headers * docs: http protocol handlers can access headers --- docs/api/protocol.md | 2 ++ spec/api-protocol-spec.js | 23 +++++++++++++++++++++++ 2 files changed, 25 insertions(+) diff --git a/docs/api/protocol.md b/docs/api/protocol.md index 4d19869ceab75..5220066143b7e 100644 --- a/docs/api/protocol.md +++ b/docs/api/protocol.md @@ -169,6 +169,7 @@ should be called with either a `String` or an object that has the `data`, * `handler` Function * `request` Object * `url` String + * `headers` Object * `referrer` String * `method` String * `uploadData` [UploadData[]](structures/upload-data.md) @@ -329,6 +330,7 @@ which sends a `Buffer` as a response. * `handler` Function * `request` Object * `url` String + * `headers` Object * `referrer` String * `method` String * `uploadData` [UploadData[]](structures/upload-data.md) diff --git a/spec/api-protocol-spec.js b/spec/api-protocol-spec.js index 630d380797f19..55ec69e925810 100644 --- a/spec/api-protocol-spec.js +++ b/spec/api-protocol-spec.js @@ -475,6 +475,19 @@ describe('protocol module', () => { }) }) }) + + it('can access request headers', (done) => { + const handler = (request) => { + assert.ok('headers' in request) + done() + } + protocol.registerHttpProtocol(protocolName, handler, () => { + $.ajax({ + url: protocolName + '://fake-host', + cache: false + }) + }) + }) }) describe('protocol.registerStreamProtocol', () => { @@ -897,6 +910,16 @@ describe('protocol module', () => { }) }) }) + + it('can access request headers', (done) => { + const handler = (request) => { + assert.ok('headers' in request) + done() + } + protocol.interceptHttpProtocol('http', handler, () => { + fetch('http://fake-host') + }) + }) }) describe('protocol.interceptStreamProtocol', () => {