Class: EventMachine::HttpRequest
- Inherits:
-
Object
- Object
- EventMachine::HttpRequest
- Defined in:
- lib/em-http/request.rb
Overview
EventMachine based HTTP request class with support for streaming consumption of the response. Response is parsed with a Ragel-generated whitelist parser which supports chunked HTTP encoding.
Example
EventMachine.run {
http = EventMachine::HttpRequest.new('http://127.0.0.1/').get :query => {'keyname' => 'value'}
http.callback {
p http.response_header.status
p http.response_header
p http.response
EventMachine.stop
}
}
Instance Attribute Summary collapse
-
#headers ⇒ Object
readonly
Returns the value of attribute headers.
-
#response ⇒ Object
readonly
Returns the value of attribute response.
Instance Method Summary collapse
-
#get(options = {}) ⇒ Object
Send an HTTP request and consume the response.
-
#initialize(host, headers = {}) ⇒ HttpRequest
constructor
A new instance of HttpRequest.
- #post(options = {}) ⇒ Object
Constructor Details
#initialize(host, headers = {}) ⇒ HttpRequest
Returns a new instance of HttpRequest.
29 30 31 32 |
# File 'lib/em-http/request.rb', line 29 def initialize(host, headers = {}) @headers = headers @uri = URI::parse(host) end |
Instance Attribute Details
#headers ⇒ Object (readonly)
Returns the value of attribute headers.
27 28 29 |
# File 'lib/em-http/request.rb', line 27 def headers @headers end |
#response ⇒ Object (readonly)
Returns the value of attribute response.
27 28 29 |
# File 'lib/em-http/request.rb', line 27 def response @response end |
Instance Method Details
#get(options = {}) ⇒ Object
Send an HTTP request and consume the response. Supported options:
head: {Key: Value}
Specify an HTTP header, e.g. {'Connection': 'close'}
query: {Key: Value}
Specify query string parameters (auto-escaped)
body: String
Specify the request body (you must encode it for now)
46 |
# File 'lib/em-http/request.rb', line 46 def get = {}; send_request(:get, ); end |
#post(options = {}) ⇒ Object
47 |
# File 'lib/em-http/request.rb', line 47 def post = {}; send_request(:post, ); end |