Skip to content

reverseproxy: make stream copy buffer size configurable#7627

Open
steadytao wants to merge 1 commit intocaddyserver:masterfrom
steadytao:feat/reverseproxy-stream-buffer-size
Open

reverseproxy: make stream copy buffer size configurable#7627
steadytao wants to merge 1 commit intocaddyserver:masterfrom
steadytao:feat/reverseproxy-stream-buffer-size

Conversation

@steadytao
Copy link
Copy Markdown
Contributor

Implements #7624 by making the copy buffer size for upgraded bidirectional streams configurable.

Summary

This adds a new stream_buffer_size option to reverse_proxy.

It applies to upgraded streaming connections such as websockets where Caddy currently uses io.Copy in both directions. Since io.Copy allocates a 32 KiB buffer per copy operation, long-lived mostly-idle websocket connections can end up holding roughly 64 KiB of buffer memory per connection.

With this change, the buffer size for those streaming copies can be tuned explicitly.

Example:

reverse_proxy localhost:8000 {
    stream_buffer_size 4KB
}

Behavior

  • stream_buffer_size controls the buffer used for each direction of an upgraded stream
  • if unset or zero, the current default behavior remains unchanged (32 KiB)
  • this only affects upgraded bidirectional streams such as websockets
  • normal request/response buffering is unchanged

Tests

Added:

  • unit coverage for the streaming copier buffer sizing
  • Caddyfile adaptation coverage for stream_buffer_size

Implements + should close #7624

Assistance Disclosure

No AI was used.

@francislavoie francislavoie added the feature ⚙️ New feature or request label Apr 4, 2026
@francislavoie francislavoie added this to the v2.11.3 milestone Apr 4, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

feature ⚙️ New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Make websocket copy buffer size configurable

2 participants