Skip to content

Commit ddc441f

Browse files
committed
http: replace superfluous connection property with getter/setter
1 parent 885c644 commit ddc441f

File tree

7 files changed

+71
-17
lines changed

7 files changed

+71
-17
lines changed

doc/api/deprecations.md

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2500,6 +2500,20 @@ Type: Runtime
25002500
Passing a callback to [`worker.terminate()`][] is deprecated. Use the returned
25012501
`Promise` instead, or a listener to the worker’s `'exit'` event.
25022502
2503+
<a id="DEP0XXX"></a>
2504+
### DEP0XXX: http connection
2505+
<!-- YAML
2506+
changes:
2507+
- version: REPLACEME
2508+
pr-url: https://github.com/nodejs/node/pull/29015
2509+
description: Documentation-only deprecation.
2510+
-->
2511+
2512+
Type: Documentation-only
2513+
2514+
Prefer [`response.socket`][] over [`response.connection`] and
2515+
[`request.socket`][] over [`request.connection`].
2516+
25032517
[`--http-parser=legacy`]: cli.html#cli_http_parser_library
25042518
[`--pending-deprecation`]: cli.html#cli_pending_deprecation
25052519
[`--throw-deprecation`]: cli.html#cli_throw_deprecation
@@ -2555,6 +2569,10 @@ Passing a callback to [`worker.terminate()`][] is deprecated. Use the returned
25552569
[`process.env`]: process.html#process_process_env
25562570
[`punycode`]: punycode.html
25572571
[`require.extensions`]: modules.html#modules_require_extensions
2572+
[`request.socket`]: http.html#http_request_socket
2573+
[`request.connection`]: http.html#http_request_connection
2574+
[`response.socket`]: http.html#http_response_socket
2575+
[`response.connection`]: http.html#http_response_connection
25582576
[`script.createCachedData()`]: vm.html#vm_script_createcacheddata
25592577
[`setInterval()`]: timers.html#timers_setinterval_callback_delay_args
25602578
[`setTimeout()`]: timers.html#timers_settimeout_callback_delay_args

doc/api/http.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -568,8 +568,11 @@ been aborted.
568568
### request.connection
569569
<!-- YAML
570570
added: v0.3.0
571+
deprecated: REPLACEME
571572
-->
572573

574+
> Stability: 0 - Deprecated. Use [`request.socket`][].
575+
573576
* {net.Socket}
574577

575578
See [`request.socket`][].
@@ -1145,10 +1148,13 @@ will result in a [`TypeError`][] being thrown.
11451148
### response.connection
11461149
<!-- YAML
11471150
added: v0.3.0
1151+
deprecated: REPLACEME
11481152
-->
11491153

11501154
* {net.Socket}
11511155

1156+
> Stability: 0 - Deprecated. Use [`response.socket`][].
1157+
11521158
See [`response.socket`][].
11531159

11541160
### response.end([data][, encoding][, callback])

doc/api/http2.md

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2702,6 +2702,18 @@ added: v8.4.0
27022702
The request authority pseudo header field. It can also be accessed via
27032703
`req.headers[':authority']`.
27042704

2705+
#### request.connection
2706+
<!-- YAML
2707+
added: v8.4.0
2708+
deprecated: REPLACEME
2709+
-->
2710+
2711+
> Stability: 0 - Deprecated. Use [`request.socket`][].
2712+
2713+
* {net.Socket|tls.TLSSocket}
2714+
2715+
See [`request.socket`][].
2716+
27052717
#### request.destroy([error])
27062718
<!-- YAML
27072719
added: v8.4.0
@@ -2995,8 +3007,11 @@ will result in a [`TypeError`][] being thrown.
29953007
#### response.connection
29963008
<!-- YAML
29973009
added: v8.4.0
3010+
deprecated: REPLACEME
29983011
-->
29993012

3013+
> Stability: 0 - Deprecated. Use [`response.socket`][].
3014+
30003015
* {net.Socket|tls.TLSSocket}
30013016

30023017
See [`response.socket`][].
@@ -3497,6 +3512,7 @@ following additional properties:
34973512
[`net.Socket.prototype.unref()`]: net.html#net_socket_unref
34983513
[`net.Socket`]: net.html#net_class_net_socket
34993514
[`net.connect()`]: net.html#net_net_connect
3515+
[`request.socket`]: #http2_request_socket
35003516
[`request.socket.getPeerCertificate()`]: tls.html#tls_tlssocket_getpeercertificate_detailed
35013517
[`response.end()`]: #http2_response_end_data_encoding_callback
35023518
[`response.setHeader()`]: #http2_response_setheader_name_value

lib/_http_client.js

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -299,7 +299,7 @@ Object.setPrototypeOf(ClientRequest.prototype, OutgoingMessage.prototype);
299299
Object.setPrototypeOf(ClientRequest, OutgoingMessage);
300300

301301
ClientRequest.prototype._finish = function _finish() {
302-
DTRACE_HTTP_CLIENT_REQUEST(this, this.connection);
302+
DTRACE_HTTP_CLIENT_REQUEST(this, this.socket);
303303
OutgoingMessage.prototype._finish.call(this);
304304
};
305305

