Class Rev::HttpClient
In: lib/rev/http_client.rb
Parent: TCPSocket

HTTP client class implemented as a subclass of Rev::TCPSocket. Encodes requests and allows streaming consumption of the response. Response is parsed with a Ragel-generated whitelist parser which supports chunked HTTP encoding.

Example

  loop = Rev::Loop.default
  client = Rev::HttpClient.connect("www.google.com").attach
  client.get('/search', query: {q: 'foobar'})
  loop.run

Methods

Included Modules

HttpEncoding

Constants

ALLOWED_METHODS = [:put, :get, :post, :delete, :head]
TRANSFER_ENCODING = "TRANSFER_ENCODING"
CONTENT_LENGTH = "CONTENT_LENGTH"
SET_COOKIE = "SET_COOKIE"
LOCATION = "LOCATION"
HOST = "HOST"
CRLF = "\r\n"

Public Class methods

Connect to the given server, with port 80 as the default

Public Instance methods

Enable the HttpClient if it has been disabled

Called when part of the body has been read

Called when an error occurs dispatching the request

Called when the request has completed

Called when response header has been received

Send an HTTP request and consume the response. Supports the following options:

  head: {Key: Value}
    Specify an HTTP header, e.g. {'Connection': 'close'}

  query: {Key: Value}
    Specify query string parameters (auto-escaped)

  cookies: {Key: Value}
    Specify hash of cookies (auto-escaped)

  body: String
    Specify the request body (you must encode it for now)

Protected Instance methods

Response processing

Request sending

[Validate]