From c2ca376bdaa91ca2a5b136a2a59310144163a0d5 Mon Sep 17 00:00:00 2001 From: Codetrauma Date: Fri, 23 Aug 2024 12:44:00 -0300 Subject: [PATCH 1/2] feat: adding default browser headers to custom request builder --- src/pages/RequestBuilder/index.tsx | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) diff --git a/src/pages/RequestBuilder/index.tsx b/src/pages/RequestBuilder/index.tsx index 35411396..95bb9e0c 100644 --- a/src/pages/RequestBuilder/index.tsx +++ b/src/pages/RequestBuilder/index.tsx @@ -56,7 +56,15 @@ export default function RequestBuilder(props?: { const [method, setMethod] = useState(props?.method || 'GET'); const [type, setType] = useState('text/plain'); const [headers, setHeaders] = useState<[string, string, boolean?][]>( - props?.headers || [['Content-Type', type, true]], + props?.headers || [ + ['Content-Type', type, true], + ['Accept', '*/*', false], + ['Host', '', false], + ['Connection', 'keep-alive', false], + ['Accept-Encoding', 'gzip, deflate, br', false], + ['Accept-Language', 'en-US,en;q=0.9', false], + ['User-Agent', window.navigator.userAgent, false], + ], ); const [responseData, setResponseData] = useState<{ @@ -185,6 +193,9 @@ export default function RequestBuilder(props?: { if (k !== 'Cookie') { map[k] = v; } + if (k === 'Host') { + map[k] ? map[k] : (map[k] = url?.host || ''); + } return map; }, {}), body: body ? formatForRequest(body, type) : undefined, @@ -412,10 +423,11 @@ function HeaderTable(props: { }): ReactElement { const headers: [string, string, boolean?][] = [ ...props.headers, - ['', '', true], + ['', ' ', true], ]; const last = props.headers.length; + console.log(last); return ( @@ -450,7 +462,7 @@ function HeaderTable(props: { { props.setHeader(i, key, e.target.value); From bef61d95fb5eb3296365ce1c5a018dd0ec2af467 Mon Sep 17 00:00:00 2001 From: Codetrauma Date: Fri, 23 Aug 2024 12:54:31 -0300 Subject: [PATCH 2/2] fix: content-type setting to empty string when changing from a method with a body to a GET --- src/pages/RequestBuilder/index.tsx | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/pages/RequestBuilder/index.tsx b/src/pages/RequestBuilder/index.tsx index 95bb9e0c..2830d00a 100644 --- a/src/pages/RequestBuilder/index.tsx +++ b/src/pages/RequestBuilder/index.tsx @@ -217,7 +217,7 @@ export default function RequestBuilder(props?: { (e: React.ChangeEvent) => { const value = e.target.value; if (value === 'GET' || value === 'HEAD') { - setType(''); + // setType(''); Leaving this here for now - I feel like I did this for a specific reason but I can't remember why setMethod(value); } else { setMethod(value); @@ -427,7 +427,6 @@ function HeaderTable(props: { ]; const last = props.headers.length; - console.log(last); return (