File tree Expand file tree Collapse file tree 1 file changed +10
-10
lines changed Expand file tree Collapse file tree 1 file changed +10
-10
lines changed Original file line number Diff line number Diff line change @@ -80,23 +80,23 @@ function normalizeRequest(req: HttpRequest): HTTPGraphQLRequest {
80
80
method : req . method ,
81
81
headers : normalizeHeaders ( req . headers ) ,
82
82
search : new URL ( req . url ) . search ,
83
- body : parseBody ( req . body , req . headers [ 'content-type' ] ) ,
83
+ body : parseBody ( req . method , req . body , req . headers [ 'content-type' ] ) ,
84
84
} ;
85
85
}
86
86
87
87
function parseBody (
88
+ method : string | undefined ,
88
89
body : string | null | undefined ,
89
90
contentType : string | undefined ,
90
- ) : object | string {
91
- if ( body ) {
92
- if ( contentType === 'application/json' ) {
93
- if ( typeof body === 'string' ) {
94
- return JSON . parse ( body ) ;
95
- }
96
- return body ;
97
- }
91
+ ) : object | null {
92
+ const isValidContentType = contentType ?. startsWith ( 'application/json' ) ;
93
+ const isValidPostRequest =
94
+ method === 'POST' && typeof body === 'string' && isValidContentType ;
95
+
96
+ if ( isValidPostRequest ) {
97
+ return JSON . parse ( body ) ;
98
98
}
99
- return '' ;
99
+ return null ;
100
100
}
101
101
102
102
function normalizeHeaders ( headers : HttpRequestHeaders ) : HeaderMap {
You can’t perform that action at this time.
0 commit comments