Skip to content
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

Actually send header and code during WriteHeader, if needed #5404

Merged
merged 3 commits into from Sep 20, 2019

Conversation

mpl
Copy link
Collaborator

@mpl mpl commented Sep 17, 2019

What does this PR do?

Before this change, the codeCatcher relied on the fact that Write would
always be called, and hence was in charge of actually sending the headers
that WriteHeader had "cached" when it had been called.

However, in the case of e.g. a 304, since the response should not have
any body, there is no reason for the caller (i.e. another proxy or
middleware in the chain of calls) to call the codeCatcher's Write.
Therefore, neither the headers, and hence nor the the response code,
were actually forwarded to the client.

Consequently, this change moves the responsibility of actually
forwarding the headers and response code to where it belongs, i.e. in
WriteHeader.

In addition, this change adds a wrapper of the codeCatcher, so that we
can satisfy the CloseNotify interface as well.

N.B: in hindsight, I think it might be possible to reproduce #5385 even before 753d173 , if one is vicious enough to include the 304 code in the range of watched error codes.

Motivation

To properly handle 304 responses (and probably other headers related bugs lurking around).

More

  • Added/updated tests
  • [] Added/updated documentation

Additional Notes

Fixes #5385

Co-authored-by: Julien Salleyron julien.salleyron@gmail.com

Copy link
Member

@ldez ldez left a comment

Choose a reason for hiding this comment

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

LGTM

Copy link
Contributor

@dtomcej dtomcej left a comment

Choose a reason for hiding this comment

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

LGTM
:shipit:

Copy link
Member

@mmatur mmatur left a comment

Choose a reason for hiding this comment

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

LGTM

mpl and others added 3 commits September 20, 2019 16:24
Before this change, the codeCatcher relied on the fact that Write would
always be called, and hence was in charge of actually sending the headers
that WriteHeader had "cached" when it had been called.

However, in the case of e.g. a 304, since the response should not have
any body, there is no reason for the caller (i.e. another proxy or
middleware in the chain of calls) to call the codeCatcher's Write.
Therefore, neither the headers, and hence nor the the response code,
were actually forwarded to the client.

Consequently, this change moves the responsibility of actually
forwarding the headers and response code to where it belongs, i.e. in
WriteHeader.

In addition, this change adds a wrapper of the codeCatcher, so that we
can satisfy the CloseNotify interface as well.

Fixes traefik#5385
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.

None yet

5 participants