Created
November 18, 2022 18:28
-
-
Save omz13/06033ff9b2aca23f18443494aba2d826 to your computer and use it in GitHub Desktop.
an experimental patch for quic-go per issue #3603
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
diff --git a/http3/server.go b/http3/server.go | |
index 0455895ec648342a88264b462eee66cb0e49b778..0c1c792c03ef78e8f43e184af39dcb29a8b0b915 100644 | |
--- a/http3/server.go | |
+++ b/http3/server.go | |
@@ -583,6 +583,7 @@ func (s *Server) handleRequest(conn quic.Connection, str quic.Stream, decoder *q | |
ctx := str.Context() | |
ctx = context.WithValue(ctx, ServerContextKey, s) | |
ctx = context.WithValue(ctx, http.LocalAddrContextKey, conn.LocalAddr()) | |
+ ctx = context.WithValue(ctx, quic.ConnectionTracingKey, conn.Context().Value(quic.ConnectionTracingKey)) | |
req = req.WithContext(ctx) | |
r := newResponseWriter(str, conn, s.logger) | |
defer r.Flush() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import ( | |
"github.com/lucas-clemente/quic-go" | |
"github.com/lucas-clemente/quic-go/http3" | |
) | |
func Foo(w http.ResponseWriter, r *http.Request) { | |
traceID := "" | |
// this is something dirty added to local/go-quic so we can peek into the | |
// underlying connection associated the handler | |
if h3connI := r.Context().Value("h3conn"); h3connI != nil { | |
// spew.Dump(h3connI) | |
if h3conn, ok := h3connI.(quic.Connection); ok { | |
if tkV, ok := h3conn.Context().Value(quic.ConnectionTracingKey).(uint64); ok { | |
// traceID = strconv.FormatUint(tk, 16) | |
tk := strconv.FormatUint(tkV, 16) | |
traceID = strings.Repeat("0", 20-len(tk)) + tk | |
} | |
} | |
} else { | |
// redacted | |
// but here you assume H1 or H2 connection and try | |
// to get data from different context value | |
} | |
if traceID == "" { | |
traceID = "-" | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment