Skip to content

Commit

Permalink
martian: log with request ctx in h2writer
Browse files Browse the repository at this point in the history
  • Loading branch information
Choraden authored and mmatczuk committed Oct 7, 2024
1 parent 329d883 commit 873afde
Showing 1 changed file with 4 additions and 3 deletions.
7 changes: 4 additions & 3 deletions internal/martian/proxy_handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
package martian

import (
"context"
"fmt"
"io"
"net/http"
Expand Down Expand Up @@ -310,13 +309,15 @@ func (p proxyHandler) handleRequest(rw http.ResponseWriter, req *http.Request) {
}

type h2Writer struct {
req *http.Request
w io.Writer
flush func() error
close func() error
}

func makeH2Writer(rw http.ResponseWriter, rc *http.ResponseController, req *http.Request) h2Writer {
return h2Writer{
req: req,
w: rw,
flush: rc.Flush,
close: req.Body.Close,
Expand All @@ -328,7 +329,7 @@ func (w h2Writer) Write(p []byte) (n int, err error) {

if n > 0 {
if err := w.flush(); err != nil {
log.Errorf(context.TODO(), "got error while flushing response back to client: %v", err)
log.Errorf(w.req.Context(), "got error while flushing response back to client: %v", err)
}
}

Expand All @@ -338,7 +339,7 @@ func (w h2Writer) Write(p []byte) (n int, err error) {
func (w h2Writer) CloseWrite() error {
// Send any DATA frames buffered in the transport.
if err := w.flush(); err != nil {
log.Errorf(context.TODO(), "got error while flushing response back to client: %v", err)
log.Errorf(w.req.Context(), "got error while flushing response back to client: %v", err)
}
// Close request body to signal the end of the request.
// This results RST_STREAM frame with error code NO_ERROR to be sent to the other side.
Expand Down

0 comments on commit 873afde

Please sign in to comment.