@@ -9,13 +9,24 @@ import determineAuthFromHAR from "./authentication";
99import { filterIgnoreHeaders } from "../../utils/headers" ;
1010import type { Options } from "../RequestStore" ;
1111import type { Entry } from "har-format" ;
12+ import qs from 'fast-querystring' ;
13+
14+ const APPLICATION_JSON = "application/json" ;
15+ const APPLICATION_X_WWW_FORM_URLENCODED = "application/x-www-form-urlencoded" ;
1216
1317export type Params = {
1418 harRequest : Entry ;
1519 responseBody : JSONType ;
1620 options : Options ;
1721} ;
1822
23+ const parseRequestBody = ( harRequest : Entry ) : JSONType => {
24+ const { mimeType, text } = harRequest . request . postData || { } ;
25+ if ( mimeType === APPLICATION_JSON ) return parseJSON ( text ) ;
26+ else if ( mimeType === APPLICATION_X_WWW_FORM_URLENCODED && text ) return qs . parse ( text ) as JSONType ;
27+ return null ;
28+ } ;
29+
1930function createLeaf ( { harRequest, responseBody, options } : Params ) : Leaf {
2031 const { enableMoreInfo } = options ;
2132 const authentication = determineAuthFromHAR ( harRequest ) ;
@@ -27,7 +38,7 @@ function createLeaf({ harRequest, responseBody, options }: Params): Leaf {
2738 const statusCode = harRequest . response . status . toString ( ) ;
2839 const requestMime = harRequest . request . postData ?. mimeType ;
2940 const responseMime = harRequest . response . content . mimeType ;
30- const requestBody = parseJSON ( harRequest . request . postData ?. text ) ;
41+ const requestBody = parseRequestBody ( harRequest ) ;
3142 const requestHeaders = entriesToJSONType ( harRequest . request . headers ) ;
3243 const responseHeaders = entriesToJSONType ( harRequest . response . headers ) ;
3344 const queryParameters = entriesToJSONType ( harRequest . request . queryString ) ;
0 commit comments