Skip to content

Commit 3b85adc

Browse files
committed
feat: allow configuring the query string parser
1 parent 854a478 commit 3b85adc

File tree

3 files changed

+52
-1
lines changed

3 files changed

+52
-1
lines changed

src/define_config.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,13 @@ export function defineConfig(config: Partial<ServerConfig>): ServerConfig {
3030
secure: false,
3131
sameSite: false,
3232
},
33+
qs: {
34+
depth: 5,
35+
parameterLimit: 1000,
36+
allowSparse: false,
37+
arrayLimit: 20,
38+
comma: true,
39+
},
3340
...config,
3441
}
3542

src/request.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,7 @@ export class Request extends Macroable {
117117
*/
118118
#parseQueryString() {
119119
if (this.parsedUrl.query) {
120-
this.updateQs(qs.parse(this.parsedUrl.query))
120+
this.updateQs(qs.parse(this.parsedUrl.query, this.#config.qs))
121121
this.#originalRequestData = { ...this.#requestData }
122122
}
123123
}

src/types/request.ts

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,50 @@ export type RequestConfig = {
4545
/**
4646
* A callback function to trust proxy ip addresses. You must use
4747
* the `proxy-addr` package to compute this value.
48+
*
49+
* Defaults to: "proxyAddr.compile('loopback')"
4850
*/
4951
trustProxy: (address: string, distance: number) => boolean
52+
53+
/**
54+
* Options to control query string parsing
55+
*/
56+
qs: {
57+
/**
58+
* Nesting depth till the parameters should be parsed.
59+
*
60+
* Defaults to 5
61+
*/
62+
depth: number
63+
64+
/**
65+
* Number of parameters to parse.
66+
*
67+
* Defaults to 1000
68+
*/
69+
parameterLimit: number
70+
71+
/**
72+
* Allow sparse elements in an array.
73+
*
74+
* Defaults to false
75+
*/
76+
allowSparse: boolean
77+
78+
/**
79+
* The max limimit for the array indices. After the given limit
80+
* the array indices will be converted to an object, where the
81+
* index is the key.
82+
*
83+
* Defaults to 20
84+
*/
85+
arrayLimit: number
86+
87+
/**
88+
* Join comma seperated query string values to an array
89+
*
90+
* Defaults to false
91+
*/
92+
comma: boolean
93+
}
5094
}

0 commit comments

Comments
 (0)