Skip to content
Browse files

Ensure the body is closed

darcs-hash:20070221184907-4fc50-693c07bb37c371f103888f6b695bd4fb0afd66c1.gz
  • Loading branch information...
1 parent b7bfb94 commit 32afea9187adc5f142e15fc992a13af3a1d90c2d @chneukirchen committed Feb 21, 2007
Showing with 32 additions and 23 deletions.
  1. +6 −3 lib/rack/handler/cgi.rb
  2. +14 −11 lib/rack/handler/mongrel.rb
  3. +12 −9 lib/rack/handler/webrick.rb
View
9 lib/rack/handler/cgi.rb
@@ -21,8 +21,12 @@ def self.serve(app)
env["REQUEST_PATH"] ||= "/"
status, headers, body = app.call(env)
- send_headers status, headers
- send_body body
+ begin
+ send_headers status, headers
+ send_body body
+ ensure
+ body.close if body.respond_to? :close
+ end
end
def self.send_headers(status, headers)
@@ -41,7 +45,6 @@ def self.send_body(body)
STDOUT.print part
STDOUT.flush
}
- body.close if body.respond_to? :close
end
end
end
View
25 lib/rack/handler/mongrel.rb
@@ -36,18 +36,21 @@ def process(request, response)
env.delete "PATH_INFO" if env["PATH_INFO"] == ""
status, headers, body = @app.call(env)
-
- response.status = status.to_i
- headers.each { |k, vs|
- vs.each { |v|
- response.header[k] = v
+
+ begin
+ response.status = status.to_i
+ headers.each { |k, vs|
+ vs.each { |v|
+ response.header[k] = v
+ }
+ }
+ body.each { |part|
+ response.body << part
}
- }
- body.each { |part|
- response.body << part
- }
- body.close if body.respond_to? :close
- response.finished
+ response.finished
+ ensure
+ body.close if body.respond_to? :close
+ end
end
end
end
View
21 lib/rack/handler/webrick.rb
@@ -37,16 +37,19 @@ def service(req, res)
env.delete "PATH_INFO" if env["PATH_INFO"] == ""
status, headers, body = @app.call(env)
- res.status = status.to_i
- headers.each { |k, vs|
- vs.each { |v|
- res[k] = v
+ begin
+ res.status = status.to_i
+ headers.each { |k, vs|
+ vs.each { |v|
+ res[k] = v
+ }
}
- }
- body.each { |part|
- res.body << part
- }
- body.close if body.respond_to? :close
+ body.each { |part|
+ res.body << part
+ }
+ ensure
+ body.close if body.respond_to? :close
+ end
end
end
end

0 comments on commit 32afea9

Please sign in to comment.
Something went wrong with that request. Please try again.