-
-
Notifications
You must be signed in to change notification settings - Fork 126
http2: mimic stdlib http2 when connContext returns nil #164
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
Merged
Merged
Changes from 1 commit
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
4f493d7
http2: mimic stdlib http2 when connContext returns nil
pires db675fb
http2: drop redundant context.Context allocation
pires 8e609a8
http2,tests: drop client GET to example server
pires 0021992
http2,tests: reduce duplicated server setup logic
pires 011ddda
http2,tests: undo changes related to ExampleServer
pires File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,63 @@ | ||
| package http2 | ||
|
|
||
| import ( | ||
| "context" | ||
| "net" | ||
| "net/http" | ||
| "testing" | ||
| "time" | ||
|
|
||
| "github.com/pires/go-proxyproto" | ||
| ) | ||
|
|
||
| // TestServeConn_ConnContextReturnsNil lives in package http2 (not http2_test) so | ||
| // it can call the unexported serveConn method directly and recover the panic in | ||
| // the same goroutine, which is not possible through the public Serve API because | ||
| // Serve spawns a new goroutine per connection. | ||
| func TestServeConn_ConnContextReturnsNil(t *testing.T) { | ||
| srv := NewServer(&http.Server{ | ||
| ReadHeaderTimeout: 5 * time.Second, | ||
| Handler: http.HandlerFunc(func(_ http.ResponseWriter, _ *http.Request) {}), | ||
| ConnContext: func(_ context.Context, _ net.Conn) context.Context { | ||
| return nil | ||
| }, | ||
| }, nil) | ||
|
|
||
| // Create a pipe and write a PROXY header with h2 ALPN to trigger the H2 path. | ||
| clientConn, serverConn := net.Pipe() | ||
| defer func() { _ = clientConn.Close() }() | ||
| defer func() { _ = serverConn.Close() }() | ||
|
|
||
| header := proxyproto.Header{ | ||
| Version: 2, | ||
| Command: proxyproto.LOCAL, | ||
| TransportProtocol: proxyproto.UNSPEC, | ||
| } | ||
| if err := header.SetTLVs([]proxyproto.TLV{{ | ||
| Type: proxyproto.PP2_TYPE_ALPN, | ||
| Value: []byte("h2"), | ||
| }}); err != nil { | ||
| t.Fatalf("failed to set TLVs: %v", err) | ||
| } | ||
|
|
||
| // Write the header in a goroutine because net.Pipe is synchronous. | ||
| go func() { | ||
| _, _ = header.WriteTo(clientConn) | ||
| _ = clientConn.Close() | ||
| }() | ||
|
|
||
| pConn := proxyproto.NewConn(serverConn) | ||
|
|
||
| defer func() { | ||
| r := recover() | ||
| if r == nil { | ||
| t.Fatal("expected panic from ConnContext returning nil") | ||
| } | ||
| msg, ok := r.(string) | ||
| if !ok || msg != "ConnContext returned nil" { | ||
| t.Fatalf("expected panic message 'ConnContext returned nil', got: %v", r) | ||
| } | ||
| }() | ||
|
|
||
| _ = srv.serveConn(context.Background(), pConn) | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.