Skip to content

Commit ae8c8df

Browse files
committed
cleanup
1 parent 0d3d6e1 commit ae8c8df

File tree

3 files changed

+6
-19
lines changed

3 files changed

+6
-19
lines changed

internal/transport/http2_client.go

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1654,13 +1654,6 @@ func (t *http2Client) reader(errCh chan<- error) {
16541654
}
16551655
}()
16561656

1657-
pool := t.bufferPool
1658-
if pool == nil {
1659-
// Note that this is only supposed to be nil in tests. Otherwise, stream
1660-
// is always initialized with a BufferPool.
1661-
pool = mem.DefaultBufferPool()
1662-
}
1663-
16641657
if err := t.readServerPreface(); err != nil {
16651658
errCh <- err
16661659
return

internal/transport/http2_server.go

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -169,7 +169,6 @@ func NewServerTransport(conn net.Conn, config *ServerConfig) (_ ServerTransport,
169169
if config.MaxHeaderListSize != nil {
170170
maxHeaderListSize = *config.MaxHeaderListSize
171171
}
172-
173172
framer := newFramer(conn, writeBufSize, readBufSize, config.SharedWriteBuffer, maxHeaderListSize, config.BufferPool)
174173
// Send initial settings as connection preface to client.
175174
isettings := []http2.Setting{{
@@ -669,16 +668,10 @@ func (t *http2Server) HandleStreams(ctx context.Context, handle func(*ServerStre
669668
close(t.readerDone)
670669
<-t.loopyWriterDone
671670
}()
672-
pool := t.bufferPool
673-
if pool == nil {
674-
// Note that this is only supposed to be nil in tests. Otherwise, stream
675-
// is always initialized with a BufferPool.
676-
pool = mem.DefaultBufferPool()
677-
}
678671
for {
679672
t.controlBuf.throttle()
680-
atomic.StoreInt64(&t.lastRead, time.Now().UnixNano())
681673
frame, err := t.framer.readFrame()
674+
atomic.StoreInt64(&t.lastRead, time.Now().UnixNano())
682675
if err != nil {
683676
if se, ok := err.(http2.StreamError); ok {
684677
if t.logger.V(logLevel) {

internal/transport/http_util.go

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -443,21 +443,22 @@ func newFramer(conn io.ReadWriter, writeBufferSize, readBufferSize int, sharedWr
443443
return f
444444
}
445445

446+
// readFrame reads a single frame. The returned Frame is only valid
447+
// until the next call to readFrame.
446448
func (f *framer) readFrame() (any, error) {
447449
fh, err := f.fr.ReadFrameHeader()
448450
if err != nil {
449451
return nil, err
450452
}
453+
// Read the data frame directly from the underlying io.Reader to avoid
454+
// copies.
451455
if fh.Type == http2.FrameData {
452456
err = f.readDataFrame(fh, f.pool, &f.dataFrame)
453457
return &f.dataFrame, err
454-
} else {
455-
return f.fr.ReadFrameForHeader(fh)
456458
}
459+
return f.fr.ReadFrameForHeader(fh)
457460
}
458461

459-
// readDataFrame reads and parses a data frame from the underlying io.Reader.
460-
// Frames aren't safe to read from after a subsequent call to ReadFrame.
461462
func (f *framer) readDataFrame(fh http2.FrameHeader, pool mem.BufferPool, df *parsedDataFrame) (err error) {
462463
if fh.StreamID == 0 {
463464
// DATA frames MUST be associated with a stream. If a

0 commit comments

Comments
 (0)