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

304 response should not include Content-Type header #19271

Merged
merged 2 commits into from
Mar 12, 2015

Conversation

eagletmt
Copy link
Contributor

Rack::Lint raises an error saying "Content-Type header found in 304
response, not allowed".

@@ -48,7 +48,10 @@ def call(env)
env['PATH_INFO'] = gzip_path
status, headers, body = @file_server.call(env)
headers['Content-Encoding'] = 'gzip'
headers['Content-Type'] = content_type(path)
if status != 304
# 304 response should not include Content-Type header.
Copy link
Member

Choose a reason for hiding this comment

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

I dont think the comment is necessary here, as the if already states that statement .

Copy link
Contributor Author

Choose a reason for hiding this comment

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

OK, I removed the trivial comment and force-pushed.

@arthurnn
Copy link
Member

As the response status code is 304, I wonder if we could short-cut this middleware altogether.
cc @jeremy

Rack::Lint raises an error saying "Content-Type header found in 304
response, not allowed".
@rafaelfranca
Copy link
Member

Yeah, I think we should skip most of the work of this middleware if 304

@pixeltrix
Copy link
Contributor

@rafaelfranca yes, since Rack::File just returns an empty triplet. @eagletmt can you rewrite call so that all of the response headers are only added if it's not 304, thanks.

Of course it'd be much better if this lived in Rack::File itself where it should be 😢

@wyaeld
Copy link
Contributor

wyaeld commented Mar 12, 2015

When did this behaviour in either rack or rails change?

@eagletmt
Copy link
Contributor Author

@arthurnn @rafaelfranca @pixeltrix I'm sorry but I couldn't figure out what to do.
Content-Encoding header must be set because FileHandler returns the content of /path/to/foo.js.gz in response to /path/to/foo.js .
What kind of procedure can I skip or short-cut here?

@arthurnn
Copy link
Member

As far as I know, if the status code is 304, you wont need to set any header nor a body in the response. So you could return it early.

@eagletmt
Copy link
Contributor Author

Ah, I get it. I modified to skip Content-Encoding and Vary header.
Thank you for your advice.

arthurnn pushed a commit that referenced this pull request Mar 12, 2015
304 response should not include Content-Type header
@arthurnn arthurnn merged commit ba7e553 into rails:master Mar 12, 2015
@arthurnn
Copy link
Member

thanks @eagletmt

@eagletmt eagletmt deleted the 304-content-type branch March 12, 2015 15:51
@adrianpike
Copy link
Contributor

@wyaeld I actually just ran into this bug! #16466 is where it started, looks like it went out in 4.2.

Looks like I get to live against master for a little bit. :)

@wyaeld
Copy link
Contributor

wyaeld commented Mar 24, 2015

@adrianpike thanks for the confirmation. We took the lesser evil temporarily of just including middleware/static.rb from master in the app, which we'll rip out once its fixed. That works fine for now.

arthurnn pushed a commit that referenced this pull request Mar 24, 2015
304 response should not include Content-Type header
arthurnn added a commit that referenced this pull request Mar 24, 2015
@arthurnn
Copy link
Member

Added a changelog entry for this b6b0884 .
And I backport it to 4-2-stable : 061b487

arthurnn added a commit that referenced this pull request Mar 24, 2015
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

6 participants