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 8023b22 commit 6186044
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 3 deletions.
3 changes: 3 additions & 0 deletions mitmproxy/tools/web/app.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import asyncio
from email.policy import strict
import hashlib
import json
import logging
Expand Down Expand Up @@ -392,6 +393,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
24 changes: 21 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.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,20 @@ 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();
if (flow.request.method === 'GET') {
await dispatch(flowActions.update(flow, {
[part]: {
query: content?.split("\n").map(item => item.split('='))
}
}));
} else {
await dispatch(flowActions.update(flow, {
[part]: {
content
}
}));
}
setEdit(false);
}
return (
Expand Down

0 comments on commit 6186044

Please sign in to comment.