diff options
Diffstat (limited to 'internal/proxy/proxy.go')
| -rw-r--r-- | internal/proxy/proxy.go | 43 |
1 files changed, 23 insertions, 20 deletions
diff --git a/internal/proxy/proxy.go b/internal/proxy/proxy.go index 82328db..08b8551 100644 --- a/internal/proxy/proxy.go +++ b/internal/proxy/proxy.go @@ -383,8 +383,8 @@ func (s *Server) forward(dial dialer, scheme, hostname string, w http.ResponseWr started := time.Now() conn, negotiated, dialErr := dial(r.Context()) if dialErr != nil { - reqRaw, reqExact := captureRequest(r, clientTee, reqBodyCap) - s.record(started, time.Since(started), scheme, hostname, r, reqRaw, reqExact, nil, false, 0, dialErr.Error()) + reqRaw, reqExact, reqTrunc := captureRequest(r, clientTee, reqBodyCap) + s.record(started, time.Since(started), scheme, hostname, r, reqRaw, reqExact, reqTrunc, nil, false, false, 0, dialErr.Error()) http.Error(w, dialErr.Error(), http.StatusBadGateway) return } @@ -412,10 +412,10 @@ func (s *Server) forward(dial dialer, scheme, hostname string, w http.ResponseWr } duration := time.Since(started) - reqRaw, reqExact := captureRequest(r, clientTee, reqBodyCap) + reqRaw, reqExact, reqTrunc := captureRequest(r, clientTee, reqBodyCap) if err != nil { - s.record(started, duration, scheme, hostname, r, reqRaw, reqExact, nil, false, 0, err.Error()) + s.record(started, duration, scheme, hostname, r, reqRaw, reqExact, reqTrunc, nil, false, false, 0, err.Error()) http.Error(w, err.Error(), http.StatusBadGateway) return } @@ -448,14 +448,15 @@ func (s *Server) forward(dial dialer, scheme, hostname string, w http.ResponseWr io.Copy(w, resp.Body) var respRaw []byte - var respExact bool + var respExact, respTrunc bool if upstreamTee != nil { - respRaw, respExact = upstreamTee.Take(), true + respRaw, respTrunc = upstreamTee.Take() + respExact = !respTrunc } else { respRaw, respExact = captureResponse(resp, respBodyCap) } - s.record(started, duration, scheme, hostname, r, reqRaw, reqExact, respRaw, respExact, resp.StatusCode, "") + s.record(started, duration, scheme, hostname, r, reqRaw, reqExact, reqTrunc, respRaw, respExact, respTrunc, resp.StatusCode, "") } // enabledRules fetches the current enabled match-and-replace rules for @@ -471,24 +472,26 @@ func (s *Server) enabledRules(scope string) ([]rules.Rule, error) { // record stores one history entry and notifies OnEntry. func (s *Server) record(started time.Time, duration time.Duration, scheme, host string, r *http.Request, - reqRaw []byte, reqExact bool, respRaw []byte, respExact bool, status int, errMsg string) { + reqRaw []byte, reqExact, reqTruncated bool, respRaw []byte, respExact, respTruncated bool, status int, errMsg string) { if s.store == nil { return } e := &store.Entry{ - StartedAt: started, - Duration: duration, - Method: r.Method, - Scheme: scheme, - Host: host, - Path: r.URL.Path, - StatusCode: status, - RequestRaw: reqRaw, - ResponseRaw: respRaw, - RequestExact: reqExact, - ResponseExact: respExact, - Error: errMsg, + StartedAt: started, + Duration: duration, + Method: r.Method, + Scheme: scheme, + Host: host, + Path: r.URL.Path, + StatusCode: status, + RequestRaw: reqRaw, + ResponseRaw: respRaw, + RequestExact: reqExact, + ResponseExact: respExact, + RequestTruncated: reqTruncated, + ResponseTruncated: respTruncated, + Error: errMsg, } id, err := s.store.Insert(e) if err != nil { |