Class | FTW::Agent |
In: |
lib/ftw/agent.rb
lib/ftw/agent.rb |
Parent: | Object |
This should act as a proper web agent.
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.
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:
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:
Build a request. Returns a FTW::Request object.
Arguments:
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:
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.