File tree Expand file tree Collapse file tree 3 files changed +12
-10
lines changed Expand file tree Collapse file tree 3 files changed +12
-10
lines changed Original file line number Diff line number Diff line change @@ -30,6 +30,7 @@ import (
3030 "io"
3131 "net/http"
3232 "net/url"
33+ "time"
3334)
3435
3536// Version is the semantic version of the connect module.
@@ -319,8 +320,8 @@ type Spec struct {
319320 Procedure string // for example, "/acme.foo.v1.FooService/Bar"
320321 IsClient bool // otherwise we're in a handler
321322 IdempotencyLevel IdempotencyLevel
322- ReadTimeout int
323- WriteTimeout int
323+ ReadTimeout time. Duration
324+ WriteTimeout time. Duration
324325}
325326
326327// Peer describes the other party to an RPC.
Original file line number Diff line number Diff line change @@ -258,8 +258,8 @@ func NewBidiStreamHandler[Req, Res any](
258258func (h * Handler ) ServeHTTP (responseWriter http.ResponseWriter , request * http.Request ) {
259259 if h .spec .ReadTimeout != 0 {
260260 rc := http .NewResponseController (responseWriter )
261- rc .SetReadDeadline (time .Now ().Add (time . Duration ( h .spec .ReadTimeout ) * time . Nanosecond ))
262- rc .SetWriteDeadline (time .Now ().Add (time . Duration ( h .spec .ReadTimeout ) * time . Nanosecond ))
261+ rc .SetReadDeadline (time .Now ().Add (h .spec .ReadTimeout ))
262+ rc .SetWriteDeadline (time .Now ().Add (h .spec .ReadTimeout ))
263263 }
264264
265265 // We don't need to defer functions to close the request body or read to
@@ -357,8 +357,8 @@ type handlerConfig struct {
357357 ReadMaxBytes int
358358 SendMaxBytes int
359359 StreamType StreamType
360- ReadTimeout int
361- WriteTimeout int
360+ ReadTimeout time. Duration
361+ WriteTimeout time. Duration
362362}
363363
364364func newHandlerConfig (procedure string , streamType StreamType , options []HandlerOption ) * handlerConfig {
Original file line number Diff line number Diff line change @@ -19,6 +19,7 @@ import (
1919 "context"
2020 "io"
2121 "net/http"
22+ "time"
2223)
2324
2425// A ClientOption configures a [Client].
@@ -351,11 +352,11 @@ func WithInterceptors(interceptors ...Interceptor) Option {
351352 return & interceptorsOption {interceptors }
352353}
353354
354- func WithReadTimeout (value int ) HandlerOption {
355+ func WithReadTimeout (value time. Duration ) HandlerOption {
355356 return & readTimeoutOption {value : value }
356357}
357358
358- func WithWriteTimeout (value int ) HandlerOption {
359+ func WithWriteTimeout (value time. Duration ) HandlerOption {
359360 return & writeTimeoutOption {value : value }
360361}
361362
@@ -654,13 +655,13 @@ func (o *conditionalHandlerOptions) applyToHandler(config *handlerConfig) {
654655 }
655656}
656657
657- type readTimeoutOption struct { value int }
658+ type readTimeoutOption struct { value time. Duration }
658659
659660func (o * readTimeoutOption ) applyToHandler (config * handlerConfig ) {
660661 config .ReadTimeout = o .value
661662}
662663
663- type writeTimeoutOption struct { value int }
664+ type writeTimeoutOption struct { value time. Duration }
664665
665666func (o * writeTimeoutOption ) applyToHandler (config * handlerConfig ) {
666667 config .WriteTimeout = o .value
You can’t perform that action at this time.
0 commit comments