Skip to content

Commit

Permalink
Merge pull request #176 from run-crank/rhart/evaluateNetworkRequests
Browse files Browse the repository at this point in the history
postData fix for evaluateRequests
  • Loading branch information
russellbot authored Jul 7, 2022
2 parents 1c0a581 + bc23414 commit a663879
Showing 1 changed file with 11 additions and 3 deletions.
14 changes: 11 additions & 3 deletions src/client/mixins/network.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { URL } from 'url';
import * as querystring from 'querystring';

const OTHER_REQUEST_METHODS = ['POST', 'PATCH', 'PUT'];
const SUPPORTED_CONTENT_TYPES = ['application/json', 'application/json;charset=UTF-8', 'application/x-www-form-urlencoded', 'text/plain'];
const SUPPORTED_CONTENT_TYPES = ['application/json', 'application/json;charset=UTF-8', 'application/x-www-form-urlencoded', 'text/plain', 'none'];

export class NetworkAware {

Expand Down Expand Up @@ -40,9 +40,17 @@ export class NetworkAware {
if (request.method === 'GET') {
actualParams = this.convertParamsToObject(new URL(request.url).searchParams);
} else if (OTHER_REQUEST_METHODS.includes(request.method)) {
const contentType = request.rawRequest._headers['content-type'];
const contentType = request.rawRequest._headers['content-type'] || 'none';
const requestHasValidContentType = SUPPORTED_CONTENT_TYPES.filter((f) => f.includes(contentType) || contentType.includes(f)).length > 0;
const postData = request.postData ? JSON.parse(request.postData) : this.convertParamsToObject(new URL(request.url).searchParams);
const isJsonString = (string) => {
try {
JSON.parse(string);
} catch (e) {
return false;
}
return true;
};
const postData = request.postData && isJsonString(request.postData) ? JSON.parse(request.postData) : this.convertParamsToObject(new URL(request.url).searchParams);
if (requestHasValidContentType) {
try {
actualParams = postData;
Expand Down

0 comments on commit a663879

Please sign in to comment.