Class FTW::Agent
In: lib/ftw/agent.rb
lib/ftw/agent.rb
Parent: Object

This should act as a proper web agent.

  • Reuse connections.
  • SSL/TLS.
  • HTTP Upgrade support.
  • HTTP 1.1 (RFC2616).
  • WebSockets (RFC6455).
  • Support Cookies.

All standard HTTP methods defined by RFC2616 are available as methods on this agent: get, head, put, etc.

Example:

    agent = FTW::Agent.new
    request = agent.get("http://www.google.com/")
    response = agent.execute(request)
    puts response.body.read

For any standard http method (like ‘get’) you can invoke it with ’!’ on the end and it will execute and return a FTW::Response object:

    agent = FTW::Agent.new
    response = agent.get!("http://www.google.com/")
    puts response.body.head

TODO(sissel): TBD: implement cookies… delicious chocolate chip cookies.

Methods

execute   execute   new   new   request   request   shutdown   shutdown   upgrade!   upgrade!   websocket!   websocket!  

Included Modules

FTW::Protocol FTW::Agent::Configuration FTW::Protocol FTW::Agent::Configuration

Classes and Modules

Module FTW::Agent::Configuration
Class FTW::Agent::TooManyRedirects

Constants

STANDARD_METHODS = %w(options get head post put delete trace connect)   List of standard HTTP methods described in RFC2616
STANDARD_METHODS = %w(options get head post put delete trace connect)   List of standard HTTP methods described in RFC2616

Public Class methods

Everything is private by default. At the bottom of this class, public methods will be declared.

Everything is private by default. At the bottom of this class, public methods will be declared.

Public Instance methods

Execute a FTW::Request in this Agent.

If an existing, idle connection is already open to the target server of this Request, it will be reused. Otherwise, a new connection is opened.

Redirects are always followed.

@param [FTW::Request] @return [FTW::Response] the response for this request.

Execute a FTW::Request in this Agent.

If an existing, idle connection is already open to the target server of this Request, it will be reused. Otherwise, a new connection is opened.

Redirects are always followed.

@param [FTW::Request] @return [FTW::Response] the response for this request.

Build a request. Returns a FTW::Request object.

Arguments:

  • method - the http method
  • uri - the URI to make the request to
  • options - a hash of options

uri can be a valid url or an Addressable::URI object. The uri will be used to choose the host/port to connect to. It also sets the protocol (https, etc). Further, it will set the ‘Host’ header.

The ‘options’ hash supports the following keys:

  • :headers => { string => string, … }. This allows you to set header values.

Build a request. Returns a FTW::Request object.

Arguments:

  • method - the http method
  • uri - the URI to make the request to
  • options - a hash of options

uri can be a valid url or an Addressable::URI object. The uri will be used to choose the host/port to connect to. It also sets the protocol (https, etc). Further, it will set the ‘Host’ header.

The ‘options’ hash supports the following keys:

  • :headers => { string => string, … }. This allows you to set header values.

shutdown this agent.

This will shutdown all active connections.

shutdown this agent.

This will shutdown all active connections.

Send the request as an HTTP upgrade.

Returns the response and the FTW::Connection for this connection. If the upgrade was denied, the connection returned will be nil.

Send the request as an HTTP upgrade.

Returns the response and the FTW::Connection for this connection. If the upgrade was denied, the connection returned will be nil.

Make a new websocket connection.

This will send the http request. If the websocket handshake is successful, a FTW::WebSocket instance will be returned. Otherwise, a FTW::Response will be returned.

See {request} for what the ‘uri’ and ‘options’ parameters should be.

Make a new websocket connection.

This will send the http request. If the websocket handshake is successful, a FTW::WebSocket instance will be returned. Otherwise, a FTW::Response will be returned.

See {request} for what the ‘uri’ and ‘options’ parameters should be.

[Validate]