Skip to content

Commit

Permalink
[web] fix query editing
Browse files Browse the repository at this point in the history
  • Loading branch information
yesmeck committed Sep 9, 2022
1 parent 57c71ea commit 1abff02
Show file tree
Hide file tree
Showing 6 changed files with 35 additions and 6 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@
([#5548](https://github.com/mitmproxy/mitmproxy/pull/5548), @sanlengjingvv)
* Fix a mitmweb crash when scrolling down the flow list.
([#5507](https://github.com/mitmproxy/mitmproxy/pull/5507), @LIU-shuyi)
* Fix query editing on mitmweb.
([#5574](https://github.com/mitmproxy/mitmproxy/pull/5574), @yesmeck)

## 28 June 2022: mitmproxy 8.1.1

Expand Down
2 changes: 2 additions & 0 deletions mitmproxy/tools/web/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -392,6 +392,8 @@ def put(self, flow_id):
request.trailers.add(*trailer)
elif k == "content":
request.text = v
elif k == "query":
request.query = [tuple(i) for i in v]
else:
raise APIError(400, f"Unknown update request.{k}: {v}")

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,15 @@ import HttpMessage, {ViewImage} from '../../../components/contentviews/HttpMessa
import {fireEvent, render, screen, waitFor} from "../../test-utils"
import fetchMock, {enableFetchMocks} from "jest-fetch-mock";

jest.mock("../../../contrib/CodeMirror")
jest.mock("../../../contrib/CodeMirror", () => {
const React = require('react');
return {
__esModule: true,
default: React.forwardRef((props, ref) => {
return <div>{props.value}</div>
})
}
})

enableFetchMocks();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,12 @@ exports[`HttpMessage 2`] = `
</div>
<div
class="codeeditor"
/>
>
<div>
foo=1
bar=2
</div>
</div>
</div>
</DocumentFragment>
`;
Expand Down
2 changes: 1 addition & 1 deletion web/src/js/__tests__/ducks/_tflow.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ export function THTTPFlow(): Required<HTTPFlow> {
"host": "address",
"http_version": "HTTP/1.1",
"method": "GET",
"path": "/path",
"path": "/path?foo=1&bar=2",
"port": 22,
"pretty_host": "address",
"scheme": "http",
Expand Down
18 changes: 15 additions & 3 deletions web/src/js/components/contentviews/HttpMessage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,13 @@ export default function HttpMessage({flow, message}: HttpMessageProps) {
} else {
url = MessageUtils.getContentURL(flow, message, contentView, maxLines + 1);
}
const content = useContent(url, message.contentHash);
let content = useContent(url, message.contentHash);
if (flow.request.method === "GET" && edit) {
const params = new URLSearchParams(new URL(`${flow.request.scheme}://${flow.request.host}/${flow.request.path}`).search);
content = Array.from(params.entries())
.reduce((acc, [key, value]) => [...acc, `${key}=${value}`], [])
.join("\n");
}
const contentViewData = useMemo<ContentViewData | undefined>(() => {
if (content && !edit) {
try {
Expand All @@ -48,8 +54,14 @@ export default function HttpMessage({flow, message}: HttpMessageProps) {

if (edit) {
const save = async () => {
const content = editorRef.current?.getContent();
await dispatch(flowActions.update(flow, {[part]: {content}}));
let content = editorRef.current?.getContent();
await dispatch(flowActions.update(flow, {
[part]: flow.request.method === 'GET' ? {
query: content?.split("\n").map(item => item.split('='))
}: {
content
}
}));
setEdit(false);
}
return (
Expand Down

0 comments on commit 1abff02

Please sign in to comment.