Skip to content

Commit

Permalink
test: replace net/http internals with bufio
Browse files Browse the repository at this point in the history
  • Loading branch information
cristaloleg committed Apr 9, 2023
1 parent 4be3cf8 commit 8e2d520
Showing 1 changed file with 3 additions and 17 deletions.
20 changes: 3 additions & 17 deletions server_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,9 @@ import (
"strings"
"sync/atomic"
"testing"
_ "unsafe" // for go:linkname

"github.com/gobwas/httphead"
"github.com/gobwas/pool/pbufio"
)

// TODO(gobwas): upgradeGenericCase with methods like configureUpgrader,
Expand Down Expand Up @@ -700,18 +700,6 @@ func sortHeaders(bts []byte) []byte {
return bytes.Join(lines, []byte("\r\n"))
}

//go:linkname httpPutBufioReader net/http.putBufioReader
func httpPutBufioReader(*bufio.Reader)

//go:linkname httpPutBufioWriter net/http.putBufioWriter
func httpPutBufioWriter(*bufio.Writer)

//go:linkname httpNewBufioReader net/http.newBufioReader
func httpNewBufioReader(io.Reader) *bufio.Reader

//go:linkname httpNewBufioWriterSize net/http.newBufioWriterSize
func httpNewBufioWriterSize(io.Writer, int) *bufio.Writer

type recorder struct {
*httptest.ResponseRecorder
hijacked bool
Expand Down Expand Up @@ -764,10 +752,8 @@ func (r *recorder) Hijack() (conn net.Conn, brw *bufio.ReadWriter, err error) {
}
}

// Use httpNewBufio* linked functions here to make
// benchmark more closer to real life usage.
br := httpNewBufioReader(conn)
bw := httpNewBufioWriterSize(conn, 4<<10)
br := pbufio.GetReader(conn, DefaultClientReadBufferSize)
bw := pbufio.GetWriter(conn, DefaultClientWriteBufferSize)

brw = bufio.NewReadWriter(br, bw)

Expand Down

0 comments on commit 8e2d520

Please sign in to comment.