srdusr
aboutsummaryrefslogtreecommitdiffstats
path: root/internal/ipc/ipc.go
diff options
context:
space:
mode:
authorsrdusr <[email protected]>2024-08-29 22:03:00 +0200
committersrdusr <[email protected]>2024-08-29 22:03:00 +0200
commit70f675e59ac4bb0e469ca0073f8cc0506b17677e (patch)
treee3a525b26dfcf16ce4f9bde97b1408a373d87944 /internal/ipc/ipc.go
parent8d15c2e0b326933f8fc912e3b13f37e78a9bc0b6 (diff)
downloadmitmux-70f675e59ac4bb0e469ca0073f8cc0506b17677e.tar.gz
mitmux-70f675e59ac4bb0e469ca0073f8cc0506b17677e.zip
Repeater: raw-byte send/resend
Implements build-order step 4, the feature the plan calls out as used daily. internal/proxy/repeat.go adds Server.Repeat(scheme, host, raw): dials fresh (HTTP/1.1-only - raw edited text has no equivalent in HTTP/2's binary framing), writes raw exactly as given with no framing correction or header injection, and captures the exact response bytes. This is deliberately separate from forward()'s parsed-*http.Request path since Repeater's entire point is letting a malformed/edited request reach the wire unmodified. Repeater sends are recorded to the same history table as proxy traffic (added a "source" column: "proxy" vs "repeater") so they show up in the unified history view and the live subscribe stream, not a separate silo. internal/ipc gains a "repeat" request/response pair; cmd/mitmuxd wires proxy.Server into ipc.NewServer via a small Repeater interface so the daemon keeps owning all network I/O and the TUI stays a thin client. cmd/mitmux gains a repeater view (bubbles/textarea for the editable raw request, a read-only viewport for the response), reachable with 'r' from either the list or detail view, ctrl+r to send. One real bug found via testing: bubbles/textarea only understands LF, but HTTP/1.1 requires CRLF, so loading raw bytes straight into it split each line in two on render. Fixed by normalizing CRLF<->LF at the editor boundary only (load: strip \r; send: restore it) - documented as a narrow, known trade-off for bodies with their own embedded LF line breaks, which is the cost of being able to edit raw HTTP as text at all. Verified live: edited and sent a plain-HTTP repeater request (confirmed in SQLite that the edit - including an intentional extra blank line from imprecise cursor navigation during testing - went out completely unmodified, which is the correct behavior: mitmux must never "fix" what the user typed), and sent an HTTPS repeater request against a freshly captured entry, both getting real 200 responses with exact response bytes back.
Diffstat (limited to 'internal/ipc/ipc.go')
-rw-r--r--internal/ipc/ipc.go28
1 files changed, 25 insertions, 3 deletions
diff --git a/internal/ipc/ipc.go b/internal/ipc/ipc.go
index c9d92b4..b1a997a 100644
--- a/internal/ipc/ipc.go
+++ b/internal/ipc/ipc.go
@@ -15,17 +15,22 @@ import (
// Request is sent by a client to the daemon.
type Request struct {
- Type string `json:"type"` // "list", "get", or "subscribe"
+ Type string `json:"type"` // "list", "get", "subscribe", or "repeat"
Limit int `json:"limit,omitempty"`
BeforeID int64 `json:"before_id,omitempty"`
ID int64 `json:"id,omitempty"`
+
+ // For "repeat": send Raw to scheme://host exactly as given.
+ Scheme string `json:"scheme,omitempty"`
+ Host string `json:"host,omitempty"`
+ Raw []byte `json:"raw,omitempty"`
}
// Response is sent by the daemon to a client.
type Response struct {
- Type string `json:"type"` // "list", "get", "new", or "error"
+ Type string `json:"type"` // "list", "get", "new", "repeat", or "error"
Entries []store.Summary `json:"entries,omitempty"` // for "list"
- Detail *EntryDetail `json:"detail,omitempty"` // for "get"
+ Detail *EntryDetail `json:"detail,omitempty"` // for "get" and "repeat"
New *store.Summary `json:"new,omitempty"` // for "new" (subscribe push)
Error string `json:"error,omitempty"`
}
@@ -92,6 +97,23 @@ func (c *Client) Get(id int64) (*EntryDetail, error) {
return resp.Detail, nil
}
+// Repeat sends raw to scheme://host exactly as given (no re-serialization,
+// no header injection) and returns the resulting entry, including the raw
+// response bytes. The exchange is also recorded to history.
+func (c *Client) Repeat(scheme, host string, raw []byte) (*EntryDetail, error) {
+ if err := c.enc.Encode(Request{Type: "repeat", Scheme: scheme, Host: host, Raw: raw}); err != nil {
+ return nil, err
+ }
+ var resp Response
+ if err := c.dec.Decode(&resp); err != nil {
+ return nil, err
+ }
+ if resp.Type == "error" {
+ return nil, errors.New(resp.Error)
+ }
+ return resp.Detail, nil
+}
+
// Subscribe opens a dedicated connection that streams newly captured
// history entries as they happen. The returned channel is closed when
// the connection ends; call the returned close func to stop early.