Skip to content
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

Embed the Hijacker interface in intercepting writer #1093

Closed
wants to merge 4 commits into from

Conversation

wicknicks
Copy link

@wicknicks wicknicks commented May 25, 2021

This PR embeds the Hijacker interface in kit's interceptingWriter. Having an hijacker embedding allows applications to use websockets. looks here for discussion around this: golang/go#26937

Addresses issue #1092.

Signed-off-by: Arjun Satish <arjun@confluent.io>
@@ -226,6 +233,7 @@ type Headerer interface {

type interceptingWriter struct {
http.ResponseWriter
http.Hijacker
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This isn't safe — if this field is nil, h, ok := w.(http.Hijacker) will succeed, but calling h.Hijack() will panic, as h will be nil.

@peterbourgon
Copy link
Member

http.Hijacker is one of five common interfaces which http.ResponseWriters are upgraded-to using the interface upgrade pattern — why just solve for this one?

@wicknicks
Copy link
Author

hey, @peterbourgon thanks very much for the suggestions. yes, it makes sense to accommodate all five interfaces. such a switch case block was what I had in mind for that, but using httpsnoop to wrap the writer is a better approach. I'll update this PR shortly. thanks again!

Signed-off-by: Arjun Satish <arjun@confluent.io>
@wicknicks
Copy link
Author

@peterbourgon made the changes. let me know what you think. thanks in advance!

@wicknicks
Copy link
Author

btw, I'm not very fluent in golang. does the interceptingWriter now include a Hijack() method? it seems like it should not. and the only way to do so, is actually have an entire switch case block around constructing interceptingWriter with the component interfaces.

Signed-off-by: Arjun Satish <arjun@confluent.io>
@wicknicks
Copy link
Author

@peterbourgon any thoughts on this approach? thanks in advance!

@codyaray
Copy link

codyaray commented Jun 9, 2021

@peterbourgon what do you think? Can this be merged? 🙏

peterbourgon
peterbourgon previously approved these changes Jun 10, 2021
Copy link
Member

@peterbourgon peterbourgon left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

With that change, OK. Not super excited about the additional dependency, but 🤷

@@ -5,6 +5,8 @@ import (
"encoding/json"
"net/http"

"github.com/felixge/httpsnoop"

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: rm the blank line and re-goimports :)

Signed-off-by: Arjun Satish <arjun@confluent.io>
@wicknicks
Copy link
Author

@peterbourgon removed the extra newline. goimports didn't bring out any other changes.

@wicknicks
Copy link
Author

@peterbourgon do you think we can merge this now, and release a new tag? many thanks in advance!

@peterbourgon
Copy link
Member

This is a big change to a core package. I'll merge it now, so we can get some beta-testing time, so to speak.

@peterbourgon
Copy link
Member

Oof! What am I saying. Can you please add some tests for this? 😇

@peterbourgon
Copy link
Member

Happy to re-review with proper test coverage.

Reasno added a commit to Reasno/kit that referenced this pull request Jan 21, 2022
peterbourgon pushed a commit that referenced this pull request Jan 31, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants