| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
1 parent febd969 commit 075b36b
5 files changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -3848,8 +3848,13 @@ changes: | |||
| 3848 | 3848 | * `port` {number} Port of remote server. **Default:** `defaultPort` if set, | |
| 3849 | 3849 | else `80`. | |
| 3850 | 3850 | * `protocol` {string} Protocol to use. **Default:** `'http:'`. | |
| 3851 | + * `setDefaultHeaders` {boolean}: Specifies whether or not to automatically add | ||
| 3852 | + default headers such as `Connection`, `Content-Length`, `Transfer-Encoding`, | ||
| 3853 | + and `Host`. If set to `false` then all necessary headers must be added | ||
| 3854 | + manually. Defaults to `true`. | ||
| 3851 | 3855 | * `setHost` {boolean}: Specifies whether or not to automatically add the | |
| 3852 | - `Host` header. Defaults to `true`. | ||
| 3856 | + `Host` header. If provided, this overrides `setDefaultHeaders`. Defaults to | ||
| 3857 | + `true`. | ||
| 3853 | 3858 | * `signal` {AbortSignal}: An AbortSignal that may be used to abort an ongoing | |
| 3854 | 3859 | request. | |
| 3855 | 3860 | * `socketPath` {string} Unix domain socket. Cannot be used if one of `host` | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -199,7 +199,13 @@ function ClientRequest(input, options, cb) { | |||
| 199 | 199 | const host = optsWithoutSignal.host = validateHost(options.hostname, 'hostname') || | |
| 200 | 200 | validateHost(options.host, 'host') || 'localhost'; | |
| 201 | 201 | ||
| 202 | - const setHost = (options.setHost === undefined || Boolean(options.setHost)); | ||
| 202 | + const setHost = options.setHost !== undefined ? | ||
| 203 | + Boolean(options.setHost) : | ||
| 204 | + options.setDefaultHeaders !== false; | ||
| 205 | + | ||
| 206 | + this._removedConnection = options.setDefaultHeaders === false; | ||
| 207 | + this._removedContLen = options.setDefaultHeaders === false; | ||
| 208 | + this._removedTE = options.setDefaultHeaders === false; | ||
| 203 | 209 | ||
| 204 | 210 | this.socketPath = options.socketPath; | |
| 205 | 211 | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -0,0 +1,33 @@ | |||
| 1 | + 'use strict'; | ||
| 2 | + | ||
| 3 | + const common = require('../common'); | ||
| 4 | + const assert = require('assert'); | ||
| 5 | + const http = require('http'); | ||
| 6 | + | ||
| 7 | + const server = http.createServer(common.mustCall(function(req, res) { | ||
| 8 | + assert.deepStrictEqual(req.rawHeaders, [ | ||
| 9 | + 'test', 'value', | ||
| 10 | + 'HOST', `127.0.0.1:${server.address().port}`, | ||
| 11 | + 'foo', 'bar', | ||
| 12 | + 'foo', 'baz', | ||
| 13 | + 'connection', 'close', | ||
| 14 | + ]); | ||
| 15 | + | ||
| 16 | + res.end('ok'); | ||
| 17 | + server.close(); | ||
| 18 | + })); | ||
| 19 | + server.listen(0, common.localhostIPv4, function() { | ||
| 20 | + const req = http.request({ | ||
| 21 | + method: 'POST', | ||
| 22 | + host: common.localhostIPv4, | ||
| 23 | + port: this.address().port, | ||
| 24 | + setDefaultHeaders: false, | ||
| 25 | + }); | ||
| 26 | + | ||
| 27 | + req.setHeader('test', 'value'); | ||
| 28 | + req.setHeader('HOST', `${common.localhostIPv4}:${server.address().port}`); | ||
| 29 | + req.setHeader('foo', ['bar', 'baz']); | ||
| 30 | + req.setHeader('connection', 'close'); | ||
| 31 | + | ||
| 32 | + req.end(); | ||
| 33 | + }); | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -0,0 +1,23 @@ | |||
| 1 | + 'use strict'; | ||
| 2 | + | ||
| 3 | + const common = require('../common'); | ||
| 4 | + const assert = require('assert'); | ||
| 5 | + const http = require('http'); | ||
| 6 | + | ||
| 7 | + const server = http.createServer(common.mustCall(function(req, res) { | ||
| 8 | + assert.deepStrictEqual(req.rawHeaders, [ | ||
| 9 | + 'Host', `${common.localhostIPv4}:${server.address().port}`, | ||
| 10 | + ]); | ||
| 11 | + | ||
| 12 | + res.end('ok'); | ||
| 13 | + server.close(); | ||
| 14 | + })); | ||
| 15 | + server.listen(0, common.localhostIPv4, function() { | ||
| 16 | + http.request({ | ||
| 17 | + method: 'POST', | ||
| 18 | + host: common.localhostIPv4, | ||
| 19 | + port: this.address().port, | ||
| 20 | + setDefaultHeaders: false, | ||
| 21 | + setHost: true | ||
| 22 | + }).end(); | ||
| 23 | + }); | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -0,0 +1,31 @@ | |||
| 1 | + 'use strict'; | ||
| 2 | + | ||
| 3 | + const common = require('../common'); | ||
| 4 | + const assert = require('assert'); | ||
| 5 | + const http = require('http'); | ||
| 6 | + | ||
| 7 | + const server = http.createServer(common.mustCall(function(req, res) { | ||
| 8 | + assert.deepStrictEqual(req.rawHeaders, [ | ||
| 9 | + 'host', `${common.localhostIPv4}:${server.address().port}`, | ||
| 10 | + 'foo', 'bar', | ||
| 11 | + 'test', 'value', | ||
| 12 | + 'foo', 'baz', | ||
| 13 | + ]); | ||
| 14 | + | ||
| 15 | + res.end('ok'); | ||
| 16 | + server.close(); | ||
| 17 | + })); | ||
| 18 | + server.listen(0, common.localhostIPv4, function() { | ||
| 19 | + http.request({ | ||
| 20 | + method: 'POST', | ||
| 21 | + host: common.localhostIPv4, | ||
| 22 | + port: this.address().port, | ||
| 23 | + setDefaultHeaders: false, | ||
| 24 | + headers: [ | ||
| 25 | + 'host', `${common.localhostIPv4}:${server.address().port}`, | ||
| 26 | + 'foo', 'bar', | ||
| 27 | + 'test', 'value', | ||
| 28 | + 'foo', 'baz', | ||
| 29 | + ] | ||
| 30 | + }).end(); | ||
| 31 | + }); | ||
| Back | FazBrowse Home | New Git URL |
0 commit comments