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

Content-* headers are stripped off HEAD response #304

Closed
nandosola opened this issue Jul 5, 2013 · 3 comments
Closed

Content-* headers are stripped off HEAD response #304

nandosola opened this issue Jul 5, 2013 · 3 comments

Comments

@nandosola
Copy link

Hi!

I have a fairly simple Sinatra app that makes use of send_file for GET and HEAD requests to a given path. The HTTP client side depends on asking a HEAD request before getting a file. For GET requests, the response headers look normal:

Content-Type: application/pdf
Last-Modified: Fri, 05 Jul 2013 11:38:00 GMT
X-Content-Type-Options: nosniff
Vary: Accept-Encoding
Transfer-Encoding: chunked

Both in Puma 2.1.x & 2.2.x, the response to the HEAD request is missing the content related information in its headers:

Last-Modified: Fri, 05 Jul 2013 11:38:00 GMT
X-Content-Type-Options: nosniff
Vary: Accept-Encoding

Interestingly enough, in Puma 2.0.1 (or WEBRick) the HEAD response is OK:

Content-Type: application/pdf
Last-Modified: Fri, 05 Jul 2013 11:38:00 GMT
X-Content-Type-Options: nosniff
Vary: Accept-Encoding
Content-Length: 68807

I'm able to reproduce this behaviour using the latest master and adding a new test under test/test_puma_server.rb

def test_HEAD_returns_content_headers
    @server.app = proc { |env| [200, {"Content-Type" => "application/pdf",
                                      "Content-Length" => "4242"}, []] }

    @server.add_tcp_listener @host, @port
    @server.run

    sock = TCPSocket.new @host, @port
    sock << "HEAD / HTTP/1.0\r\n\r\n"

    data = sock.read

    assert_equal "HTTP/1.0 200 OK\r\nContent-Type: application/pdf\r\nContent-Length: 4242\r\n\r\n", data
  end

Env info:

  • Sinatra 1.4.3
  • jruby 1.7.2 (1.9.3p327) 2013-01-04 302c706 on Java HotSpot(TM) 64-Bit Server VM 1.7.0_21-b12 [darwin-x86_64]

Note:

@evanphx
Copy link
Member

evanphx commented Jul 6, 2013

I'd like to call out this issue as a wonder one. The failing test case made it so easy for me to figure out what was wrong and correct the issue in only about 5 minutes.

🚀 👍 :octocat:

@evanphx evanphx closed this as completed in f7f7733 Jul 6, 2013
@nandosola
Copy link
Author

Cheers! Have a good weekend!

@nathansamson
Copy link
Contributor

Hi,

I had a user reporting that (sometimes) they viewed the source code of the website. Sometimes HTML, sometimes the JavaScript AJAX response. This seemsed to have been caused by using the back button and caches etc...

I've never found a way to reproduce this reliably (although I've seen this myself), but it occured in different browsers (Firefox, Chrome at least) and different OS (linux, windows).

Could this problem been caused by this?
My setup is (F5) -> nginx -> Puma (rails 3.2)
Note that F5 was not always present.

I thought I already posted this, so if I posted thissomewhere else my apologies...

Regards,
Nathan

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants