mirror of
https://github.com/refraction-networking/uquic.git
synced 2025-04-07 06:07:36 +03:00
http3: add Date response header if not set (#3952)
* automatically add date header if not already set * improve comment for Date header --------- Co-authored-by: Marten Seemann <martenseemann@gmail.com>
This commit is contained in:
parent
f97c9bf88c
commit
2c4371b6a9
2 changed files with 12 additions and 3 deletions
|
@ -55,6 +55,12 @@ func (w *responseWriter) WriteHeader(status int) {
|
||||||
|
|
||||||
if status < 100 || status >= 200 {
|
if status < 100 || status >= 200 {
|
||||||
w.headerWritten = true
|
w.headerWritten = true
|
||||||
|
// Add Date header.
|
||||||
|
// This is what the standard library does.
|
||||||
|
// Can be disabled by setting the Date header to nil.
|
||||||
|
if _, ok := w.header["Date"]; !ok {
|
||||||
|
w.header.Set("Date", time.Now().UTC().Format(http.TimeFormat))
|
||||||
|
}
|
||||||
}
|
}
|
||||||
w.status = status
|
w.status = status
|
||||||
|
|
||||||
|
|
|
@ -65,8 +65,9 @@ var _ = Describe("Response Writer", func() {
|
||||||
It("writes status", func() {
|
It("writes status", func() {
|
||||||
rw.WriteHeader(http.StatusTeapot)
|
rw.WriteHeader(http.StatusTeapot)
|
||||||
fields := decodeHeader(strBuf)
|
fields := decodeHeader(strBuf)
|
||||||
Expect(fields).To(HaveLen(1))
|
Expect(fields).To(HaveLen(2))
|
||||||
Expect(fields).To(HaveKeyWithValue(":status", []string{"418"}))
|
Expect(fields).To(HaveKeyWithValue(":status", []string{"418"}))
|
||||||
|
Expect(fields).To(HaveKey("date"))
|
||||||
})
|
})
|
||||||
|
|
||||||
It("writes headers", func() {
|
It("writes headers", func() {
|
||||||
|
@ -116,8 +117,9 @@ var _ = Describe("Response Writer", func() {
|
||||||
rw.WriteHeader(http.StatusOK)
|
rw.WriteHeader(http.StatusOK)
|
||||||
rw.WriteHeader(http.StatusInternalServerError)
|
rw.WriteHeader(http.StatusInternalServerError)
|
||||||
fields := decodeHeader(strBuf)
|
fields := decodeHeader(strBuf)
|
||||||
Expect(fields).To(HaveLen(1))
|
Expect(fields).To(HaveLen(2))
|
||||||
Expect(fields).To(HaveKeyWithValue(":status", []string{"200"}))
|
Expect(fields).To(HaveKeyWithValue(":status", []string{"200"}))
|
||||||
|
Expect(fields).To(HaveKey("date"))
|
||||||
})
|
})
|
||||||
|
|
||||||
It("allows calling WriteHeader() several times when using the 103 status code", func() {
|
It("allows calling WriteHeader() several times when using the 103 status code", func() {
|
||||||
|
@ -137,8 +139,9 @@ var _ = Describe("Response Writer", func() {
|
||||||
|
|
||||||
// According to the spec, headers sent in the informational response must also be included in the final response
|
// According to the spec, headers sent in the informational response must also be included in the final response
|
||||||
fields = decodeHeader(strBuf)
|
fields = decodeHeader(strBuf)
|
||||||
Expect(fields).To(HaveLen(2))
|
Expect(fields).To(HaveLen(3))
|
||||||
Expect(fields).To(HaveKeyWithValue(":status", []string{"200"}))
|
Expect(fields).To(HaveKeyWithValue(":status", []string{"200"}))
|
||||||
|
Expect(fields).To(HaveKey("date"))
|
||||||
Expect(fields).To(HaveKeyWithValue("link", []string{"</style.css>; rel=preload; as=style", "</script.js>; rel=preload; as=script"}))
|
Expect(fields).To(HaveKeyWithValue("link", []string{"</style.css>; rel=preload; as=style", "</script.js>; rel=preload; as=script"}))
|
||||||
|
|
||||||
Expect(getData(strBuf)).To(Equal([]byte("foobar")))
|
Expect(getData(strBuf)).To(Equal([]byte("foobar")))
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue