mirror of
https://github.com/dstotijn/hetty.git
synced 2025-07-01 18:47:29 -04:00
Sort HTTP headers
This commit is contained in:
@ -7,7 +7,7 @@ import { useRouter } from "next/router";
|
|||||||
import React, { useEffect, useState } from "react";
|
import React, { useEffect, useState } from "react";
|
||||||
|
|
||||||
import { useInterceptedRequests } from "lib/InterceptedRequestsContext";
|
import { useInterceptedRequests } from "lib/InterceptedRequestsContext";
|
||||||
import { KeyValuePair, sortKeyValuePairs } from "lib/components/KeyValuePair";
|
import { KeyValuePair } from "lib/components/KeyValuePair";
|
||||||
import Link from "lib/components/Link";
|
import Link from "lib/components/Link";
|
||||||
import RequestTabs from "lib/components/RequestTabs";
|
import RequestTabs from "lib/components/RequestTabs";
|
||||||
import ResponseStatus from "lib/components/ResponseStatus";
|
import ResponseStatus from "lib/components/ResponseStatus";
|
||||||
@ -112,11 +112,11 @@ function EditRequest(): JSX.Element {
|
|||||||
newQueryParams.push({ key: "", value: "" });
|
newQueryParams.push({ key: "", value: "" });
|
||||||
setQueryParams(newQueryParams);
|
setQueryParams(newQueryParams);
|
||||||
|
|
||||||
const newReqHeaders = sortKeyValuePairs(interceptedRequest.headers || []);
|
const newReqHeaders = interceptedRequest.headers || [];
|
||||||
setReqHeaders([...newReqHeaders.map(({ key, value }) => ({ key, value })), { key: "", value: "" }]);
|
setReqHeaders([...newReqHeaders.map(({ key, value }) => ({ key, value })), { key: "", value: "" }]);
|
||||||
|
|
||||||
setResBody(interceptedRequest.response?.body || "");
|
setResBody(interceptedRequest.response?.body || "");
|
||||||
const newResHeaders = sortKeyValuePairs(interceptedRequest.response?.headers || []);
|
const newResHeaders = interceptedRequest.response?.headers || [];
|
||||||
setResHeaders([...newResHeaders.map(({ key, value }) => ({ key, value })), { key: "", value: "" }]);
|
setResHeaders([...newResHeaders.map(({ key, value }) => ({ key, value })), { key: "", value: "" }]);
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
@ -3,7 +3,7 @@ import { Alert, Box, Button, Fab, Tooltip, Typography, useTheme } from "@mui/mat
|
|||||||
import { useRouter } from "next/router";
|
import { useRouter } from "next/router";
|
||||||
import React, { useState } from "react";
|
import React, { useState } from "react";
|
||||||
|
|
||||||
import { KeyValuePair, sortKeyValuePairs } from "lib/components/KeyValuePair";
|
import { KeyValuePair } from "lib/components/KeyValuePair";
|
||||||
import RequestTabs from "lib/components/RequestTabs";
|
import RequestTabs from "lib/components/RequestTabs";
|
||||||
import Response from "lib/components/Response";
|
import Response from "lib/components/Response";
|
||||||
import SplitPane from "lib/components/SplitPane";
|
import SplitPane from "lib/components/SplitPane";
|
||||||
@ -90,7 +90,7 @@ function EditRequest(): JSX.Element {
|
|||||||
newQueryParams.push({ key: "", value: "" });
|
newQueryParams.push({ key: "", value: "" });
|
||||||
setQueryParams(newQueryParams);
|
setQueryParams(newQueryParams);
|
||||||
|
|
||||||
const newHeaders = sortKeyValuePairs(senderRequest.headers || []);
|
const newHeaders = senderRequest.headers || [];
|
||||||
setHeaders([...newHeaders.map(({ key, value }) => ({ key, value })), { key: "", value: "" }]);
|
setHeaders([...newHeaders.map(({ key, value }) => ({ key, value })), { key: "", value: "" }]);
|
||||||
setResponse(senderRequest.response);
|
setResponse(senderRequest.response);
|
||||||
},
|
},
|
||||||
|
@ -184,20 +184,4 @@ export function KeyValuePairTable({ items, onChange, onDelete }: KeyValuePairTab
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
export function sortKeyValuePairs(items: KeyValuePair[]): KeyValuePair[] {
|
|
||||||
const sorted = [...items];
|
|
||||||
|
|
||||||
sorted.sort((a, b) => {
|
|
||||||
if (a.key < b.key) {
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
if (a.key > b.key) {
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
return 0;
|
|
||||||
});
|
|
||||||
|
|
||||||
return sorted;
|
|
||||||
}
|
|
||||||
|
|
||||||
export default KeyValuePairTable;
|
export default KeyValuePairTable;
|
||||||
|
@ -1,6 +1,5 @@
|
|||||||
import { Box, Typography } from "@mui/material";
|
import { Box, Typography } from "@mui/material";
|
||||||
|
|
||||||
import { sortKeyValuePairs } from "./KeyValuePair";
|
|
||||||
import ResponseTabs from "./ResponseTabs";
|
import ResponseTabs from "./ResponseTabs";
|
||||||
|
|
||||||
import ResponseStatus from "lib/components/ResponseStatus";
|
import ResponseStatus from "lib/components/ResponseStatus";
|
||||||
@ -29,7 +28,7 @@ function Response({ response }: ResponseProps): JSX.Element {
|
|||||||
</Box>
|
</Box>
|
||||||
<ResponseTabs
|
<ResponseTabs
|
||||||
body={response?.body}
|
body={response?.body}
|
||||||
headers={sortKeyValuePairs(response?.headers || [])}
|
headers={response?.headers || []}
|
||||||
hasResponse={response !== undefined && response !== null}
|
hasResponse={response !== undefined && response !== null}
|
||||||
/>
|
/>
|
||||||
</Box>
|
</Box>
|
||||||
|
@ -49,3 +49,17 @@ func UnmarshalURL(v interface{}) (*url.URL, error) {
|
|||||||
|
|
||||||
return u, nil
|
return u, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type HTTPHeaders []HTTPHeader
|
||||||
|
|
||||||
|
func (h HTTPHeaders) Len() int {
|
||||||
|
return len(h)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (h HTTPHeaders) Less(i, j int) bool {
|
||||||
|
return h[i].Key < h[j].Key
|
||||||
|
}
|
||||||
|
|
||||||
|
func (h HTTPHeaders) Swap(i, j int) {
|
||||||
|
h[i], h[j] = h[j], h[i]
|
||||||
|
}
|
||||||
|
@ -11,6 +11,7 @@ import (
|
|||||||
"io/ioutil"
|
"io/ioutil"
|
||||||
"net/http"
|
"net/http"
|
||||||
"regexp"
|
"regexp"
|
||||||
|
"sort"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
"github.com/99designs/gqlgen/graphql"
|
"github.com/99designs/gqlgen/graphql"
|
||||||
@ -124,6 +125,8 @@ func parseRequestLog(reqLog reqlog.RequestLog) (HTTPRequestLog, error) {
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
sort.Sort(HTTPHeaders(log.Headers))
|
||||||
}
|
}
|
||||||
|
|
||||||
if reqLog.Response != nil {
|
if reqLog.Response != nil {
|
||||||
@ -172,6 +175,8 @@ func parseResponseLog(resLog reqlog.ResponseLog) (HTTPResponseLog, error) {
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
sort.Sort(HTTPHeaders(httpResLog.Headers))
|
||||||
}
|
}
|
||||||
|
|
||||||
return httpResLog, nil
|
return httpResLog, nil
|
||||||
@ -710,6 +715,8 @@ func parseSenderRequest(req sender.Request) (SenderRequest, error) {
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
sort.Sort(HTTPHeaders(senderReq.Headers))
|
||||||
}
|
}
|
||||||
|
|
||||||
if len(req.Body) > 0 {
|
if len(req.Body) > 0 {
|
||||||
@ -765,6 +772,8 @@ func parseHTTPRequest(req *http.Request) (HTTPRequest, error) {
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
sort.Sort(HTTPHeaders(httpReq.Headers))
|
||||||
}
|
}
|
||||||
|
|
||||||
if req.Body != nil {
|
if req.Body != nil {
|
||||||
@ -815,6 +824,8 @@ func parseHTTPResponse(res *http.Response) (HTTPResponse, error) {
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
sort.Sort(HTTPHeaders(httpRes.Headers))
|
||||||
}
|
}
|
||||||
|
|
||||||
if res.Body != nil {
|
if res.Body != nil {
|
||||||
|
Reference in New Issue
Block a user