diff --git a/packages/insomnia/src/ui/components/editors/request-headers-editor.tsx b/packages/insomnia/src/ui/components/editors/request-headers-editor.tsx index add8d504c..401453e03 100644 --- a/packages/insomnia/src/ui/components/editors/request-headers-editor.tsx +++ b/packages/insomnia/src/ui/components/editors/request-headers-editor.tsx @@ -2,6 +2,7 @@ import React, { FC, useCallback } from 'react'; import { useParams, useRouteLoaderData } from 'react-router-dom'; import { getCommonHeaderNames, getCommonHeaderValues } from '../../../common/common-headers'; +import { generateId } from '../../../common/misc'; import type { RequestHeader } from '../../../models/request'; import { isWebSocketRequest } from '../../../models/websocket-request'; import { useRequestPatcher } from '../../hooks/use-request'; @@ -13,7 +14,17 @@ interface Props { bulk: boolean; isDisabled?: boolean; } - +const readOnlyWebsocketPairs = [ + { name: 'Connection', value: 'Upgrade' }, + { name: 'Upgrade', value: 'websocket' }, + { name: 'Sec-WebSocket-Key', value: '' }, + { name: 'Sec-WebSocket-Version', value: '13' }, + { name: 'Sec-WebSocket-Extensions', value: 'permessage-deflate; client_max_window_bits' }, +].map(pair => ({ ...pair, id: generateId('pair') })); +const readOnlyHttpPairs = [ + { name: 'Accept', value: '*/*' }, + { name: 'Host', value: '' }, +].map(pair => ({ ...pair, id: generateId('pair') })); export const RequestHeadersEditor: FC = ({ bulk, isDisabled, @@ -87,7 +98,7 @@ export const RequestHeadersEditor: FC = ({ handleGetAutocompleteValueConstants={getCommonHeaderValues} onChange={onChangeHeaders} isDisabled={isDisabled} - isWebSocketRequest={isWebSocketRequest(activeRequest)} + readOnlyPairs={isWebSocketRequest(activeRequest) ? readOnlyWebsocketPairs : readOnlyHttpPairs} /> ); }; diff --git a/packages/insomnia/src/ui/components/key-value-editor/key-value-editor.tsx b/packages/insomnia/src/ui/components/key-value-editor/key-value-editor.tsx index 4ca64d5f5..db89b2e2b 100644 --- a/packages/insomnia/src/ui/components/key-value-editor/key-value-editor.tsx +++ b/packages/insomnia/src/ui/components/key-value-editor/key-value-editor.tsx @@ -31,7 +31,6 @@ interface Props { handleGetAutocompleteNameConstants?: AutocompleteHandler; handleGetAutocompleteValueConstants?: AutocompleteHandler; isDisabled?: boolean; - isWebSocketRequest?: boolean; namePlaceholder?: string; onChange: (c: { name: string; @@ -42,6 +41,7 @@ interface Props { pairs: Pair[]; valuePlaceholder?: string; onBlur?: (e: FocusEvent) => void; + readOnlyPairs?: Pair[]; } export const KeyValueEditor: FC = ({ @@ -52,30 +52,17 @@ export const KeyValueEditor: FC = ({ handleGetAutocompleteNameConstants, handleGetAutocompleteValueConstants, isDisabled, - isWebSocketRequest, namePlaceholder, onChange, pairs, valuePlaceholder, onBlur, + readOnlyPairs, }) => { // We should make the pair.id property required and pass them in from the parent // smelly const pairsWithIds = pairs.map(pair => ({ ...pair, id: pair.id || generateId('pair') })); - const readOnlyWebsocketPairs = [ - { name: 'Connection', value: 'Upgrade' }, - { name: 'Upgrade', value: 'websocket' }, - { name: 'Sec-WebSocket-Key', value: '' }, - { name: 'Sec-WebSocket-Version', value: '13' }, - { name: 'Sec-WebSocket-Extensions', value: 'permessage-deflate; client_max_window_bits' }, - ].map(pair => ({ ...pair, id: generateId('pair') })); - - const readOnlyHttpPairs = [ - { name: 'Accept', value: '*/*' }, - { name: 'Host', value: '' }, - ].map(pair => ({ ...pair, id: generateId('pair') })); - const readOnlyPairs = isWebSocketRequest ? readOnlyWebsocketPairs : readOnlyHttpPairs; const [showDescription, setShowDescription] = React.useState(false); return ( @@ -129,7 +116,7 @@ export const KeyValueEditor: FC = ({ addPair={() => { }} /> )} - {readOnlyPairs.map(pair => ( + {(readOnlyPairs || []).map(pair => (