From fbf82c7bd60637d28283607aeb00968467fc7c97 Mon Sep 17 00:00:00 2001 From: Akshay Shah Date: Fri, 28 Jan 2022 09:22:59 -0800 Subject: [PATCH 1/2] Rename ReceivedHeader -> {Request,Response}Header Especially on user-facing types, use the familar request/response terminology instead of sender/receiver. See #53. --- client_duplex_stream.go | 4 ++-- clientstream/stream.go | 8 ++++---- handlerstream/stream.go | 8 ++++---- 3 files changed, 10 insertions(+), 10 deletions(-) diff --git a/client_duplex_stream.go b/client_duplex_stream.go index 1f023167..e73bd883 100644 --- a/client_duplex_stream.go +++ b/client_duplex_stream.go @@ -40,7 +40,7 @@ var _ Receiver = (*clientReceiver)(nil) func (cr *clientReceiver) Receive(m any) error { return cr.stream.Receive(m) } func (cr *clientReceiver) Close() error { return cr.stream.CloseReceive() } func (cr *clientReceiver) Spec() Specification { return cr.stream.Spec() } -func (cr *clientReceiver) Header() http.Header { return cr.stream.ReceivedHeader() } +func (cr *clientReceiver) Header() http.Header { return cr.stream.ResponseHeader() } // clientStream represents a bidirectional exchange of protobuf messages // between the client and server. The request body is the stream from client to @@ -186,7 +186,7 @@ func (cs *clientStream) CloseReceive() error { return nil } -func (cs *clientStream) ReceivedHeader() http.Header { +func (cs *clientStream) ResponseHeader() http.Header { <-cs.responseReady return cs.response.Header } diff --git a/clientstream/stream.go b/clientstream/stream.go index e5d87213..eea444b7 100644 --- a/clientstream/stream.go +++ b/clientstream/stream.go @@ -68,9 +68,9 @@ func (s *Server[Res]) Receive() (*Res, error) { return &res, nil } -// ReceivedHeader returns the headers received from the server. It blocks until +// ResponseHeader returns the headers received from the server. It blocks until // the first call to Receive returns. -func (s *Server[Res]) ReceivedHeader() http.Header { +func (s *Server[Res]) ResponseHeader() http.Header { return s.receiver.Header() } @@ -122,8 +122,8 @@ func (b *Bidirectional[Req, Res]) CloseReceive() error { return b.receiver.Close() } -// ReceivedHeader returns the headers received from the server. It blocks until +// ResponseHeader returns the headers received from the server. It blocks until // the first call to Receive returns. -func (b *Bidirectional[Req, Res]) ReceivedHeader() http.Header { +func (b *Bidirectional[Req, Res]) ResponseHeader() http.Header { return b.receiver.Header() } diff --git a/handlerstream/stream.go b/handlerstream/stream.go index b11d09c7..ef9539e1 100644 --- a/handlerstream/stream.go +++ b/handlerstream/stream.go @@ -19,8 +19,8 @@ func NewClient[Req, Res any](s rerpc.Sender, r rerpc.Receiver) *Client[Req, Res] return &Client[Req, Res]{sender: s, receiver: r} } -// ReceivedHeader returns the headers received from the client. -func (c *Client[Req, Res]) ReceivedHeader() http.Header { +// RequestHeader returns the headers received from the client. +func (c *Client[Req, Res]) RequestHeader() http.Header { return c.receiver.Header() } @@ -80,8 +80,8 @@ func NewBidirectional[Req, Res any](s rerpc.Sender, r rerpc.Receiver) *Bidirecti return &Bidirectional[Req, Res]{sender: s, receiver: r} } -// ReceivedHeader returns the headers received from the client. -func (b *Bidirectional[Req, Res]) ReceivedHeader() http.Header { +// RequestHeader returns the headers received from the client. +func (b *Bidirectional[Req, Res]) RequestHeader() http.Header { return b.receiver.Header() } From 9fcfdb3f44dafce4bf6ac5c1f4f1b5a8cd34ad40 Mon Sep 17 00:00:00 2001 From: Akshay Shah Date: Fri, 28 Jan 2022 09:31:42 -0800 Subject: [PATCH 2/2] Remove MaxHeaderBytes --- client_example_test.go | 2 +- rerpc.go | 4 ---- server_example_test.go | 2 +- 3 files changed, 2 insertions(+), 6 deletions(-) diff --git a/client_example_test.go b/client_example_test.go index 6f239b69..f3d19975 100644 --- a/client_example_test.go +++ b/client_example_test.go @@ -32,7 +32,7 @@ func ExampleClient() { // idle connections per host. MaxIdleConnsPerHost: 16, IdleConnTimeout: 90 * time.Second, - MaxResponseHeaderBytes: rerpc.MaxHeaderBytes, + MaxResponseHeaderBytes: 8 * 1024, // 8 KiB, gRPC's recommended setting }, CheckRedirect: func(_ *http.Request, _ []*http.Request) error { // Don't follow any redirects. diff --git a/rerpc.go b/rerpc.go index 44f891a6..3d62892e 100644 --- a/rerpc.go +++ b/rerpc.go @@ -3,10 +3,6 @@ package rerpc // Version is the semantic version of the reRPC module. const Version = "0.0.1" -// MaxHeaderBytes is 8KiB, gRPC's recommended maximum header size. To enforce -// this limit, set MaxHeaderBytes on your http.Server. -const MaxHeaderBytes = 1024 * 8 - // StreamType describes whether the client, server, neither, or both is // streaming. type StreamType uint8 diff --git a/server_example_test.go b/server_example_test.go index ce824e61..443ba8b9 100644 --- a/server_example_test.go +++ b/server_example_test.go @@ -61,7 +61,7 @@ func Example() { Handler: mux, ReadTimeout: 2500 * time.Millisecond, WriteTimeout: 5 * time.Second, - MaxHeaderBytes: rerpc.MaxHeaderBytes, + MaxHeaderBytes: 8 * 1024, // 8KiB, gRPC's recommendation } // You could also use golang.org/x/net/http2/h2c to serve gRPC requests // without TLS.