diff options
author | Laurence Lee <lalee@bigdaddy.lalee.net> | 2009-04-11 04:01:24 -1000 |
---|---|---|
committer | Laurence Lee <lalee@bigdaddy.lalee.net> | 2009-04-11 04:01:24 -1000 |
commit | 72dc967d05f811f379ca4909e64c4bac3a256314 (patch) | |
tree | dfb2be99b1805861e6432c9647e78f2186c707f6 | |
parent | 2b8134d168fbd23145f525c27328c5c8f22770c5 (diff) | |
parent | f2200adcdbb9789e7422cd24b66861ffb4e219cf (diff) | |
download | rack-72dc967d05f811f379ca4909e64c4bac3a256314.tar.gz |
Merge branch 'master' into lalee
-rw-r--r-- | Rakefile | 11 | ||||
-rw-r--r-- | lib/rack/handler/fastcgi.rb | 4 | ||||
-rw-r--r-- | lib/rack/request.rb | 16 | ||||
-rw-r--r-- | lib/rack/utils.rb | 16 |
4 files changed, 35 insertions, 12 deletions
@@ -6,12 +6,10 @@ require 'rake/testtask' desc "Run all the tests" task :default => [:test] -desc "Do predistribution stuff" -task :predist => [:chmod, :changelog, :rdoc] - desc "Make an archive as .tar.gz" -task :dist => [:predist] do +task :dist => [:chmod, :changelog, :rdoc, "SPEC"] do + FileUtils.touch("RDOX") sh "git archive --format=tar --prefix=#{release}/ HEAD^{tree} >#{release}.tar" sh "pax -waf #{release}.tar -s ':^:#{release}/:' RDOX SPEC ChangeLog doc" sh "gzip -f -9 #{release}.tar" @@ -144,14 +142,15 @@ Also see http://rack.rubyforge.org. File.open("rack.gemspec", "w") { |f| f << spec.to_ruby } end - task :gem => "rack.gemspec" do + task :gem => ["rack.gemspec", "SPEC"] do + FileUtils.touch("RDOX") sh "gem build rack.gemspec" end end desc "Generate RDoc documentation" task :rdoc do - sh(*%w{rdoc --line-numbers --inline-source --main README + sh(*%w{rdoc --line-numbers --main README --title 'Rack\ Documentation' --charset utf-8 -U -o doc} + %w{README KNOWN-ISSUES SPEC RDOX} + Dir["lib/**/*.rb"]) diff --git a/lib/rack/handler/fastcgi.rb b/lib/rack/handler/fastcgi.rb index 6324c7d2..aded5b8a 100644 --- a/lib/rack/handler/fastcgi.rb +++ b/lib/rack/handler/fastcgi.rb @@ -27,6 +27,10 @@ module Rack super end end + + def rewind + 0 # Ignore + end end def self.serve(request, app) diff --git a/lib/rack/request.rb b/lib/rack/request.rb index c1e272a6..0557837b 100644 --- a/lib/rack/request.rb +++ b/lib/rack/request.rb @@ -92,6 +92,14 @@ module Rack 'multipart/form-data' ] + # The set of media-types. Requests that do not indicate + # one of the media types presents in this list will not be eligible + # for param parsing like soap attachments or generic multiparts + PARSEABLE_DATA_MEDIA_TYPES = [ + 'multipart/related', + 'multipart/mixed' + ] + # Determine whether the request body contains form-data by checking # the request media_type against registered form-data media-types: # "application/x-www-form-urlencoded" and "multipart/form-data". The @@ -101,6 +109,12 @@ module Rack FORM_DATA_MEDIA_TYPES.include?(media_type) end + # Determine whether the request body contains data by checking + # the request media_type against registered parse-data media-types + def parseable_data? + PARSEABLE_DATA_MEDIA_TYPES.include?(media_type) + end + # Returns the data recieved in the query string. def GET if @env["rack.request.query_string"] == query_string @@ -119,7 +133,7 @@ module Rack def POST if @env["rack.request.form_input"].eql? @env["rack.input"] @env["rack.request.form_hash"] - elsif form_data? + elsif form_data? || parseable_data? @env["rack.request.form_input"] = @env["rack.input"] unless @env["rack.request.form_hash"] = Utils::Multipart.parse_multipart(env) diff --git a/lib/rack/utils.rb b/lib/rack/utils.rb index 7acc10d2..01519ef4 100644 --- a/lib/rack/utils.rb +++ b/lib/rack/utils.rb @@ -293,7 +293,7 @@ module Rack def self.parse_multipart(env) unless env['CONTENT_TYPE'] =~ - %r|\Amultipart/form-data.*boundary=\"?([^\";,]+)\"?|n + %r|\Amultipart/.*boundary=\"?([^\";,]+)\"?|n nil else boundary = "--#{$1}" @@ -319,15 +319,15 @@ module Rack filename = content_type = name = nil until head && buf =~ rx - if !head && i = buf.index("\r\n\r\n") + if !head && i = buf.index(EOL+EOL) head = buf.slice!(0, i+2) # First \r\n buf.slice!(0, 2) # Second \r\n filename = head[/Content-Disposition:.* filename="?([^\";]*)"?/ni, 1] - content_type = head[/Content-Type: (.*)\r\n/ni, 1] - name = head[/Content-Disposition:.* name="?([^\";]*)"?/ni, 1] + content_type = head[/Content-Type: (.*)#{EOL}/ni, 1] + name = head[/Content-Disposition:.*\s+name="?([^\";]*)"?/ni, 1] || head[/Content-ID:\s*([^#{EOL}]*)/ni, 1] - if filename + if content_type || filename body = Tempfile.new("RackMultipart") body.binmode if body.respond_to?(:binmode) end @@ -369,6 +369,12 @@ module Rack data = {:filename => filename, :type => content_type, :name => name, :tempfile => body, :head => head} + elsif !filename && content_type + body.rewind + + # Generic multipart cases, not coming from a form + data = {:type => content_type, + :name => name, :tempfile => body, :head => head} else data = body end |