Skip to content

net/http: make the http server con write buffer size configurable #68142

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

Closed
wants to merge 1 commit into from
Closed
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
12 changes: 11 additions & 1 deletion src/net/http/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -2010,7 +2010,13 @@ func (c *conn) serve(ctx context.Context) {

c.r = &connReader{conn: c}
c.bufr = newBufioReader(c.r)
c.bufw = newBufioWriterSize(checkConnErrorWriter{c}, 4<<10)

var writeBufferSize int = 4 << 10
if c.server.WriteBufferSize != 0 {
writeBufferSize = c.server.WriteBufferSize
}

c.bufw = newBufioWriterSize(checkConnErrorWriter{c}, writeBufferSize)

for {
w, err := c.readRequest(ctx)
Expand Down Expand Up @@ -2981,6 +2987,10 @@ type Server struct {
// value.
ConnContext func(ctx context.Context, c net.Conn) context.Context

// WriteBufferSize optionally specifies the buffer size used to write to a connection.
// If not set, a default value of 4 KB is used.
WriteBufferSize int

inShutdown atomic.Bool // true when server is in shutdown

disableKeepAlives atomic.Bool
Expand Down