@@ -15,6 +15,9 @@ import {getSearch} from './utils/get-search.js';
15
15
16
16
const INTERNALS = Symbol ( 'Request internals' ) ;
17
17
18
+ const forbiddenMethods = new Set ( [ "CONNECT" , "TRACE" , "TRACK" ] ) ;
19
+ const normalizedMethods = new Set ( [ "DELETE" , "GET" , "HEAD" , "OPTIONS" , "POST" , "PUT" ] ) ;
20
+
18
21
/**
19
22
* Check if `obj` is an instance of Request.
20
23
*
@@ -32,15 +35,15 @@ const isRequest = object => {
32
35
/**
33
36
* Request class
34
37
* @implements {globalThis.Request}
35
- *
38
+ *
36
39
* @typedef {Object } RequestState
37
40
* @property {string } method
38
41
* @property {RequestRedirect } redirect
39
42
* @property {globalThis.Headers } headers
40
43
* @property {RequestCredentials } credentials
41
44
* @property {URL } parsedURL
42
45
* @property {AbortSignal|null } signal
43
- *
46
+ *
44
47
* @typedef {Object } RequestExtraOptions
45
48
* @property {number } [follow]
46
49
* @property {boolean } [compress]
@@ -49,15 +52,15 @@ const isRequest = object => {
49
52
* @property {Agent } [agent]
50
53
* @property {number } [highWaterMark]
51
54
* @property {boolean } [insecureHTTPParser]
52
- *
55
+ *
53
56
* @typedef {((url:URL) => import('http').Agent) | import('http').Agent } Agent
54
- *
57
+ *
55
58
* @typedef {Object } RequestOptions
56
59
* @property {string } [method]
57
60
* @property {ReadableStream<Uint8Array>|null } [body]
58
61
* @property {globalThis.Headers } [headers]
59
62
* @property {RequestRedirect } [redirect]
60
- *
63
+ *
61
64
*/
62
65
export default class Request extends Body {
63
66
/**
@@ -80,8 +83,13 @@ export default class Request extends Body {
80
83
81
84
82
85
86
+ // Normalize method: https://fetch.spec.whatwg.org/#methods
83
87
let method = init . method || settings . method || 'GET' ;
84
- method = method . toUpperCase ( ) ;
88
+ if ( forbiddenMethods . has ( method . toUpperCase ( ) ) ) {
89
+ throw new TypeError ( `Failed to construct 'Request': '${ method } ' HTTP method is unsupported.` )
90
+ } else if ( normalizedMethods . has ( method . toUpperCase ( ) ) ) {
91
+ method = method . toUpperCase ( ) ;
92
+ }
85
93
86
94
const inputBody = init . body != null
87
95
? init . body
@@ -99,7 +107,7 @@ export default class Request extends Body {
99
107
} ) ;
100
108
const input = settings
101
109
102
-
110
+
103
111
const headers = /** @type {globalThis.Headers } */
104
112
( new Headers ( init . headers || input . headers || { } ) ) ;
105
113
@@ -170,11 +178,11 @@ export default class Request extends Body {
170
178
get destination ( ) {
171
179
return ""
172
180
}
173
-
181
+
174
182
get integrity ( ) {
175
183
return ""
176
184
}
177
-
185
+
178
186
/** @type {RequestMode } */
179
187
get mode ( ) {
180
188
return "cors"
@@ -184,7 +192,7 @@ export default class Request extends Body {
184
192
get referrer ( ) {
185
193
return ""
186
194
}
187
-
195
+
188
196
/** @type {ReferrerPolicy } */
189
197
get referrerPolicy ( ) {
190
198
return ""
@@ -308,7 +316,7 @@ export const getNodeRequestOptions = request => {
308
316
port : parsedURL . port ,
309
317
hash : parsedURL . hash ,
310
318
search : parsedURL . search ,
311
- // @ts -ignore - it does not has a query
319
+ // @ts -ignore - it does not has a query
312
320
query : parsedURL . query ,
313
321
href : parsedURL . href ,
314
322
method : request . method ,
0 commit comments