Skip to content

Commit 7b29979

Browse files
committed
Merge branch 'master' into feat/add-br+sztd-with-priority-opts
2 parents 89429f0 + 5095382 commit 7b29979

File tree

7 files changed

+1079
-23
lines changed

7 files changed

+1079
-23
lines changed

lib/request.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -630,7 +630,7 @@ internals.Info = class {
630630
this.received = received;
631631
this.referrer = req.headers.referrer || req.headers.referer || '';
632632
this.host = host;
633-
this.hostname = host.split(':')[0];
633+
this.hostname = /^(.*?)(?::\d+)?$/.exec(host)[1];
634634
this.id = `${received}:${request._core.info.id}:${request._core._counter()}`;
635635

636636
this._remoteAddress = null;

lib/types/request.d.ts

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,8 @@ export interface RequestAuth<
8989
* set to false.
9090
*/
9191
isAuthorized: boolean;
92+
/** true if the request has been authenticated via the `server.inject()` `auth` option, otherwise `undefined`. */
93+
isInjected?: boolean | undefined;
9294
/** the route authentication mode. */
9395
mode: AuthMode;
9496
/** the name of the strategy used. */
@@ -250,7 +252,7 @@ export interface RequestLog {
250252
}
251253

252254
export interface RequestQuery {
253-
[key: string]: any;
255+
[key: string]: string | string[] | undefined;
254256
}
255257

256258
/**
@@ -269,9 +271,9 @@ export interface InternalRequestDefaults {
269271

270272
Payload: stream.Readable | Buffer | string | object;
271273
Query: RequestQuery;
272-
Params: Record<string, any>;
274+
Params: Record<string, string>;
273275
Pres: Record<string, any>;
274-
Headers: Record<string, any>;
276+
Headers: Record<string, string | string[] | undefined>;
275277
RequestApp: RequestApplicationState;
276278

277279
AuthUser: UserCredentials;
@@ -303,11 +305,7 @@ export type ReqRef = Partial<Record<keyof ReqRefDefaults, unknown>>;
303305
/**
304306
* Utilities for merging request refs and other things
305307
*/
306-
export type MergeType<T, U> = {
307-
[K in keyof T]: K extends keyof U
308-
? U[K]
309-
: T[K];
310-
};
308+
export type MergeType<T, U> = Omit<T, keyof U> & U;
311309

312310
export type MergeRefs<T extends ReqRef> = MergeType<ReqRefDefaults, T>;
313311

@@ -441,7 +439,7 @@ export interface Request<Refs extends ReqRef = ReqRefDefaults> extends Podium {
441439
/**
442440
* Same as pre but represented as the response object created by the pre method.
443441
*/
444-
readonly preResponses: Record<string, any>;
442+
readonly preResponses: Record<string, unknown>;
445443

446444
/**
447445
* By default the object outputted from node's URL parse() method.
@@ -474,7 +472,7 @@ export interface Request<Refs extends ReqRef = ReqRefDefaults> extends Podium {
474472
/**
475473
* An object containing parsed HTTP state information (cookies) where each key is the cookie name and value is the matching cookie content after processing using any registered cookie definition.
476474
*/
477-
readonly state: Record<string, any>;
475+
readonly state: Record<string, unknown>;
478476

479477
/**
480478
* The parsed request URI.

lib/types/route.d.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -358,7 +358,7 @@ export interface RouteOptionsPreObject<Refs extends ReqRef = ReqRefDefaults> {
358358
/**
359359
* key name used to assign the response of the method to in request.pre and request.preResponses.
360360
*/
361-
assign?: keyof Refs['Pres'] | undefined;
361+
assign?: keyof MergeRefs<Refs>['Pres'] | undefined;
362362
/**
363363
* A failAction value which determine what to do when a pre-handler method throws an error. If assign is specified and the failAction setting is not 'error', the error will be assigned.
364364
*/
@@ -978,5 +978,5 @@ export interface ServerRoute<Refs extends ReqRef = ReqRefDefaults> {
978978
/**
979979
* route custom rules object. The object is passed to each rules processor registered with server.rules(). Cannot be used if route.options.rules is defined.
980980
*/
981-
rules?: Refs['Rules'] | undefined;
981+
rules?: MergeRefs<Refs>['Rules'] | undefined;
982982
}

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
"name": "@hapi/hapi",
33
"description": "HTTP Server framework",
44
"homepage": "https://hapi.dev",
5-
"version": "21.4.4",
5+
"version": "21.4.6",
66
"repository": "git://github.com/hapijs/hapi",
77
"main": "lib/index.js",
88
"types": "lib/index.d.ts",

test/request.js

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,36 @@ describe('Request.Generator', () => {
123123

124124
describe('Request', () => {
125125

126+
it('sets host and hostname', async () => {
127+
128+
const server = Hapi.server();
129+
130+
const handler = (request) => {
131+
132+
return [request.info.host, request.info.hostname].join('|');
133+
};
134+
135+
server.route({ method: 'GET', path: '/', handler });
136+
137+
const res1 = await server.inject({ url: '/', headers: { host: 'host' } });
138+
expect(res1.payload).to.equal('host|host');
139+
140+
const res2 = await server.inject({ url: '/', headers: { host: 'host:123' } });
141+
expect(res2.payload).to.equal('host:123|host');
142+
143+
const res3 = await server.inject({ url: '/', headers: { host: '127.0.0.1' } });
144+
expect(res3.payload).to.equal('127.0.0.1|127.0.0.1');
145+
146+
const res4 = await server.inject({ url: '/', headers: { host: '127.0.0.1:123' } });
147+
expect(res4.payload).to.equal('127.0.0.1:123|127.0.0.1');
148+
149+
const res5 = await server.inject({ url: '/', headers: { host: '[::1]' } });
150+
expect(res5.payload).to.equal('[::1]|[::1]');
151+
152+
const res6 = await server.inject({ url: '/', headers: { host: '[::1]:123' } });
153+
expect(res6.payload).to.equal('[::1]:123|[::1]');
154+
});
155+
126156
it('sets client address (default)', async (flags) => {
127157

128158
const server = Hapi.server();

0 commit comments

Comments
 (0)