Skip to content

Instantly share code, notes, and snippets.

@collin
Created July 30, 2008 12:53
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save collin/3261 to your computer and use it in GitHub Desktop.
Save collin/3261 to your computer and use it in GitHub Desktop.
require 'rubygems'
$:.unshift "sinatra/lib"
require "sinatra"
get "/form" do
haml %{
%form.song{:action => "/songs", :method => "post", :enctype=>"multipart/form-data"}
/%input{:type=>"text", :name => "url"}
%input{:type=>"file", :name => "file"}
%input{:type=>"submit", :value=> ">"}
}
end
post "/songs" do
redirect "/form"
end
Strangly, this breaks with Mongrel when uploading a matching "*.mp3" (possibly others)
index b02786d..d3bdc68 100755
--- a/lib/sinatra.rb
+++ b/lib/sinatra.rb
@@ -1235,7 +1235,13 @@ module Sinatra
body = returned.to_result(context)
end
body = '' unless body.respond_to?(:each)
- body = '' if request.request_method.upcase == 'HEAD'
+
+# Using request.env["REQUEST_METHOD"].upcase instead of:
+# request.request_method because it failed silently
+# in the example: http://gist.github.com/3261
+# when uploading a file matching "*.mp3"
+ body = '' if request.env["REQUEST_METHOD"].upcase == 'HEAD'
+
context.body = body.kind_of?(String) ? [*body] : body
context.finish
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment