Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

martian: log with request ctx in h2writer #934

Merged
merged 1 commit into from
Oct 7, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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