Change to how HAR is rendered

This commit is contained in:
Kuba Orlik 2021-11-26 22:07:05 +01:00
parent 02a30a4831
commit b11f5f9737
1 changed files with 44 additions and 24 deletions

View File

@ -21,7 +21,11 @@ export type HAREntry = {
method: string; method: string;
postData?: { postData?: {
mimeType: string; mimeType: string;
params: NameValue[]; params: (NameValue & {
fileName: string;
contentType: string;
comment: "";
})[];
text: string; text: string;
}; };
queryString: NameValue[]; queryString: NameValue[];
@ -201,8 +205,7 @@ export default class ExtendedRequest {
this.requestBody.raw || {} this.requestBody.raw || {}
).map(([key, value], index) => [`${key}.${index}`, value]) ).map(([key, value], index) => [`${key}.${index}`, value])
), ),
}) }).map(([key, value]) => {
.map(([key, value]) => {
// to handle how ocdn.eu encrypts POST body on https://businessinsider.com.pl/ // to handle how ocdn.eu encrypts POST body on https://businessinsider.com.pl/
if ( if (
(Array.isArray(value) && value.length === 1 && !value[0]) || (Array.isArray(value) && value.length === 1 && !value[0]) ||
@ -217,11 +220,8 @@ export default class ExtendedRequest {
} else { } else {
return [key, value || ""]; return [key, value || ""];
} }
}) }),
.map(([key, value]) => { StolenDataEntry.parseValue
const parsed = StolenDataEntry.parseValue(value);
return [key, parsed];
}) as [string, unknown][]
).map( ).map(
([key, value]) => new StolenDataEntry(this, "request_body", key, value) ([key, value]) => new StolenDataEntry(this, "request_body", key, value)
); );
@ -319,10 +319,14 @@ export default class ExtendedRequest {
pageref: "page_1", pageref: "page_1",
startedDateTime: `${new Date().toJSON().replace("Z", "+01:00")}`, startedDateTime: `${new Date().toJSON().replace("Z", "+01:00")}`,
request: { request: {
bodySize: 0, bodySize:
JSON.stringify(this.requestBody.formData || {}).length +
(this.requestBody.raw || [])
.map((e) => e.bytes.byteLength)
.reduce((a, b) => a + b, 0),
method: this.data.method, method: this.data.method,
url: this.data.url, url: this.data.url,
headersSize: 100, headersSize: JSON.stringify(this.requestHeaders).length,
httpVersion: "HTTP/2", httpVersion: "HTTP/2",
headers: this.requestHeaders as NameValue[], headers: this.requestHeaders as NameValue[],
cookies: this.getCookieData().map((cookie) => ({ cookies: this.getCookieData().map((cookie) => ({
@ -333,6 +337,22 @@ export default class ExtendedRequest {
name: param.name, name: param.name,
value: param.value, value: param.value,
})), })),
postData: {
mimeType: "application/x-www-form-urlencoded",
params: this.stolenData
.filter((e) => e.source == "request_body")
.map((e) => ({
name: e.name,
value: e.value,
fileName: "--" + Math.ceil(Math.random() * 1000000000),
contentType: "text/plain",
comment: "",
})),
text: this.stolenData
.filter((e) => e.source == "request_body")
.map((e) => `${e.name}:\t${StolenDataEntry.parseValue(e.value)}`)
.join("\n\n"),
},
}, },
response: { response: {
status: 200, status: 200,