Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 388d125

Browse filesBrowse files
wenningplusaddaleax
authored andcommitted
http: expose host and protocol on ClientRequest
Allow host and protocol to be inspected. PR-URL: #33803 Fixes: #2461 Reviewed-By: Robert Nagy <ronagy@icloud.com> Reviewed-By: Trivikram Kamat <trivikr.dev@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com>
1 parent be6aee9 commit 388d125
Copy full SHA for 388d125

File tree

Expand file treeCollapse file tree

3 files changed

+46
-0
lines changed
Open diff view settings
Filter options
Expand file treeCollapse file tree

3 files changed

+46
-0
lines changed
Open diff view settings
Collapse file

‎doc/api/http.md‎

Copy file name to clipboardExpand all lines: doc/api/http.md
+21Lines changed: 21 additions & 0 deletions
  • Display the source diff
  • Display the rich diff
Original file line numberDiff line numberDiff line change
@@ -688,6 +688,27 @@ added: v0.4.0
688688

689689
* {string} The request path.
690690

691+
### `request.method`
692+
<!-- YAML
693+
added: v0.1.97
694+
-->
695+
696+
* {string} The request method.
697+
698+
### `request.host`
699+
<!-- YAML
700+
added: REPLACEME
701+
-->
702+
703+
* {string} The request host.
704+
705+
### `request.protocol`
706+
<!-- YAML
707+
added: REPLACEME
708+
-->
709+
710+
* {string} The request protocol.
711+
691712
### `request.removeHeader(name)`
692713
<!-- YAML
693714
added: v1.6.0
Collapse file

‎lib/_http_client.js‎

Copy file name to clipboardExpand all lines: lib/_http_client.js
+2Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -213,6 +213,8 @@ function ClientRequest(input, options, cb) {
213213
this.parser = null;
214214
this.maxHeadersCount = null;
215215
this.reusedSocket = false;
216+
this.host = host;
217+
this.protocol = protocol;
216218

217219
let called = false;
218220

Collapse file

‎test/parallel/test-http-outgoing-properties.js‎

Copy file name to clipboardExpand all lines: test/parallel/test-http-outgoing-properties.js
+23Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,3 +51,26 @@ const OutgoingMessage = http.OutgoingMessage;
5151
msg.write('asd');
5252
assert.strictEqual(msg.writableLength, 7);
5353
}
54+
55+
{
56+
const server = http.createServer((req, res) => {
57+
res.end();
58+
server.close();
59+
});
60+
61+
server.listen(0);
62+
63+
server.on('listening', common.mustCall(() => {
64+
const req = http.request({
65+
port: server.address().port,
66+
method: 'GET',
67+
path: '/'
68+
});
69+
70+
assert.strictEqual(req.path, '/');
71+
assert.strictEqual(req.method, 'GET');
72+
assert.strictEqual(req.host, 'localhost');
73+
assert.strictEqual(req.protocol, 'http:');
74+
req.end();
75+
}));
76+
}

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.