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

cached responses should NOT include content-length #144

Closed
catmando opened this issue Mar 23, 2016 · 2 comments
Closed

cached responses should NOT include content-length #144

catmando opened this issue Mar 23, 2016 · 2 comments

Comments

@catmando
Copy link

This is the problem behind #142

Cached responses are including the Content-Length header, and if that value does not match the actual content length, then things break.

The actual content length may differ in the case of a jsonp request, where the callback id may not be the same number of characters as the value that was cached.

A quick monkey patch does the trick:

# i.e add to spec_helper.rb
Billy::ProxyConnection.send(:define_method, :send_response) do |response|
  res = EM::DelegatedHttpResponse.new(self)
  res.status = response[:status]
  res.headers = response[:headers]
  res.headers.delete("Content-Length")
  res.content = response[:content]
  res.send_response
end

would you like a PR with this solution?

FYI I thought about simply not caching the Content-Length but that seems like a bad idea for a couple of reasons.

  1. This problem may exist in caches that are out there in the wild, and so the above solution works in spite of that.

  2. It just feels better to write a the Content-Length if request_headers was asked for, and then blow it away when stubbing the request.

@ronwsmith
Copy link
Collaborator

I think the cleanest solution would be to not cache it when jsonp is enabled. Please submit a PR deleting it conditionally over here: https://github.com/oesmith/puffing-billy/blob/master/lib/billy/handlers/proxy_handler.rb#L78

@ronwsmith
Copy link
Collaborator

@catmando I see that @jaydorsey made a monkey patch in his puffing-billy fork, but no PR was ever submitted. If either of you submit a PR, I'd be happy to accept it.

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

2 participants