rack-raw-upload 1.0.7 → 1.0.8

Sign up to get free protection for your applications and to get access to all the features.
@@ -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.7'
6
+ VERSION = '1.0.8'
7
7
 
8
8
  def initialize(app, opts = {})
9
9
  @app = app
@@ -33,7 +33,7 @@ module Rack
33
33
  env['rack.input'].extend(EqlFix)
34
34
  tempfile = env['rack.input']
35
35
  else
36
- tempfile = create_tempfile
36
+ tempfile = Tempfile.new('raw-upload.', @tmpdir)
37
37
  tempfile << env['rack.input'].read
38
38
  tempfile.flush
39
39
  tempfile.rewind
@@ -78,7 +78,7 @@ module Rack
78
78
  regexp = '^' + candidate.gsub('.', '\.').gsub('*', '[^/]*') + '$'
79
79
  !! (Regexp.new(regexp) =~ request_path)
80
80
  end
81
-
81
+
82
82
  def content_type_of_raw_file?(content_type)
83
83
  case content_type
84
84
  when %r{^application/x-www-form-urlencoded}, %r{^multipart/form-data}
@@ -88,29 +88,6 @@ module Rack
88
88
  end
89
89
  end
90
90
 
91
- def create_tempfile
92
- tempfile = Tempfile.new('raw-upload.', @tmpdir)
93
-
94
- # If the GC runs, it may unlink the tempfile.
95
- # To avoid this, I create another version of it
96
- # (a hard link to the same file). If the original
97
- # is unlinked, we'll still have this other link.
98
- ret = relink_file(tempfile)
99
- tempfile.close
100
- ret
101
- end
102
-
103
- def relink_file(file)
104
- new_name = file.path + random_string
105
- ::File.link(file.path, new_name)
106
- ret = ::File.open(new_name, "r+")
107
- ret.binmode
108
- ret
109
- rescue SystemCallError
110
- # The randomly chosen file name was taken. Try again.
111
- retry
112
- end
113
-
114
91
  def random_string
115
92
  (0...8).map{65.+(rand(25)).chr}.join
116
93
  end
@@ -98,11 +98,29 @@ class RawUploadTest < Test::Unit::TestCase
98
98
  assert_successful_non_upload
99
99
  end
100
100
 
101
- should "ensure the uploaded file exists after garbage collection (Ruby 1.9)" do
102
- upload
103
- received = last_request.POST["file"]
104
- GC.start
105
- assert File.exists?(received[:tempfile].path)
101
+ context "when garbage collection runs (Ruby 1.9)" do
102
+ context "and the file is received as a Tempfile" do
103
+ should "ensure that the uploaded file remains" do
104
+ tempfile = Tempfile.new('rack-raw-upload-test-')
105
+ tempfile << @file.read
106
+ tempfile.rewind
107
+ upload('rack.input' => tempfile)
108
+ received = last_request.POST["file"]
109
+ GC.start
110
+ assert File.exists?(received[:tempfile].path)
111
+ assert_file_uploaded
112
+ end
113
+ end
114
+
115
+ context "and the file is NOT received as a TmpFile" do
116
+ should "ensure that the uploaded file remains" do
117
+ upload
118
+ received = last_request.POST["file"]
119
+ GC.start
120
+ assert File.exists?(received[:tempfile].path)
121
+ assert_file_uploaded
122
+ end
123
+ end
106
124
  end
107
125
 
108
126
  context "with X-File-Upload: smart" do
metadata CHANGED
@@ -1,88 +1,70 @@
1
- --- !ruby/object:Gem::Specification
1
+ --- !ruby/object:Gem::Specification
2
2
  name: rack-raw-upload
3
- version: !ruby/object:Gem::Version
4
- hash: 25
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.0.8
5
5
  prerelease:
6
- segments:
7
- - 1
8
- - 0
9
- - 7
10
- version: 1.0.7
11
6
  platform: ruby
12
- authors:
7
+ authors:
13
8
  - Pablo Brasero
14
9
  autorequire:
15
10
  bindir: bin
16
11
  cert_chain: []
17
-
18
- date: 2011-08-20 00:00:00 Z
19
- dependencies:
20
- - !ruby/object:Gem::Dependency
12
+ date: 2011-10-08 00:00:00.000000000Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
21
15
  name: json
22
- prerelease: false
23
- requirement: &id001 !ruby/object:Gem::Requirement
16
+ requirement: &2153512340 !ruby/object:Gem::Requirement
24
17
  none: false
25
- requirements:
26
- - - ">="
27
- - !ruby/object:Gem::Version
28
- hash: 3
29
- segments:
30
- - 0
31
- version: "0"
18
+ requirements:
19
+ - - ! '>='
20
+ - !ruby/object:Gem::Version
21
+ version: '0'
32
22
  type: :runtime
