Created
July 30, 2008 12:53
-
-
Save collin/3261 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Strangly, this breaks with Mongrel when uploading a matching "*.mp3" (possibly others) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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