lib/rack_jetty/servlet_handler.rb in rack-jetty-0.1.0 vs lib/rack_jetty/servlet_handler.rb in rack-jetty-0.2.0
- old
+ new
@@ -20,11 +20,11 @@
def handle(target, request, response, dispatch)
begin
env = DefaultRackEnv.merge({
'rack.input' => Rack::RewindableInput.new(JavaInput.new(request.get_input_stream)),
'rack.url_scheme' => request.get_scheme,
- 'CONTENT_TYPE' => request.get_content_type.to_s,
+ 'CONTENT_TYPE' => request.get_content_type,
'CONTENT_LENGTH' => request.get_content_length, # some post-processing done below
'REQUEST_METHOD' => request.get_method || "GET",
'REQUEST_URI' => request.getRequestURI,
'PATH_INFO' => request.get_path_info,
'QUERY_STRING' => request.get_query_string || "",
@@ -39,10 +39,21 @@
next if h =~ /^Content-(Type|Length)$/i
k = "HTTP_#{h.upcase.gsub(/-/, '_')}"
env[k] = request.getHeader(h) unless env.has_key?(k)
end
+ # request.get_content_type returns nil if the Content-Type is not included
+ # and Rack doesn't expect Content-Type => '' - certain methods will issue
+ # a backtrace if it's passed in.
+ #
+ # The correct behaviour is not to include Content-Type in the env hash
+ # if it is blank.
+ #
+ # https://github.com/rack/rack/issues#issue/40 covers the problem from
+ # Rack's end.
+ env.delete('CONTENT_TYPE') if [nil, ''].include?(env['CONTENT_TYPE'])
+
status, headers, output = handler.app.call(env)
if (match = %r{^([0-9]{3,3}) +([[:print:]]+)$}.match(status.to_s))
response.set_status(match[1].to_i, match[2].to_s)
else
@@ -60,13 +71,13 @@
end
end
buffer = response.get_output_stream
output.each do |s|
- buffer.print(s)
+ buffer.write(s.to_java_bytes)
end
ensure
request.set_handled(true)
end
end
end
-end
\ No newline at end of file
+end