Browse files

Better handling of proxy response content-length

  • Loading branch information...
1 parent fca7cc3 commit a73b9bad1e308a52aa119a7722039cc6edc9e699 @wagenet wagenet committed Sep 10, 2010
Showing with 9 additions and 2 deletions.
  1. +9 −2 lib/sproutcore/rack/proxy.rb
View
11 lib/sproutcore/rack/proxy.rb
@@ -104,8 +104,15 @@ def handle_proxy(proxy, proxy_url, env)
# Location headers should rewrite the hostname if it is included.
value.gsub!(/^http:\/\/#{http_host}(:[0-9]+)?\//, "http://#{http_host}/") if key.downcase == 'location'
# content-length is returning char count not bytesize
- value = response.body.bytesize.to_s if key.downcase == 'content-length'
-
+ if key.downcase == 'content-length'
+ if response.body.respond_to?(:bytesize)
+ value = response.body.bytesize.to_s
+ elsif response.body.respond_to?(:size)
+ value = response.body.size.to_s
+ else
+ value = '0'
+ end
+ end
SC.logger << " #{key}: #{value}\n"
response_headers[key] = value

0 comments on commit a73b9ba

Please sign in to comment.