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 2 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
33 changes: 33 additions & 0 deletions doc/api/http.md
Original file line number Diff line number Diff line change
Expand Up @@ -744,6 +744,39 @@ added: v0.4.0

* {string} The request path.

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

* {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
25 changes: 25 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,28 @@ 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();
res.on('finish', () => {
server.close();
zhangwinning marked this conversation as resolved.
Show resolved Hide resolved
});
});

server.listen(0);

server.on('listening', 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();
});
}