33
- version_requirements: *id001
34
- - !ruby/object:Gem::Dependency
35
- name: rake
36
23
  prerelease: false
37
- requirement: &id002 !ruby/object:Gem::Requirement
24
+ version_requirements: *2153512340
25
+ - !ruby/object:Gem::Dependency
26
+ name: rake
27
+ requirement: &2153511880 !ruby/object:Gem::Requirement
38
28
  none: false
39
- requirements:
40
- - - ">="
41
- - !ruby/object:Gem::Version
42
- hash: 3
43
- segments:
44
- - 0
45
- version: "0"
29
+ requirements:
30
+ - - ! '>='
31
+ - !ruby/object:Gem::Version
32
+ version: '0'
46
33
  type: :development
47
- version_requirements: *id002
48
- - !ruby/object:Gem::Dependency
49
- name: rack-test
50
34
  prerelease: false
51
- requirement: &id003 !ruby/object:Gem::Requirement
35
+ version_requirements: *2153511880
36
+ - !ruby/object:Gem::Dependency
37
+ name: rack-test
38
+ requirement: &2153511460 !ruby/object:Gem::Requirement
52
39
  none: false
53
- requirements:
54
- - - ">="
55
- - !ruby/object:Gem::Version
56
- hash: 3
57
- segments:
58
- - 0
59
- version: "0"
40
+ requirements:
41
+ - - ! '>='
42
+ - !ruby/object:Gem::Version
43
+ version: '0'
60
44
  type: :development
61
- version_requirements: *id003
62
- - !ruby/object:Gem::Dependency
63
- name: shoulda
64
45
  prerelease: false
65
- requirement: &id004 !ruby/object:Gem::Requirement
46
+ version_requirements: *2153511460
47
+ - !ruby/object:Gem::Dependency
48
+ name: shoulda
49
+ requirement: &2153511000 !ruby/object:Gem::Requirement
66
50
  none: false
67
- requirements:
68
- - - ">="
69
- - !ruby/object:Gem::Version
70
- hash: 3
71
- segments:
72
- - 0
73
- version: "0"
51
+ requirements:
52
+ - - ! '>='
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
74
55
  type: :development
75
- version_requirements: *id004
76
- description: Middleware that converts files uploaded with mimetype application/octet-stream into normal form input, so Rack applications can read these as normal, rather than as raw input.
56
+ prerelease: false
57
+ version_requirements: *2153511000
58
+ description: Middleware that converts files uploaded with mimetype application/octet-stream
59
+ into normal form input, so Rack applications can read these as normal, rather than
60
+ as raw input.
77
61
  email: pablobm@gmail.com
78
62
  executables: []
79
-
80
63
  extensions: []
81
-
82
- extra_rdoc_files:
64
+ extra_rdoc_files:
83
65
  - LICENSE
84
66
  - README.md
85
- files:
67
+ files:
86
68
  - lib/rack/raw_upload.rb
87
69
  - lib/rack-raw-upload.rb
88
70
  - test/raw_upload_test.rb
@@ -92,38 +74,29 @@ files:
92
74
  - Gemfile.lock
93
75
  homepage: https://github.com/newbamboo/rack-raw-upload
94
76
  licenses: []
95
-
96
77
  post_install_message:
97
- rdoc_options:
78
+ rdoc_options:
98
79
  - --charset=UTF-8
99
80
  - --main
100
81
  - README.rdoc
101
- require_paths:
82
+ require_paths:
102
83
  - lib
103
- required_ruby_version: !ruby/object:Gem::Requirement
84
+ required_ruby_version: !ruby/object:Gem::Requirement
104
85
  none: false
105
- requirements:
106
- - - ">="
107
- - !ruby/object:Gem::Version
108
- hash: 3
109
- segments:
110
- - 0
111
- version: "0"
112
- required_rubygems_version: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - ! '>='
88
+ - !ruby/object:Gem::Version
89
+ version: '0'
90
+ required_rubygems_version: !ruby/object:Gem::Requirement
113
91
  none: false
114
- requirements:
115
- - - ">="
116
- - !ruby/object:Gem::Version
117
- hash: 3
118
- segments:
119
- - 0
120
- version: "0"
92
+ requirements:
93
+ - - ! '>='
94
+ - !ruby/object:Gem::Version
95
+ version: '0'
121
96
  requirements: []
122
-
123
97
  rubyforge_project:
124
98
  rubygems_version: 1.8.6
125
99
  signing_key:
126
100
  specification_version: 3
127
101
  summary: Rack Raw Upload middleware
128
102
  test_files: []
129
-