@@ -643,7 +643,6 @@ function emitFreeNT(socket) {
643643
function tickOnSocket(req, socket) {
644644
const parser = parsers.alloc();
645645
req.socket = socket;
646-
req.connection = socket;
647646
parser.initialize(HTTPParser.RESPONSE,
648647
new HTTPClientAsyncResource('HTTPINCOMINGMESSAGE', req));
649648
parser.socket = socket;

lib/_http_incoming.js

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,6 @@ function IncomingMessage(socket) {
4242
this._readableState.readingMore = true;
4343

4444
this.socket = socket;
45-
this.connection = socket;
4645

4746
this.httpVersionMajor = null;
4847
this.httpVersionMinor = null;
@@ -76,6 +75,15 @@ function IncomingMessage(socket) {
7675
Object.setPrototypeOf(IncomingMessage.prototype, Stream.Readable.prototype);
7776
Object.setPrototypeOf(IncomingMessage, Stream.Readable);
7877

78+
Object.defineProperty(IncomingMessage.prototype, 'connection', {
79+
get: function() {
80+
return this.socket;
81+
},
82+
set: function(val) {
83+
this.socket = val;
84+
}
85+
});
86+
7987
IncomingMessage.prototype.setTimeout = function setTimeout(msecs, callback) {
8088
if (callback)
8189
this.on('timeout', callback);

lib/_http_outgoing.js

Lines changed: 19 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,6 @@ function OutgoingMessage() {
100100
this[kIsCorked] = false;
101101

102102
this.socket = null;
103-
this.connection = null;
104103
this._header = null;
105104
this[outHeadersKey] = null;
106105

@@ -137,6 +136,15 @@ Object.defineProperty(OutgoingMessage.prototype, '_headers', {
137136
}, 'OutgoingMessage.prototype._headers is deprecated', 'DEP0066')
138137
});
139138

139+
Object.defineProperty(OutgoingMessage.prototype, 'connection', {
140+
get: function() {
141+
return this.socket;
142+
},
143+
set: function(val) {
144+
this.socket = val;
145+
}
146+
});
147+
140148
Object.defineProperty(OutgoingMessage.prototype, '_headerNames', {
141149
get: internalUtil.deprecate(function() {
142150
const headers = this[outHeadersKey];
@@ -253,7 +261,7 @@ OutgoingMessage.prototype._send = function _send(data, encoding, callback) {
253261

254262
OutgoingMessage.prototype._writeRaw = _writeRaw;
255263
function _writeRaw(data, encoding, callback) {
256-
const conn = this.connection;
264+
const conn = this.socket;
257265
if (conn && conn.destroyed) {
258266
// The socket was destroyed. If we're still trying to write to it,
259267
// then we haven't gotten the 'close' event yet.
@@ -591,10 +599,10 @@ function write_(msg, chunk, encoding, callback, fromEnd) {
591599
['string', 'Buffer'], chunk);
592600
}
593601

594-
if (!fromEnd && msg.connection && !msg[kIsCorked]) {
595-
msg.connection.cork();
602+
if (!fromEnd && msg.socket && !msg[kIsCorked]) {
603+
msg.socket.cork();
596604
msg[kIsCorked] = true;
597-
process.nextTick(connectionCorkNT, msg, msg.connection);
605+
process.nextTick(connectionCorkNT, msg, msg.socket);
598606
}
599607

600608
var len, ret;
@@ -682,8 +690,8 @@ OutgoingMessage.prototype.end = function end(chunk, encoding, callback) {
682690
else
683691
this._contentLength = chunk.length;
684692
}
685-
if (this.connection) {
686-
this.connection.cork();
693+
if (this.socket) {
694+
this.socket.cork();
687695
uncork = true;
688696
}
689697
write_(this, chunk, encoding, null, true);
@@ -705,16 +713,16 @@ OutgoingMessage.prototype.end = function end(chunk, encoding, callback) {
705713
}
706714

707715
if (uncork)
708-
this.connection.uncork();
716+
this.socket.uncork();
709717

710718
this.finished = true;
711719

712720
// There is the first message on the outgoing queue, and we've sent
713721
// everything to the socket.
714722
debug('outgoing message end.');
715723
if (this.outputData.length === 0 &&
716-
this.connection &&
717-
this.connection._httpMessage === this) {
724+
this.socket &&
725+
this.socket._httpMessage === this) {
718726
this._finish();
719727
}
720728

@@ -723,7 +731,7 @@ OutgoingMessage.prototype.end = function end(chunk, encoding, callback) {
723731

724732

725733
OutgoingMessage.prototype._finish = function _finish() {
726-
assert(this.connection);
734+
assert(this.socket);
727735
this.emit('prefinish');
728736
};
729737

lib/_http_server.js

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -167,7 +167,7 @@ Object.setPrototypeOf(ServerResponse.prototype, OutgoingMessage.prototype);
167167
Object.setPrototypeOf(ServerResponse, OutgoingMessage);
168168

169169
ServerResponse.prototype._finish = function _finish() {
170-
DTRACE_HTTP_SERVER_RESPONSE(this.connection);
170+
DTRACE_HTTP_SERVER_RESPONSE(this.socket);
171171
if (this[kServerResponseStatistics] !== undefined) {
172172
emitStatistics(this[kServerResponseStatistics]);
173173
}
@@ -205,7 +205,6 @@ ServerResponse.prototype.assignSocket = function assignSocket(socket) {
205205
socket._httpMessage = this;
206206
socket.on('close', onServerResponseClose);
207207
this.socket = socket;
208-
this.connection = socket;
209208
this.emit('socket', socket);
210209
this._flush();
211210
};
@@ -214,7 +213,7 @@ ServerResponse.prototype.detachSocket = function detachSocket(socket) {
214213
assert(socket._httpMessage === this);
215214
socket.removeListener('close', onServerResponseClose);
216215
socket._httpMessage = null;
217-
this.socket = this.connection = null;
216+
this.socket = null;
218217
};
219218

220219
ServerResponse.prototype.writeContinue = function writeContinue(cb) {

0 commit comments

Comments
 (0)