Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

http:ClientRequest return host、protocol #33803

Closed
wants to merge 7 commits into from
Closed
Show file tree
Hide file tree
Changes from 4 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
29 changes: 29 additions & 0 deletions doc/api/http.md
Original file line number Diff line number Diff line change
Expand Up @@ -744,6 +744,35 @@ added: v0.4.0

* {string} The request path.

### `request.method`
<!-- YAML
added: v0.1.97
-->

* {string} The request method.

### `request.host`
<!-- YAML
added: REPLACEME
changes:
zhangwinning marked this conversation as resolved.
Show resolved Hide resolved
- version: REPLACEME
pr-url: https://github.com/nodejs/node/pull/33803
description: exposed host property.
-->

* {string} The request host.

### `request.protocol`
<!-- YAML
added: REPLACEME
changes:
- version: REPLACEME
pr-url: https://github.com/nodejs/node/pull/33803
description: exposed protocol property.
-->

* {string} The request protocol.

### `request.removeHeader(name)`
<!-- YAML
added: v1.6.0
Expand Down
2 changes: 2 additions & 0 deletions lib/_http_client.js
Original file line number Diff line number Diff line change
Expand Up @@ -221,6 +221,8 @@ function ClientRequest(input, options, cb) {
this.parser = null;
this.maxHeadersCount = null;
this.reusedSocket = false;
this.host = host;
this.protocol = protocol;

let called = false;

Expand Down
23 changes: 23 additions & 0 deletions test/parallel/test-http-outgoing-properties.js
Original file line number Diff line number Diff line change
Expand Up @@ -51,3 +51,26 @@ const OutgoingMessage = http.OutgoingMessage;
msg.write('asd');
assert.strictEqual(msg.writableLength, 7);
}

{
const server = http.createServer(function(req, res) {
zhangwinning marked this conversation as resolved.
Show resolved Hide resolved
res.end();
server.close();
});

server.listen(0);

server.on('listening', common.mustCall(function() {
zhangwinning marked this conversation as resolved.
Show resolved Hide resolved
const req = http.request({
port: server.address().port,
method: 'GET',
path: '/'
});

assert.strictEqual(req.path, '/');
assert.strictEqual(req.method, 'GET');
assert.strictEqual(req.host, 'localhost');
assert.strictEqual(req.protocol, 'http:');
req.end();
}));
}