Browse Source

docs: http protocol handlers can access headers (#15431)

* test: check http protocol handlers can access headers

* docs: http protocol handlers can access headers
David Sanders 6 years ago
parent
commit
bae652f46d
2 changed files with 25 additions and 0 deletions
  1. 2 0
      docs/api/protocol.md
  2. 23 0
      spec/api-protocol-spec.js

+ 2 - 0
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)

+ 23 - 0
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', () => {