fix disabled user-agent (#6459)

This commit is contained in:
Jack Kavanagh 2023-09-07 13:19:11 +02:00 committed by GitHub
parent 2e5b963e89
commit cc9f7590e4
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 13 additions and 1 deletions

View File

@ -36,6 +36,7 @@ export type RenderedRequest = Request & {
disabled?: boolean;
}[];
cookieJar: CookieJar;
suppressUserAgent: boolean;
};
export type RenderedGrpcRequest = GrpcRequest;
@ -495,6 +496,7 @@ export async function getRenderedRequestAndContext(
const renderedRequest = renderResult._request;
const renderedCookieJar = renderResult._cookieJar;
renderedRequest.description = await render(description, renderContext, null, KEEP_ON_ERROR);
const suppressUserAgent = request.headers.some(h => h.name.toLowerCase() === 'user-agent' && h.disabled === true);
// Remove disabled params
renderedRequest.parameters = renderedRequest.parameters.filter(p => !p.disabled);
// Remove disabled headers
@ -515,6 +517,7 @@ export async function getRenderedRequestAndContext(
return {
context: renderContext,
request: {
suppressUserAgent,
cookieJar: renderedCookieJar,
cookies: [],
isPrivate: false,

View File

@ -90,6 +90,7 @@ interface OpenCurlRequestOptions {
authentication: RequestAuthentication;
cookieJar: CookieJar;
initialPayload?: string;
suppressUserAgent: boolean;
}
const openCurlConnection = async (
_event: Electron.IpcMainInvokeEvent,
@ -137,7 +138,7 @@ const openCurlConnection = async (
const clientCertificates = await models.clientCertificate.findByParentId(options.workspaceId);
const filteredClientCertificates = clientCertificates.filter(c => !c.disabled && urlMatchesCertHost(setDefaultProtocol(c.host, 'https:'), options.url));
const { curl, debugTimeline } = createConfiguredCurlInstance({
req: { ...request, cookieJar: options.cookieJar, cookies: [] },
req: { ...request, cookieJar: options.cookieJar, cookies: [], suppressUserAgent: options.suppressUserAgent },
finalUrl: options.url,
settings,
caCert: caCertificate,

View File

@ -41,6 +41,7 @@ interface RequestUsedHere {
url: string;
cookieJar: any;
cookies: { name: string; value: string }[];
suppressUserAgent: boolean;
}
interface SettingsUsedHere {
preferredHttpVersion: string;
@ -376,6 +377,9 @@ export const createConfiguredCurlInstance = ({
const userAgent: RequestHeader | null = headers.find((h: any) => h.name.toLowerCase() === 'user-agent') || null;
const userAgentOrFallback = typeof userAgent?.value === 'string' ? userAgent?.value : 'insomnia/' + version;
curl.setOpt(Curl.option.USERAGENT, userAgentOrFallback);
if (req.suppressUserAgent) {
curl.setOpt(Curl.option.USERAGENT, '');
}
const { username, password, disabled } = authentication;
const isDigest = authentication.type === AUTH_DIGEST;

View File

@ -140,6 +140,7 @@ export const RequestUrlBar = forwardRef<RequestUrlBarHandle, Props>(({
headers: rendered.headers,
authentication: rendered.authentication,
cookieJar: rendered.workspaceCookieJar,
suppressUserAgent: rendered.suppressUserAgent,
});
};
startListening();

View File

@ -106,6 +106,7 @@ export const WebSocketActionBar: FC<ActionBarProps> = ({ request, environmentId,
headers: rendered.headers,
authentication: rendered.authentication,
cookieJar: rendered.workspaceCookieJar,
suppressUserAgent: rendered.suppressUserAgent,
});
};

View File

@ -248,6 +248,7 @@ export interface ConnectActionParams {
headers: RequestHeader[];
authentication: RequestAuthentication;
cookieJar: CookieJar;
suppressUserAgent: boolean;
}
export const connectAction: ActionFunction = async ({ request, params }) => {
const { requestId, workspaceId } = params;
@ -274,6 +275,7 @@ export const connectAction: ActionFunction = async ({ request, params }) => {
headers: rendered.headers,
authentication: rendered.authentication,
cookieJar: rendered.cookieJar,
suppressUserAgent: rendered.suppressUserAgent,
});
}
// HACK: even more elaborate hack to get the request to update