-
-
Notifications
You must be signed in to change notification settings - Fork 2.4k
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
HTTP server NoOpRequestDecoder #659
Conversation
transport/http/server.go
Outdated
@@ -136,6 +136,12 @@ type ErrorEncoder func(ctx context.Context, err error, w http.ResponseWriter) | |||
// provided in the context under keys with the ContextKeyResponse prefix. | |||
type ServerFinalizerFunc func(ctx context.Context, code int, r *http.Request) | |||
|
|||
// NoOpRequestDecoder is a DecodeRequestFunc that can be used for requests that do not | |||
// need to be decoded, and simply returns nil, nil. | |||
func NoOpRequestDecoder(ctx context.Context, r *http.Request) (interface{}, error) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I know it might look a bit strange, but I think in Go we usually spell this NopRequestDecoder
. See for precedent:
https://golang.org/pkg/io/ioutil/#NopCloser
https://godoc.org/github.com/go-kit/kit/log#NewNopLogger
https://godoc.org/golang.org/x/text/transform#NopResetter
transport/http/server_test.go
Outdated
case <-done: | ||
case <-time.After(time.Second): | ||
t.Fatal("timeout waiting for finalizer") | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this test is doing too much. It seems to me that it would be perfectly valid to test this without spinning up an http server and extra goroutines. Consider calling handler.ServeHTTP
directly. You can use httptest.NewRequest
and httptest.NewRecorder
to construct appropriate arguments for ServeHTTP
and do it all sequentially with no need for worrying about timeouts, done channels or stopping a server.
Adds NoOpRequestDecoder for HTTP request that do not need to be decoded. Fixes go-kit#657
@ChrisHines Thanks for the review. I made the requested changes. Cheers. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
Fun! Thanks! I guess we ought to do a release soon... |
Adds NoOpRequestDecoder for HTTP request that do not need to be decoded.
Fixes #657