Module: M2R::Upload
- Included in:
- Request
- Defined in:
- lib/m2r/request/upload.rb
Overview
Logic for Mongrel2 request delivered using async-upload feature Contains methods for recognizing such requests and reading them.
Instance Method Summary collapse
-
#body_io ⇒ File
Request body encapsulated in IO compatible object.
-
#free! ⇒ nil
Free external resources such as files or sockets.
-
#upload? ⇒ true, false
True if this is async-upload related request.
-
#upload_done? ⇒ true, false
True if this is final async-upload request.
-
#upload_path ⇒ String
Relative path to file containing body of HTTP request.
-
#upload_start? ⇒ true, false
True if this is async-upload start notification.
Instance Method Details
#body_io ⇒ File
Returns Request body encapsulated in IO compatible object.
33 34 35 36 37 38 39 40 |
# File 'lib/m2r/request/upload.rb', line 33 def body_io return super unless upload_done? @body_io ||= begin f = File.open(upload_path, "r+b") f.set_encoding(Encoding::BINARY) if f.respond_to?(:set_encoding) f end end |
#free! ⇒ nil
Returns Free external resources such as files or sockets.
44 45 46 47 |
# File 'lib/m2r/request/upload.rb', line 44 def free! super File.delete(body_io.path) if upload_done? end |
#upload? ⇒ true, false
Returns True if this is async-upload related request.
8 9 10 |
# File 'lib/m2r/request/upload.rb', line 8 def upload? !!@mongrel_headers['x-mongrel2-upload-start'] end |
#upload_done? ⇒ true, false
Returns True if this is final async-upload request.
20 21 22 |
# File 'lib/m2r/request/upload.rb', line 20 def upload_done? upload? and upload_path end |
#upload_path ⇒ String
Returns Relative path to file containing body of HTTP request.
27 28 29 |
# File 'lib/m2r/request/upload.rb', line 27 def upload_path @mongrel_headers['x-mongrel2-upload-done'] end |
#upload_start? ⇒ true, false
Returns True if this is async-upload start notification.
14 15 16 |
# File 'lib/m2r/request/upload.rb', line 14 def upload_start? upload? and not upload_path end |