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 de84701
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 3 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
* Added Magisk module generation for Android onboarding (@jorants).
* Update Linux binary builder to Ubuntu 20.04, bumping the minimum glibc version to 2.31. (@jorants)
* Render application/prpc content as gRPC/Protocol Buffers (@selfisekai)
* Fix Query editing on mitmweb (@yesmeck).

## 28 June 2022: mitmproxy 8.1.1

Expand Down
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
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.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 de84701

Please sign in to comment.