Skip to content

Commit

Permalink
#302: adjust Content-Length header (if present) to account for new JS…
Browse files Browse the repository at this point in the history
…ONP response body; fixes specs
  • Loading branch information
Alex Vondrak committed Dec 12, 2014
1 parent 92bad68 commit 7288238
Showing 1 changed file with 6 additions and 3 deletions.
9 changes: 6 additions & 3 deletions lib/goliath/rack/jsonp.rb
Expand Up @@ -11,17 +11,20 @@ class JSONP
def post_process(env, status, headers, body)
return [status, headers, body] unless env.params['callback']

response = ""
response = ''
if body.respond_to?(:each)
body.each { |s| response << s }
else
response = body
end

response = "#{env.params['callback']}(#{response})"

headers[Goliath::Constants::CONTENT_TYPE] = 'application/javascript'
[status, headers, ["#{env.params['callback']}(#{response})"]]
headers['Content-Length'] &&= response.bytesize.to_s

[status, headers, [response]]
end
end
end
end

0 comments on commit 7288238

Please sign in to comment.