Skip to content

Commit 0daec61

Browse files
ronagTrott
authored andcommitted
http: replace superfluous connection property with getter/setter
PR-URL: #29015 Reviewed-By: Anna Henningsen <anna@addaleax.net> Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Trivikram Kamat <trivikr.dev@gmail.com> Reviewed-By: Luigi Pinca <luigipinca@gmail.com> Reviewed-By: Rich Trott <rtrott@gmail.com>
1 parent 6f613d8 commit 0daec61

7 files changed

+71
-17
lines changed

doc/api/deprecations.md

+18
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

+6
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`][].
@@ -1166,10 +1169,13 @@ will result in a [`TypeError`][] being thrown.
11661169
### response.connection
11671170
<!-- YAML
11681171
added: v0.3.0
1172+
deprecated: REPLACEME
11691173
-->
11701174

11711175
* {net.Socket}
11721176

1177+
> Stability: 0 - Deprecated. Use [`response.socket`][].
1178+
11731179
See [`response.socket`][].
11741180

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

doc/api/http2.md

+16
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`][].
@@ -3508,6 +3523,7 @@ following additional properties:
35083523
[`net.Socket.prototype.unref()`]: net.html#net_socket_unref
35093524
[`net.Socket`]: net.html#net_class_net_socket
35103525
[`net.connect()`]: net.html#net_net_connect
3526+
[`request.socket`]: #http2_request_socket
35113527
[`request.socket.getPeerCertificate()`]: tls.html#tls_tlssocket_getpeercertificate_detailed
35123528
[`response.end()`]: #http2_response_end_data_encoding_callback
35133529
[`response.setHeader()`]: #http2_response_setheader_name_value

lib/_http_client.js

+1-2
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

+9-1
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

+19-11
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,6 @@ function OutgoingMessage() {
102102
this[kIsCorked] = false;
103103

104104
this.socket = null;
105-
this.connection = null;
106105
this._header = null;
107106
this[kOutHeaders] = null;
108107

@@ -157,6 +156,15 @@ Object.defineProperty(OutgoingMessage.prototype, '_headers', {
157156
}, 'OutgoingMessage.prototype._headers is deprecated', 'DEP0066')
158157
});
159158

159+
Object.defineProperty(OutgoingMessage.prototype, 'connection', {
160+
get: function() {
161+
return this.socket;
162+
},
163+
set: function(val) {
164+
this.socket = val;
165+
}
166+
});
167+
160168
Object.defineProperty(OutgoingMessage.prototype, '_headerNames', {
161169
get: internalUtil.deprecate(function() {
162170
const headers = this[kOutHeaders];
@@ -273,7 +281,7 @@ OutgoingMessage.prototype._send = function _send(data, encoding, callback) {
273281

274282
OutgoingMessage.prototype._writeRaw = _writeRaw;
275283
function _writeRaw(data, encoding, callback) {
276-
const conn = this.connection;
284+
const conn = this.socket;
277285
if (conn && conn.destroyed) {
278286
// The socket was destroyed. If we're still trying to write to it,
279287
// then we haven't gotten the 'close' event yet.
@@ -615,10 +623,10 @@ function write_(msg, chunk, encoding, callback, fromEnd) {
615623
['string', 'Buffer'], chunk);
616624
}
617625

618-
if (!fromEnd && msg.connection && !msg[kIsCorked]) {
619-
msg.connection.cork();
626+
if (!fromEnd && msg.socket && !msg[kIsCorked]) {
627+
msg.socket.cork();
620628
msg[kIsCorked] = true;
621-
process.nextTick(connectionCorkNT, msg, msg.connection);
629+
process.nextTick(connectionCorkNT, msg, msg.socket);
622630
}
623631

624632
var len, ret;
@@ -706,8 +714,8 @@ OutgoingMessage.prototype.end = function end(chunk, encoding, callback) {
706714
else
707715
this._contentLength = chunk.length;
708716
}
709-
if (this.connection) {
710-
this.connection.cork();
717+
if (this.socket) {
718+
this.socket.cork();
711719
uncork = true;
712720
}
713721
write_(this, chunk, encoding, null, true);
@@ -729,16 +737,16 @@ OutgoingMessage.prototype.end = function end(chunk, encoding, callback) {
729737
}
730738

731739
if (uncork)
732-
this.connection.uncork();
740+
this.socket.uncork();
733741

734742
this.finished = true;
735743

736744
// There is the first message on the outgoing queue, and we've sent
737745
// everything to the socket.
738746
debug('outgoing message end.');
739747
if (this.outputData.length === 0 &&
740-
this.connection &&
741-
this.connection._httpMessage === this) {
748+
this.socket &&
749+
this.socket._httpMessage === this) {
742750
this._finish();
743751
}
744752

@@ -747,7 +755,7 @@ OutgoingMessage.prototype.end = function end(chunk, encoding, callback) {
747755

748756

749757
OutgoingMessage.prototype._finish = function _finish() {
750-
assert(this.connection);
758+
assert(this.socket);
751759
this.emit('prefinish');
752760
};
753761

lib/_http_server.js

+2-3
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)