File tree Expand file tree Collapse file tree 2 files changed +8
-3
lines changed Expand file tree Collapse file tree 2 files changed +8
-3
lines changed Original file line number Diff line number Diff line change @@ -87,7 +87,9 @@ export class IncomingMessage extends Readable implements _IncomingMessage {
87
87
) : void => {
88
88
const connectingIp = headers . get ( 'cf-connecting-ip' ) ;
89
89
const isConnectingIpIpv4 = connectingIp ? isIPv4 ( connectingIp ) : true ;
90
- const remotePort = Math . floor ( Math . random ( ) * ( 65535 - 32768 + 1 ) ) ;
90
+ // Return a port number between 2^15 and 2^16.
91
+ const remotePort =
92
+ Math . floor ( Math . random ( ) * ( 65535 - 32768 + 1 ) ) + 32768 ;
91
93
92
94
incoming . #socket = {
93
95
encrypted : headers . get ( 'x-forwarded-proto' ) === 'https' ,
@@ -113,11 +115,12 @@ export class IncomingMessage extends Readable implements _IncomingMessage {
113
115
} ,
114
116
get localPort ( ) : number {
115
117
// This is the port defined by the `server.listen(port)` call.
116
- // TODO(soon): Investigate if we should return 443 on production.
117
118
return localPort ;
118
119
} ,
119
120
// Since we don't implement net.Socket, we fallback to IncomingMessage.destroy here.
120
- destroy : incoming . destroy . bind ( incoming ) ,
121
+ // We do not use .bind() in case user overwrites destroy method.
122
+ destroy : ( err : Error | undefined ) : IncomingMessage =>
123
+ incoming . destroy ( err ) ,
121
124
} ;
122
125
} ;
123
126
}
Original file line number Diff line number Diff line change @@ -1140,6 +1140,8 @@ export const testIncomingMessageSocket = {
1140
1140
strictEqual ( req . socket . localAddress , '127.0.0.1' ) ;
1141
1141
strictEqual ( req . socket . remoteAddress , '127.0.0.1' ) ;
1142
1142
strictEqual ( typeof req . socket . remotePort , 'number' ) ;
1143
+ ok ( req . socket . remotePort >= Math . pow ( 2 , 15 ) ) ;
1144
+ ok ( req . socket . remotePort <= Math . pow ( 2 , 16 ) ) ;
1143
1145
strictEqual ( req . socket . remoteFamily , 'IPv4' ) ;
1144
1146
1145
1147
res . writeHead ( 200 ) ;
You can’t perform that action at this time.
0 commit comments