Skip to content

Commit f3188f5

Browse files
committed
feat: added URL path components array to Request
1 parent bccb882 commit f3188f5

File tree

1 file changed

+10
-0
lines changed

1 file changed

+10
-0
lines changed

src/Request.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,11 @@ export class Request<A> {
4141
*/
4242
public readonly server: Server<A>;
4343

44+
/**
45+
* The components of the request URL path name.
46+
*/
47+
public readonly pathComponents: ReadonlyArray<string>;
48+
4449
/**
4550
* The parsed request cookies from the {@link https://developer.mozilla.org/en-US/docs/Web/HTTP/Reference/Headers/Cookie|Cookie} request header.
4651
*/
@@ -70,6 +75,11 @@ export class Request<A> {
7075
this.ip = ip;
7176
this.server = server;
7277

78+
this.pathComponents = this.url.pathname
79+
.split("/")
80+
.map(decodeURIComponent)
81+
.filter(component => component.length > 0);
82+
7383
this.cookies = new Map(
7484
this.headers.get("cookie")
7585
?.split("; ")

0 commit comments

Comments
 (0)