@@ -9,18 +9,7 @@ export function init(manifest) {
9
9
const app = new App ( manifest ) ;
10
10
11
11
return async ( event ) => {
12
- const { httpMethod, headers, rawUrl, body, isBase64Encoded } = event ;
13
-
14
- const encoding = isBase64Encoded ? 'base64' : 'utf-8' ;
15
- const rawBody = typeof body === 'string' ? Buffer . from ( body , encoding ) : body ;
16
-
17
- const rendered = await app . render (
18
- new Request ( rawUrl , {
19
- method : httpMethod ,
20
- headers : new Headers ( headers ) ,
21
- body : rawBody
22
- } )
23
- ) ;
12
+ const rendered = await app . render ( to_request ( event ) ) ;
24
13
25
14
const partial_response = {
26
15
statusCode : rendered . status ,
@@ -46,6 +35,27 @@ export function init(manifest) {
46
35
} ;
47
36
}
48
37
38
+ /**
39
+ * @param {import('@netlify/functions').HandlerEvent } event
40
+ * @returns {Request }
41
+ */
42
+ function to_request ( event ) {
43
+ const { httpMethod, headers, rawUrl, body, isBase64Encoded } = event ;
44
+
45
+ /** @type {RequestInit } */
46
+ const init = {
47
+ method : httpMethod ,
48
+ headers : new Headers ( headers )
49
+ } ;
50
+
51
+ if ( httpMethod !== 'GET' && httpMethod !== 'HEAD' ) {
52
+ const encoding = isBase64Encoded ? 'base64' : 'utf-8' ;
53
+ init . body = typeof body === 'string' ? Buffer . from ( body , encoding ) : body ;
54
+ }
55
+
56
+ return new Request ( rawUrl , init ) ;
57
+ }
58
+
49
59
/**
50
60
* Splits headers into two categories: single value and multi value
51
61
* @param {Headers } headers
0 commit comments