Skip to content

Commit 7cd3ce6

Browse files
authored
fix: add methods (#54)
Translate method number to string
1 parent c5407c6 commit 7cd3ce6

File tree

1 file changed

+37
-7
lines changed

1 file changed

+37
-7
lines changed

src/fetch/index.ts

Lines changed: 37 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -9,14 +9,44 @@ import { type Uint8ArrayList } from 'uint8arraylist'
99

1010
interface Fetch { (req: Request): Promise<Response> }
1111

12-
const METHOD_GET = 1
12+
const METHODS = [
13+
'DELETE',
14+
'GET',
15+
'HEAD',
16+
'POST',
17+
'PUT',
18+
'CONNECT',
19+
'OPTIONS',
20+
'TRACE',
21+
'COPY',
22+
'LOCK',
23+
'MKCOL',
24+
'MOVE',
25+
'PROPFIND',
26+
'PROPPATCH',
27+
'SEARCH',
28+
'UNLOCK',
29+
'BIND',
30+
'REBIND',
31+
'UNBIND',
32+
'ACL',
33+
'REPORT',
34+
'MKACTIVITY',
35+
'CHECKOUT',
36+
'MERGE',
37+
'M-SEARCH',
38+
'NOTIFY',
39+
'SUBSCRIBE',
40+
'UNSUBSCRIBE',
41+
'PATCH',
42+
'PURGE',
43+
'MKCALENDAR',
44+
'LINK',
45+
'UNLINK'
46+
]
1347

1448
function getStringMethod (method: number): string {
15-
if (method === 1) {
16-
return 'GET'
17-
}
18-
19-
return 'UNKNOWN'
49+
return METHODS[method] ?? 'UNKNOWN'
2050
}
2151

2252
interface Duplex<TSource, TSink = TSource, RSink = Promise<void>> {
@@ -129,7 +159,7 @@ export function readHTTPMsg (expectRequest: boolean, r: Duplex<Uint8Array | Uint
129159
// Headers are parsed. We can return the response
130160
try {
131161
if (expectRequest) {
132-
if (info.method === METHOD_GET) {
162+
if (getStringMethod(info.method) === 'GET') {
133163
reqBody = null
134164
}
135165

0 commit comments

Comments
 (0)