diff --git a/client.go b/client.go index d44e6e4a..31cf7dbc 100644 --- a/client.go +++ b/client.go @@ -334,6 +334,7 @@ func newClientConfig(rawURL string, options []ClientOption) (*clientConfig, *Err Procedure: protoPath, CompressionPools: make(map[string]*compressionPool), BufferPool: newBufferPool(), + ReadMaxBytes: defaultReadMaxBytes, } withProtoBinaryCodec().applyToClient(&config) withGzip().applyToClient(&config) diff --git a/connect_ext_test.go b/connect_ext_test.go index fc6bb581..1e1bab5a 100644 --- a/connect_ext_test.go +++ b/connect_ext_test.go @@ -430,7 +430,7 @@ func TestServer(t *testing.T) { if testing.Short() { t.Skipf("skipping %s test in short mode", t.Name()) } - hellos := strings.Repeat("hello", 1024*1024) // ~5mb + hellos := strings.Repeat("hello", 512*1024) // ~2.5mb request := connect.NewRequest(&pingv1.PingRequest{Text: hellos}) for _, el := range expectedHeaderValues { request.Header().Add(clientHeader, el) @@ -1686,7 +1686,7 @@ func TestClientWithReadMaxBytes(t *testing.T) { } else { compressionOption = connect.WithCompressMinBytes(math.MaxInt) } - mux.Handle(pingv1connect.NewPingServiceHandler(pingServer{}, compressionOption)) + mux.Handle(pingv1connect.NewPingServiceHandler(pingServer{}, compressionOption, connect.WithReadMaxBytes(0))) server := memhttptest.NewServer(t, mux) return server } @@ -1822,7 +1822,7 @@ func TestHandlerWithSendMaxBytes(t *testing.T) { newHTTP2Server := func(t *testing.T, compressed bool, sendMaxBytes int) *memhttp.Server { t.Helper() mux := http.NewServeMux() - options := []connect.HandlerOption{connect.WithSendMaxBytes(sendMaxBytes)} + options := []connect.HandlerOption{connect.WithSendMaxBytes(sendMaxBytes), connect.WithReadMaxBytes(0)} if compressed { options = append(options, connect.WithCompressMinBytes(1)) } else { diff --git a/handler.go b/handler.go index 5355329d..e358ad61 100644 --- a/handler.go +++ b/handler.go @@ -361,6 +361,7 @@ func newHandlerConfig(procedure string, streamType StreamType, options []Handler CompressionPools: make(map[string]*compressionPool), Codecs: make(map[string]Codec), BufferPool: newBufferPool(), + ReadMaxBytes: defaultReadMaxBytes, StreamType: streamType, } withProtoBinaryCodec().applyToHandler(&config) diff --git a/option.go b/option.go index 7945c9b2..36882dd4 100644 --- a/option.go +++ b/option.go @@ -247,8 +247,8 @@ func WithCompressMinBytes(minBytes int) Option { // size of a message that the server can respond with. Limits apply to each Protobuf // message, not to the stream as a whole. // -// Setting WithReadMaxBytes to zero allows any message size. Both clients and -// handlers default to allowing any request size. +// Both clients and handlers default to a limit of 4 MiB. Setting +// WithReadMaxBytes to zero allows any message size. // // Handlers may also use [http.MaxBytesHandler] to limit the total size of the // HTTP request stream (rather than the per-message size). Connect handles diff --git a/protocol.go b/protocol.go index 4e98b2b1..246676be 100644 --- a/protocol.go +++ b/protocol.go @@ -44,6 +44,8 @@ const ( headerDate = "Date" discardLimit = 1024 * 1024 * 4 // 4MiB + + defaultReadMaxBytes = 1024 * 1024 * 4 // 4MiB ) var errNoTimeout = errors.New("no timeout")