-
Notifications
You must be signed in to change notification settings - Fork 851
Do not add content-length for status 204 cache #9877
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
Do not add content-length for status 204 cache #9877
Conversation
|
[approve ci rocky] |
proxy/http/HttpTransact.cc
Outdated
| s->hdr_info.trust_response_cl = true; | ||
| } else { | ||
| header->set_content_length(cl); | ||
| if (!(s->source == SOURCE_CACHE && header->status_get() == HTTP_STATUS_NO_CONTENT)) { |
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.
Can you tell me why s->source == SOURCE_CACHE is needed?
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 think in general the reverse proxy is supposed to send the reponse from the origin server as is, so I thought it would be better to limit the guard not to add content-length to the case for sending from the status 204 cache.
However, as I'm writing this, I noticed that it would also delete content-length when sending the status 204 cache after receiving a status 204 response having content-length from an origin server. So the code above is modifying the response from an origin server after all.
So, should we avoid to add content-length for both the case when it sends from cache or when it proxies the response from an origin server? If so, is if (header->status_get() != HTTP_STATUS_NO_CONTENT) the correct?
I ran my tests for if (header->status_get() != HTTP_STATUS_NO_CONTENT) and confirmed they pass.
hnakamur/atstest-go@aaeccc2
hnakamur@2faa3f9
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.
Having different behavior for the two sources (origin server and cache) doesn't make sense to me. The document in cache is originally from an origin server and it's just cached. If we removed the header only when we serve a document from cache, a client would see inconsistent responses that depend on the cache status. So, yes, I think we should check only the status code.
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.
Thanks for your explanation. I pushed 2faa3f9.
maskit
left a comment
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.
Thanks.
as suggested at apache/trafficserver#9877 master: hnakamur/trafficserver@2faa3f9 9.2.1: hnakamur/trafficserver@e8f1108
* Do not add content-length for status 204 cache * Do not add content-length when proxying status 204 response too (cherry picked from commit 327a003)
|
Cherry picked to the 9.2.x branch |
In master and version 9.2.1, content-length header is added when serving the cache with status 204 No Content.
It seems caused by Make 204 cacheable again by maskit · Pull Request #9333 · apache/trafficserver.
With this pull request, content-length is not added when serving the cache with status 204 No Content.
I made test cases at https://github.com/hnakamur/atstest-go.
(Note aside: the response headers in above logs are sorted alphabetically so the order is not same as the received response).
I also made the same fix for trafficserver version 9.2.1 at https://github.com/hnakamur/trafficserver/tree/9_2_1_dont_add_content_length_for_status_204_cache
https://www.rfc-editor.org/rfc/rfc9110.html#section-8.6-8