Skip to content

Conversation

@hnakamur
Copy link
Contributor

@hnakamur hnakamur commented Jun 18, 2023

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

A server MUST NOT send a Content-Length header field in any response with a status code of 1xx (Informational) or 204 (No Content). A server MUST NOT send a Content-Length header field in any 2xx (Successful) response to a CONNECT request (Section 9.3.6).

@bneradt
Copy link
Contributor

bneradt commented Jun 20, 2023

[approve ci rocky]

@randall randall added this to the 10.0.0 milestone Jun 20, 2023
@randall randall added the HTTP label Jun 20, 2023
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)) {
Copy link
Member

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?

Copy link
Contributor Author

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

Copy link
Member

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.

Copy link
Contributor Author

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.

Copy link
Member

@maskit maskit left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks.

@maskit maskit merged commit 327a003 into apache:master Jun 21, 2023
hnakamur added a commit to hnakamur/atstest-go that referenced this pull request Jun 21, 2023
bryancall pushed a commit that referenced this pull request Jun 26, 2023
* 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)
@bryancall bryancall modified the milestones: 10.0.0, 9.2.2 Jun 26, 2023
@bryancall
Copy link
Contributor

Cherry picked to the 9.2.x branch

@bryancall bryancall added the Bug label Jun 26, 2023
@hnakamur hnakamur deleted the dont_add_content_length_for_status_204_cache branch June 26, 2023 20:06
masaori335 pushed a commit to masaori335/trafficserver that referenced this pull request Jul 24, 2023
* 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 from commit 7226cba)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants