-
Notifications
You must be signed in to change notification settings - Fork 87
Requests
See also: Reel::Request and Reel::RequestMixin Yardocs
Reel::Request
objects represent an incoming HTTP request from a client. The following methods can be used to obtain the request properties:
>> request.method
=> "GET"
>> request.url
=> "/foobar?baz=quux"
>> request.uri
=> #<URI::Generic:0x007ff70b8ba588 URL:/foobar?baz=quux>
>> request.path
=> "/foobar"
>> request.query_string
=> "baz=quux"
>> request.headers
=> {"User-Agent"=>
"curl/7.24.0 (x86_64-apple-darwin12.0) libcurl/7.24.0 OpenSSL/0.9.8x zlib/1.2.5",
"Host"=>"localhost:3000",
"Accept"=>"*/*"}
# shorthand
>> request["Host"]
=> "localhost:3000"
>> request.version
=> "1.1"
> request.websocket?
=> true
>> request.body
=> #<Reel::RequestBody:3fd5a89e1cc8 @streaming=false>
See also: Reel::RequestBody Yardoc
Reel::RequestBody
is an object representing an incoming request body. Unlike frameworks like Rack (which mandates "rewindable input"), Reel has been proactively designed to support the streaming of request bodies, allowing you to handle them incrementally as they're uploaded to the server. It also supports methods for quickly consuming the request body as a string.
>> request.body.to_s
=> "hello, world!"
The #readpartial
method of Reel::RequestBody
can be used to incrementally stream the body:
>> request.body.readpartial(3)
=> "hel"
>> request.body.readpartial(5)
=> "lo,wo"
>> request.body.readpartial(10)
=> "rld!"
>> request.body.readpartial(10)
=> nil
Reel::RequestBody
is an Enumerable
, so you can use the #each
method to iterate over it:
>> request.body.each { |chunk| puts chunk }
hello,
world!
=> nil