mirror of
https://github.com/Kong/insomnia
synced 2024-11-08 06:39:48 +00:00
fix disabled user-agent (#6459)
This commit is contained in:
parent
2e5b963e89
commit
cc9f7590e4
@ -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,
|
||||
|
@ -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,
|
||||
|
@ -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;
|
||||
|
@ -140,6 +140,7 @@ export const RequestUrlBar = forwardRef<RequestUrlBarHandle, Props>(({
|
||||
headers: rendered.headers,
|
||||
authentication: rendered.authentication,
|
||||
cookieJar: rendered.workspaceCookieJar,
|
||||
suppressUserAgent: rendered.suppressUserAgent,
|
||||
});
|
||||
};
|
||||
startListening();
|
||||
|
@ -106,6 +106,7 @@ export const WebSocketActionBar: FC<ActionBarProps> = ({ request, environmentId,
|
||||
headers: rendered.headers,
|
||||
authentication: rendered.authentication,
|
||||
cookieJar: rendered.workspaceCookieJar,
|
||||
suppressUserAgent: rendered.suppressUserAgent,
|
||||
});
|
||||
|
||||
};
|
||||
|
@ -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
|
||||
|
Loading…
Reference in New Issue
Block a user