Skip to content

Commit

Permalink
changes PRs-review
Browse files Browse the repository at this point in the history
  • Loading branch information
PavelMor25 committed Dec 6, 2023
1 parent e8b3bee commit 1f5a5fd
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 7 deletions.
6 changes: 3 additions & 3 deletions src/native-automation/request-pipeline/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import CertificateErrorEvent = Protocol.Security.CertificateErrorEvent;
import HeaderEntry = Protocol.Fetch.HeaderEntry;
import NativeAutomationRequestHookEventProvider from '../request-hooks/event-provider';
import ResourceInjector, { ResourceInjectorOptions } from '../resource-injector';
import { convertToHeaderEntries, getHeader } from '../utils/headers';
import { convertToHeaderEntries, getHeaderValue } from '../utils/headers';

import {
createRequestPausedEventForResponse,
Expand Down Expand Up @@ -154,7 +154,7 @@ export default class NativeAutomationRequestPipeline extends NativeAutomationApi
await this._resourceInjector.processNonProxiedContent(fulfillInfo, this._client, sessionId);
else {
const userScripts = await this._getUserScripts(event);
const contentType = getHeader(event.responseHeaders, 'content-type');
const contentType = getHeaderValue(event.responseHeaders, 'content-type');

await this._resourceInjector.processHTMLPageContent(fulfillInfo, {
isIframe: false,
Expand Down Expand Up @@ -199,7 +199,7 @@ export default class NativeAutomationRequestPipeline extends NativeAutomationApi
return;
}

const contentType = getHeader(event.responseHeaders, 'content-type');
const contentType = getHeaderValue(event.responseHeaders, 'content-type');
const resourceInfo = await this._resourceInjector.getDocumentResourceInfo(event, this._client, contentType as string);

if (resourceInfo.error) {
Expand Down
4 changes: 2 additions & 2 deletions src/native-automation/utils/headers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ export function convertToOutgoingHttpHeaders (headers: HeaderEntry[] | undefined
}, {});
}

export function getHeader (headers: HeaderEntry[] | undefined, headerName: string): string {
return headers?.find(header => header.name === headerName)?.value || '';
export function getHeaderValue (headers: HeaderEntry[] | undefined, headerName: string): string | null {
return headers?.find(header => header.name.toLowerCase() === headerName)?.value || null;
}

4 changes: 2 additions & 2 deletions src/native-automation/utils/string.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import GetResponseBodyResponse = Protocol.Network.GetResponseBodyResponse;
import HeaderEntry = Protocol.Fetch.HeaderEntry;
import { decodeBufferToString, encodeStringToBuffer } from 'testcafe-hammerhead';

export function getResponseAsString (response: GetResponseBodyResponse, contentType = ''): string {
export function getResponseAsString (response: GetResponseBodyResponse, contentType = 'charset=utf-8'): string {
const bufferBody = getResponseAsBuffer(response);

return decodeBufferToString(bufferBody, contentType);
Expand All @@ -15,7 +15,7 @@ export function getResponseAsBuffer (response: GetResponseBodyResponse): Buffer
: Buffer.from(response.body);
}

export function toBase64String (str: string, contentType = ''): string {
export function toBase64String (str: string, contentType = 'charset=utf-8'): string {
const bufferBody = encodeStringToBuffer(str, contentType);

return bufferBody.toString('base64');
Expand Down

0 comments on commit 1f5a5fd

Please sign in to comment.