Skip to content

Commit

Permalink
http3: replace slog with req's logger
Browse files Browse the repository at this point in the history
  • Loading branch information
imroc committed Sep 11, 2024
1 parent dcdcd1a commit 551b96d
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 32 deletions.
20 changes: 8 additions & 12 deletions internal/http3/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import (
"context"
"errors"
"io"
"log/slog"
"net/http"
"net/http/httptrace"
"net/textproto"
Expand Down Expand Up @@ -53,8 +52,6 @@ type SingleDestinationRoundTripper struct {
StreamHijacker func(FrameType, quic.ConnectionTracingID, quic.Stream, error) (hijacked bool, err error)
UniStreamHijacker func(ServerStreamType, quic.ConnectionTracingID, quic.ReceiveStream, error) (hijacked bool)

Logger *slog.Logger

initOnce sync.Once
hconn *connection
requestWriter *requestWriter
Expand All @@ -76,15 +73,14 @@ func (c *SingleDestinationRoundTripper) init() {
c.Connection,
c.EnableDatagrams,
PerspectiveClient,
c.Logger,
0,
c.Options,
)
// send the SETTINGs frame, using 0-RTT data, if possible
go func() {
if err := c.setupConn(c.hconn); err != nil {
if c.Logger != nil {
c.Logger.Debug("Setting up connection failed", "error", err)
if c.Debugf != nil {
c.Debugf("Setting up connection failed: %s", err.Error())
}
c.hconn.CloseWithError(quic.ApplicationErrorCode(ErrCodeInternalError), "")
}
Expand Down Expand Up @@ -113,8 +109,8 @@ func (c *SingleDestinationRoundTripper) handleBidirectionalStreams() {
for {
str, err := c.hconn.AcceptStream(context.Background())
if err != nil {
if c.Logger != nil {
c.Logger.Debug("accepting bidirectional stream failed", "error", err)
if c.Debugf != nil {
c.Debugf("accepting bidirectional stream failed: %s", err.Error())
}
return
}
Expand All @@ -131,8 +127,8 @@ func (c *SingleDestinationRoundTripper) handleBidirectionalStreams() {
return
}
if err != nil {
if c.Logger != nil {
c.Logger.Debug("error handling stream", "error", err)
if c.Debugf != nil {
c.Debugf("error handling stream: %s", err.Error())
}
}
c.hconn.CloseWithError(quic.ApplicationErrorCode(ErrCodeFrameUnexpected), "received HTTP/3 frame on bidirectional stream")
Expand Down Expand Up @@ -283,8 +279,8 @@ func (c *SingleDestinationRoundTripper) doRequest(req *http.Request, str *reques
go func() {
dumps := dump.GetDumpers(req.Context(), c.Dump)
if err := c.sendRequestBody(str, req.Body, dumps); err != nil {
if c.Logger != nil {
c.Logger.Debug("error writing request", "error", err)
if c.Debugf != nil {
c.Debugf("error writing request: %s", err.Error())
}
}
str.Close()
Expand Down
16 changes: 6 additions & 10 deletions internal/http3/conn.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import (
"context"
"fmt"
"io"
"log/slog"
"net"
"net/http"
"sync"
Expand Down Expand Up @@ -44,7 +43,6 @@ type connection struct {
ctx context.Context

perspective Perspective
logger *slog.Logger

enableDatagrams bool

Expand All @@ -65,7 +63,6 @@ func newConnection(
quicConn quic.Connection,
enableDatagrams bool,
perspective Perspective,
logger *slog.Logger,
idleTimeout time.Duration,
options *transport.Options,
) *connection {
Expand All @@ -74,7 +71,6 @@ func newConnection(
Connection: quicConn,
Options: options,
perspective: perspective,
logger: logger,
idleTimeout: idleTimeout,
enableDatagrams: enableDatagrams,
decoder: qpack.NewDecoder(func(hf qpack.HeaderField) {}),
Expand Down Expand Up @@ -183,8 +179,8 @@ func (c *connection) HandleUnidirectionalStreams(hijack func(ServerStreamType, q
for {
str, err := c.Connection.AcceptUniStream(context.Background())
if err != nil {
if c.logger != nil {
c.logger.Debug("accepting unidirectional stream failed", "error", err)
if c.Debugf != nil {
c.Debugf("accepting unidirectional stream failed: %s", err.Error())
}
return
}
Expand All @@ -196,8 +192,8 @@ func (c *connection) HandleUnidirectionalStreams(hijack func(ServerStreamType, q
if hijack != nil && hijack(ServerStreamType(streamType), id, str, err) {
return
}
if c.logger != nil {
c.logger.Debug("reading stream type on stream failed", "stream ID", str.StreamID(), "error", err)
if c.Debugf != nil {
c.Debugf("reading stream type on stream failed (id %v): %s", str.StreamID(), err.Error())
}
return
}
Expand Down Expand Up @@ -274,8 +270,8 @@ func (c *connection) HandleUnidirectionalStreams(hijack func(ServerStreamType, q
}
go func() {
if err := c.receiveDatagrams(); err != nil {
if c.logger != nil {
c.logger.Debug("receiving datagrams failed", "error", err)
if c.Debugf != nil {
c.Debugf("receiving datagrams failed: %s", err.Error())
}
}
}()
Expand Down
14 changes: 4 additions & 10 deletions internal/http3/roundtrip.go
Original file line number Diff line number Diff line change
Expand Up @@ -87,11 +87,6 @@ type RoundTripper struct {
// It is invalid to specify any settings defined by RFC 9114 (HTTP/3) and RFC 9297 (HTTP Datagrams).
AdditionalSettings map[uint64]uint64

// MaxResponseHeaderBytes specifies a limit on how many response bytes are
// allowed in the server's response header.
// Zero means to use a default limit.
MaxResponseHeaderBytes int64

initOnce sync.Once
initErr error

Expand Down Expand Up @@ -197,11 +192,10 @@ func (r *RoundTripper) init() error {
if r.newClient == nil {
r.newClient = func(conn quic.EarlyConnection) singleRoundTripper {
return &SingleDestinationRoundTripper{
Options: r.Options,
Connection: conn,
EnableDatagrams: r.EnableDatagrams,
AdditionalSettings: r.AdditionalSettings,
MaxResponseHeaderBytes: r.MaxResponseHeaderBytes,
Options: r.Options,
Connection: conn,
EnableDatagrams: r.EnableDatagrams,
AdditionalSettings: r.AdditionalSettings,
}
}
}
Expand Down

0 comments on commit 551b96d

Please sign in to comment.