Commit a0ab6cd6 authored by Brad Fitzpatrick's avatar Brad Fitzpatrick

net/http: add test that panic in a handler signals an error to the client

Change-Id: Iba40edc9ddad62534b06c5af20bbc3dd3dc14d0a
Reviewed-on: https://go-review.googlesource.com/21881Reviewed-by: default avatarAndrew Gerrand <adg@golang.org>
Run-TryBot: Brad Fitzpatrick <bradfitz@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
parent 982274c9
...@@ -1123,6 +1123,34 @@ func testBogusStatusWorks(t *testing.T, h2 bool) { ...@@ -1123,6 +1123,34 @@ func testBogusStatusWorks(t *testing.T, h2 bool) {
} }
} }
func TestInterruptWithPanic_h1(t *testing.T) { testInterruptWithPanic(t, h1Mode) }
func TestInterruptWithPanic_h2(t *testing.T) { testInterruptWithPanic(t, h2Mode) }
func testInterruptWithPanic(t *testing.T, h2 bool) {
log.SetOutput(ioutil.Discard) // is noisy otherwise
defer log.SetOutput(os.Stderr)
const msg = "hello"
defer afterTest(t)
cst := newClientServerTest(t, h2, HandlerFunc(func(w ResponseWriter, r *Request) {
io.WriteString(w, msg)
w.(Flusher).Flush()
panic("no more")
}))
defer cst.close()
res, err := cst.c.Get(cst.ts.URL)
if err != nil {
t.Fatal(err)
}
defer res.Body.Close()
slurp, err := ioutil.ReadAll(res.Body)
if string(slurp) != msg {
t.Errorf("client read %q; want %q", slurp, msg)
}
if err == nil {
t.Errorf("client read all successfully; want some error")
}
}
type noteCloseConn struct { type noteCloseConn struct {
net.Conn net.Conn
closeFunc func() closeFunc func()
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment