Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 18 additions & 1 deletion frontend/src/features/soar/components/HttpParamsEditor.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,13 @@ const METHODS = ['GET', 'POST', 'PUT', 'PATCH', 'DELETE', 'HEAD', 'OPTIONS'] as
const BODY_METHODS = new Set<string>(['POST', 'PUT', 'PATCH'])
const SCHEMES = ['https', 'http'] as const
const EMPTY_ROWS: Array<[string, string]> = []
const DEFAULT_HEADER_ROWS: Array<[string, string]> = [
['Access-Control-Allow-Origin', '*'],
['Content-Type', 'application/json'],
['Accept', '*/*'],
['Accept-Encoding', 'gzip, deflate, br'],
['Connection', 'keep-alive'],
]
type Row = [string, string]
type RowCache = { rows: Row[]; selected: boolean[] }
const HTTP_ROWS_CACHE = new Map<string, RowCache>()
Expand Down Expand Up @@ -52,6 +59,7 @@ export function HttpParamsEditor({ nodeId, nodes, params: httpParams, readOnly,
const urlRef = useRef<HTMLInputElement>(null)
const bodyRef = useRef<HTMLTextAreaElement>(null)
const queryParamsRef = useRef<Record<string, string>>(queryParams)
const defaultHeadersNodeRef = useRef<string | null>(null)
const activeQueryParams = getActiveQueryParams(nodeId, queryParamsRef.current, queryParams)
const previewBaseUrl = p.url || (rest.trim() ? `${scheme}://${rest}` : '')
const fullUrlPreview = appendQueryParams(previewBaseUrl, activeQueryParams)
Expand Down Expand Up @@ -89,6 +97,14 @@ export function HttpParamsEditor({ nodeId, nodes, params: httpParams, readOnly,
onChange({ ...current, ...changes })
}

useEffect(() => {
if (readOnly || defaultHeadersNodeRef.current === nodeId) return
defaultHeadersNodeRef.current = nodeId
if (!p.headers) {
emit({ headers: Object.fromEntries(DEFAULT_HEADER_ROWS) })
}
}, [nodeId, p.headers, readOnly])

const commitUrl = (nextScheme: string, nextRest: string) => {
const trimmed = nextRest.trim()
const activeParams = getActiveQueryParams(nodeId, queryParamsRef.current, queryParams)
Expand Down Expand Up @@ -392,7 +408,7 @@ function KeyValueRows({
if (!nextSelected[index]) return
if (k.trim()) out[k.trim()] = v
})
onChange(Object.keys(out).length > 0 ? out : undefined)
onChange(out)
}

const setAt = (i: number, patch: { key?: string; value?: string }) => {
Expand Down Expand Up @@ -566,6 +582,7 @@ function HeaderRows({
<KeyValueRows
title={t('soar.editor.canvas.http.headers')}
values={headers}
defaultRows={DEFAULT_HEADER_ROWS}
addLabel={t('soar.editor.canvas.http.addHeader')}
readOnly={readOnly}
nodes={nodes}
Expand Down
5 changes: 2 additions & 3 deletions frontend/src/features/soar/types/soar.types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -158,9 +158,8 @@ export const EXECUTOR_CATALOG: ExecutorMeta[] = [
method: 'GET',
url: '',
headers: {
'Postman-Token': '<calculated when request is sent>',
Host: '<calculated when request is sent>',
'User-Agent': 'PostmanRuntime/7.43.0',
'Access-Control-Allow-Origin': '*',
'Content-Type': 'application/json',
Accept: '*/*',
'Accept-Encoding': 'gzip, deflate, br',
Connection: 'keep-alive',
Expand Down
Loading