@@ -28,8 +28,9 @@ export class Request<A> {
2828 /**
2929 * The address requested by the client (first peer). If the request originated from a trusted proxy, this address
3030 * will be constructed based on protocol and host provided by the proxy. If the proxy does not specify protocol,
31- * `http:` will be used as a default. If the proxy does not specify host, will use the `HOST` environment variable
32- * or default to `localhost`. If the proxy is not trusted, will be the same as {@link Request#originalUrl}.
31+ * `http:` will be used as a default. If the proxy does not specify host (or the proxy is not trusted), will use the
32+ * `Host` request header. If that is not specified either, will use the `HOST` environment variable or default to
33+ * `localhost`.
3334 *
3435 * If basic authentication is available to this request via headers, the `username` and `password` fields are
3536 * available in the {@link URL} object.
@@ -41,14 +42,6 @@ export class Request<A> {
4142 */
4243 public readonly headers : Readonly < Headers > ;
4344
44- /**
45- * The `Host` header provided by the client (first peer). If the request originated from a trusted proxy, this
46- * will be obtained from the proxy. Otherwise, if the proxy does not specify the original `Host` header, or the
47- * proxy is untrusted, this will be the same as the `Host` header in {@link Request#headers} (and `null` if not
48- * set).
49- */
50- public readonly host : string | null ;
51-
5245 /**
5346 * Request body readable stream.
5447 */
@@ -87,7 +80,6 @@ export class Request<A> {
8780 * @param originalUrl See {@link Request#originalUrl}.
8881 * @param url See {@link Request#url}.
8982 * @param headers See {@link Request#headers}.
90- * @param host See {@link Request#host}.
9183 * @param bodyStream See {@link Request#bodyStream}.
9284 * @param originalIp See {@link Request#originalIp}.
9385 * @param ip See {@link Request#ip}.
@@ -99,7 +91,6 @@ export class Request<A> {
9991 originalUrl : Request < A > [ "originalUrl" ] ,
10092 url : Request < A > [ "url" ] ,
10193 headers : Request < A > [ "headers" ] ,
102- host : Request < A > [ "host" ] ,
10394 bodyStream : Request < A > [ "bodyStream" ] ,
10495 originalIp : Request < A > [ "originalIp" ] ,
10596 ip : Request < A > [ "ip" ] ,
@@ -109,7 +100,6 @@ export class Request<A> {
109100 this . originalUrl = originalUrl ;
110101 this . url = url ;
111102 this . headers = headers ;
112- this . host = host ;
113103 this . bodyStream = bodyStream ;
114104 this . originalIp = originalIp ;
115105 this . ip = ip ;
@@ -154,7 +144,6 @@ export class Request<A> {
154144 const proxy = isTrustedProxy ? this . getClientInfoFromTrustedProxy ( headers ) : { } ;
155145
156146 const clientIp = proxy . ip ?? ip ;
157- const clientHost = proxy . host ?? headers . get ( "host" ) ;
158147
159148 const auth =
160149 incomingMessage . headers . authorization
@@ -173,13 +162,16 @@ export class Request<A> {
173162 if ( proxy . protocol !== undefined )
174163 clientUrl . protocol = proxy . protocol + ":" ;
175164
165+ const clientHost = proxy . host ?? headers . get ( "host" ) ;
166+ if ( clientHost !== null )
167+ clientUrl . host = clientHost ;
168+
176169 try {
177170 return new Request < A > (
178171 incomingMessage . method as Request . Method ,
179172 new URL ( originalUrl ) ,
180173 clientUrl ,
181174 headers ,
182- clientHost ,
183175 incomingMessage ,
184176 ip ,
185177 clientIp ,
@@ -301,7 +293,6 @@ export class Request<A> {
301293 this . originalUrl ,
302294 this . url ,
303295 this . headers ,
304- this . host ,
305296 this . bodyStream ,
306297 this . originalIp ,
307298 this . ip ,
0 commit comments