-
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
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
allow sending 1xx responses #3047
allow sending 1xx responses #3047
Conversation
Codecov Report
@@ Coverage Diff @@
## master #3047 +/- ##
==========================================
- Coverage 86.17% 86.05% -0.12%
==========================================
Files 132 133 +1
Lines 9352 9441 +89
==========================================
+ Hits 8059 8124 +65
- Misses 936 955 +19
- Partials 357 362 +5
Continue to review full report at Codecov.
|
Thank you for the PR! |
Can you please rebase this PR? I fixed the CI configuration, so the tests should pass now. |
@marten-seemann this logic can be theoretically applied to all 1xx status codes. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The headers are written to a buffered stream. Do we need to flush it for 1xx status codes?
Currently, it's not possible to send informational responses such as 103 Early Hints or 102 Processing. This patch allows calling WriteHeader() multiple times in order to send informational responses before the final one. It follows the patch for HTTP/1 (golang/go#42597) and HTTP/2 (golang/net#96). In conformance with RFC 8297, if the status code is 103 the current content of the header map is also sent. Its content is not removed after the call to WriteHeader() because the headers must also be included in the final response. The Chrome and Fastly teams are starting a large-scale experiment to measure the real-life impact of the 103 status code. Using Early Hints is proposed as a (partial) alternative to Server Push, which are going to be removed from Chrome: https://groups.google.com/a/chromium.org/g/blink-dev/c/K3rYLvmQUBY/m/21anpFhxAQAJ Being able to send this status code from servers implemented using Go would help to see if implementing it in browsers is worth it.
cb3a992
to
11220d7
Compare
Yes, headers must be sent with the 103 response (it's what allow the client to preload needed resources early), and, by the spec, again in the final response. (rebased btw) |
We're writing headers to the |
@dunglas Any update on this? |
@marten-seemann Sorry for the late reply, I was on vacation. I tried to add a call to Also, shouldn't |
That looks like an artifact of the test setup. Please apply the following change: --- a/http3/response_writer_test.go
+++ b/http3/response_writer_test.go
@@ -24,7 +24,7 @@ var _ = Describe("Response Writer", func() {
BeforeEach(func() {
strBuf = &bytes.Buffer{}
str := mockquic.NewMockStream(mockCtrl)
- str.EXPECT().Write(gomock.Any()).Do(strBuf.Write).AnyTimes()
+ str.EXPECT().Write(gomock.Any()).DoAndReturn(strBuf.Write).AnyTimes()
rw = newResponseWriter(str, utils.DefaultLogger)
})
I don't know. The reason to not do is that if you're just writing a response, you'd want the HEADERS frame to go in the same QUIC packet as the DATA frames. How do resource hints work? |
This does the trick, thanks!
Actually the 103 status code is just an optimization for resources and preload hints, which are already supported by all modern browsers. They are special Link HTTP headers allowing to hint the browser to do some network related actions as early as possible (resolving a domain name, doing a TLS handshake, downloading a resource...). |
Thank you for your explanation, that makes sense. Would you mind sending us another PR to update the documentation? |
Currently, it's not possible to send informational responses such as 103 Early Hints or 102 Processing.
This patch allows calling WriteHeader() multiple times in order to send informational responses before the final one.
It follows the patch for HTTP/1 (golang/go#42597) and HTTP/2 (golang/net#96).
In conformance with RFC 8297, if the status code is 103 the current content of the header map is also sent. Its content is not removed after the call to WriteHeader() because the headers must also be included in the final response.
The Chrome and Fastly teams are starting a large-scale experiment to measure the real-life impact of the 103 status code.
Using Early Hints is proposed as a (partial) alternative to Server Push, which are going to be removed from Chrome: https://groups.google.com/a/chromium.org/g/blink-dev/c/K3rYLvmQUBY/m/21anpFhxAQAJ
Being able to send this status code from servers implemented using Go would help to see if implementing it in browsers is worth it.