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

Fixed case when no hijacker is added but no-response is true #772

Merged
merged 1 commit into from
Apr 7, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion server.go
Original file line number Diff line number Diff line change
Expand Up @@ -2087,7 +2087,7 @@ func (s *Server) serveConn(c net.Conn) (err error) {

hijackHandler = ctx.hijackHandler
ctx.hijackHandler = nil
hijackNoResponse = ctx.hijackNoResponse
hijackNoResponse = ctx.hijackNoResponse && hijackHandler != nil
ctx.hijackNoResponse = false

ctx.userValues.Reset()
Expand Down
37 changes: 37 additions & 0 deletions server_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2148,6 +2148,43 @@ func TestRequestCtxHijackNoResponse(t *testing.T) {
}
}

func TestRequestCtxNoHijackNoResponse(t *testing.T) {
t.Parallel()

s := &Server{
Handler: func(ctx *RequestCtx) {
io.WriteString(ctx, "test")
ctx.HijackSetNoResponse(true)
},
}

rw := &readWriter{}
rw.r.WriteString("GET /foo HTTP/1.1\r\nHost: google.com\r\nContent-Length: 0\r\n\r\n")

ch := make(chan error)
go func() {
ch <- s.ServeConn(rw)
}()

select {
case err := <-ch:
if err != nil {
t.Fatalf("Unexpected error from serveConn: %s", err)
}
case <-time.After(100 * time.Millisecond):
t.Fatal("timeout")
}

bf := bufio.NewReader(
strings.NewReader(rw.w.String()),
)
resp := AcquireResponse()
resp.Read(bf)
if got := string(resp.Body()); got != "test" {
t.Errorf(`expected "test", got %q`, got)
}
}

func TestRequestCtxInit(t *testing.T) {
var ctx RequestCtx
var logger testLogger
Expand Down