forked from quic-go/quic-go
http3: panic in ResponseWriter.WriteHeader for invalid status codes (#3984)
* response writer: panic for invalid status code * add tests * readd imports * readd imports * fix imports
This commit is contained in:
@@ -3,6 +3,7 @@ package http3
|
|||||||
import (
|
import (
|
||||||
"bufio"
|
"bufio"
|
||||||
"bytes"
|
"bytes"
|
||||||
|
"fmt"
|
||||||
"net/http"
|
"net/http"
|
||||||
"strconv"
|
"strconv"
|
||||||
"strings"
|
"strings"
|
||||||
@@ -55,7 +56,12 @@ func (w *responseWriter) WriteHeader(status int) {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
if status < 100 || status >= 200 {
|
// http status must be 3 digits
|
||||||
|
if status < 100 || status > 999 {
|
||||||
|
panic(fmt.Sprintf("invalid WriteHeader code %v", status))
|
||||||
|
}
|
||||||
|
|
||||||
|
if status >= 200 {
|
||||||
w.headerWritten = true
|
w.headerWritten = true
|
||||||
// Add Date header.
|
// Add Date header.
|
||||||
// This is what the standard library does.
|
// This is what the standard library does.
|
||||||
|
|||||||
@@ -178,4 +178,9 @@ var _ = Describe("Response Writer", func() {
|
|||||||
Expect(n).To(Equal(0))
|
Expect(n).To(Equal(0))
|
||||||
Expect(err).To(Equal(http.ErrContentLength))
|
Expect(err).To(Equal(http.ErrContentLength))
|
||||||
})
|
})
|
||||||
|
|
||||||
|
It(`panics when writing invalid status`, func() {
|
||||||
|
Expect(func() { rw.WriteHeader(99) }).To(Panic())
|
||||||
|
Expect(func() { rw.WriteHeader(1000) }).To(Panic())
|
||||||
|
})
|
||||||
})
|
})
|
||||||
|
|||||||
Reference in New Issue
Block a user