rack-raw-upload 1.0.4 → 1.0.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/lib/rack/raw_upload.rb +5 -5
- data/test/raw_upload_test.rb +12 -0
- metadata +6 -6
data/lib/rack/raw_upload.rb
CHANGED
@@ -3,7 +3,7 @@ require 'tmpdir' # Needed in 1.8.7 to access Dir::tmpdir
|
|
3
3
|
module Rack
|
4
4
|
class RawUpload
|
5
5
|
|
6
|
-
VERSION = '1.0.
|
6
|
+
VERSION = '1.0.5'
|
7
7
|
|
8
8
|
def initialize(app, opts = {})
|
9
9
|
@app = app
|
@@ -61,13 +61,13 @@ module Rack
|
|
61
61
|
|
62
62
|
def kick_in?(env)
|
63
63
|
env['HTTP_X_FILE_UPLOAD'] == 'true' ||
|
64
|
-
! @explicit && env['HTTP_X_FILE_UPLOAD'] != 'false' &&
|
65
|
-
env.has_key?('HTTP_X_FILE_UPLOAD') && env['HTTP_X_FILE_UPLOAD'] != 'false' &&
|
64
|
+
! @explicit && env['HTTP_X_FILE_UPLOAD'] != 'false' && raw_file_upload?(env) ||
|
65
|
+
env.has_key?('HTTP_X_FILE_UPLOAD') && env['HTTP_X_FILE_UPLOAD'] != 'false' && raw_file_upload?(env)
|
66
66
|
end
|
67
67
|
|
68
|
-
def
|
68
|
+
def raw_file_upload?(env)
|
69
69
|
upload_path?(env['PATH_INFO']) &&
|
70
|
-
env['REQUEST_METHOD']
|
70
|
+
%{POST PUT}.include?(env['REQUEST_METHOD']) &&
|
71
71
|
content_type_of_raw_file?(env['CONTENT_TYPE'])
|
72
72
|
end
|
73
73
|
|
data/test/raw_upload_test.rb
CHANGED
@@ -33,6 +33,11 @@ class RawUploadTest < Test::Unit::TestCase
|
|
33
33
|
end
|
34
34
|
|
35
35
|
context "raw file upload" do
|
36
|
+
should "work with PUT requests" do
|
37
|
+
upload('REQUEST_METHOD' => 'PUT')
|
38
|
+
assert_file_uploaded
|
39
|
+
end
|
40
|
+
|
36
41
|
should "work with Content-Type 'application/octet-stream'" do
|
37
42
|
upload('CONTENT_TYPE' => 'application/octet-stream')
|
38
43
|
assert_file_uploaded_as 'application/octet-stream'
|
@@ -183,6 +188,13 @@ class RawUploadTest < Test::Unit::TestCase
|
|
183
188
|
assert ! rru.upload_path?('/upload')
|
184
189
|
end
|
185
190
|
end
|
191
|
+
|
192
|
+
def assert_file_uploaded
|
193
|
+
file = File.open(@path)
|
194
|
+
received = last_request.POST["file"]
|
195
|
+
assert_equal file.gets, received[:tempfile].gets
|
196
|
+
assert last_response.ok?
|
197
|
+
end
|
186
198
|
|
187
199
|
def assert_file_uploaded_as(file_type)
|
188
200
|
file = File.open(@path)
|
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rack-raw-upload
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
5
|
-
prerelease:
|
4
|
+
hash: 29
|
5
|
+
prerelease:
|
6
6
|
segments:
|
7
7
|
- 1
|
8
8
|
- 0
|
9
|
-
-
|
10
|
-
version: 1.0.
|
9
|
+
- 5
|
10
|
+
version: 1.0.5
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- Pablo Brasero
|
@@ -15,7 +15,7 @@ autorequire:
|
|
15
15
|
bindir: bin
|
16
16
|
cert_chain: []
|
17
17
|
|
18
|
-
date: 2011-06
|
18
|
+
date: 2011-07-06 00:00:00 +01:00
|
19
19
|
default_executable:
|
20
20
|
dependencies:
|
21
21
|
- !ruby/object:Gem::Dependency
|
@@ -123,7 +123,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
123
123
|
requirements: []
|
124
124
|
|
125
125
|
rubyforge_project:
|
126
|
-
rubygems_version: 1.
|
126
|
+
rubygems_version: 1.6.2
|
127
127
|
signing_key:
|
128
128
|
specification_version: 3
|
129
129
|
summary: Rack Raw Upload middleware
|