-
-
Notifications
You must be signed in to change notification settings - Fork 104
feat: send 103 Early Hints responses #95
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
Conversation
There is a todo comment about early hints on line 251, can it be removed now or more changes needed? |
c29b18c
to
5e037f7
Compare
Todo removed, thanks @andrerom. |
@@ -227,6 +227,7 @@ func (v *Vulcain) Apply(req *http.Request, rw http.ResponseWriter, responseBody | |||
} | |||
if addPreloadToVary { | |||
responseHeaders.Add("Vary", "Preload") | |||
rw.WriteHeader(http.StatusEarlyHints) |
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.
I don't think that it's the good place to send the 103 response (hence the test failure).
This should be done here:
Line 256 in f2d77e9
v.addPreloadHeader(newHeaders, url) |
and here:
Line 288 in f2d77e9
v.addPreloadHeader(newHeaders, url) |
Maybe should we refactor the code to prevent sending many 103 responses and send it only when all Preload headers have been computed?
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.
Also, I think that Server Push should now be opt-in (through a config option). By default, we should only use 103 responses as they are the new standard. This can be done in another PR of course.
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.
Actually I had to gather preload links added by push()
and manually add them to the ResponseWriter header map as they were not for some reason. With this approach, only one 103 response is sent with all Links included.
The code feels a bit hackish but it works as expected so unless you see door for improvement, this is ready to go on my side.
a1c53af
to
4d78bc0
Compare
vulcain.go
Outdated
} | ||
rw.WriteHeader(http.StatusEarlyHints) | ||
// remove extra Link from final response headers | ||
rw.Header().Del("Link") |
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.
Why?
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.
Without this, the final response ends up with an extra - duplicated preload link. If you want to try it out (would be nice): checkout my PR, comment that line and run go test -v -timeout 30s -run PreloadHeader
ac8b0ca
to
90bbeb3
Compare
Work ongoing in https://github.com/dunglas/vulcain/compare/main...chalasr:vulcain:firstclass-103?expand=1 |
Hi guys do you think we can move forward with the @chalasr PR, we need it to use correctly VULCAIN :( |
vulcain.go
Outdated
} | ||
rw.WriteHeader(http.StatusEarlyHints) | ||
// remove extra Link from final response headers | ||
rw.Header().Del("Link") |
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.
Why is this needed? I'm not sure to well understand what's going on here.
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.
Without this, the final response ends up with an extra - duplicated preload link. If you want to try it out (would be nice): checkout my PR, comment that line and run go test -v -timeout 30s -run PreloadHeader
Btw, should the final response actually have links if we already sent them in a 103?
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.
Yes, it even must have them, or downloaded data will be discarded.
Friendly ping :) |
90bbeb3
to
408d2dc
Compare
408d2dc
to
8007a60
Compare
I pushed a commit simplifying bit the code. I tested locally with Caddy, and it works as expected, the test failure is because the legacy proxy doesn't seem to support 103 properly and is still used by the test suite. |
2a810b0
to
07bb98d
Compare
07bb98d
to
32c5aa1
Compare
Now that Go 1.20 is released, it should be possible (I hope), to add proper support for 103 Early Hints to the legacy server that we use in our tests suite using a director function: https://pkg.go.dev/net/http/httputil#ReverseProxy.Director We'll have to keep supporting Go 1.19 until caddyserver/caddy#5288 is fixed. Another option would be to add a test for this feature in the Caddy module now that caddyserver/caddy#5187 is merged (we should be able to re-enable the tests for the Caddy module of Mercure by the way, but that's not related to this project 😅). Even if we follow this path, I would like that we add an example using a director function, at least because it will be displayed in the docs and we want to keep good examples of how to use Vulcain as a library without Caddy. WDYT? |
Works for me, I can be back on this PR in March. Sorry for the late reply |
Caddy 2.7 is out. We can now drop support for Go 1.19! |
32c5aa1
to
4c4d5d4
Compare
4c4d5d4
to
ccc3996
Compare
Thanks @chalasr. I fixed a tricky issue and some flaky tests. It's entirely green now 🎉 |
Thank you! |
This makes Vulcain sends 103 Early Hints responses when server-push isn't supported (with preload links).
The patch might be very naive but here we are, first contrib in Go. Please tell me if there is something else to be done.