Class: HTTP::Client

### Home Classes Methods

### In Files

- lib/http/client.rb

### Parent

Object

### Methods

- ::new
- #close
- #make_request
- #perform
- #request

### Included Modules

- HTTP::Chainable

### Class/Module Index

Quicksearch

- HTTP
- HTTP::Cache
- HTTP::Cache::Headers
- HTTP::Cache::NullCache
- HTTP::Cache::NullLogger
- HTTP::CacheError
- HTTP::Chainable
- HTTP::Client
- HTTP::Connection
- HTTP::Error
- HTTP::Headers
- HTTP::Headers::Mixin
- HTTP::InvalidHeaderNameError
- HTTP::MimeType
- HTTP::MimeType::Adapter
- HTTP::MimeType::JSON
- HTTP::Options
- HTTP::Redirector
- HTTP::Redirector::EndlessRedirectError
- HTTP::Redirector::TooManyRedirectsError
- HTTP::Request
- HTTP::Request::Caching
- HTTP::Request::UnsupportedMethodError
- HTTP::Request::UnsupportedSchemeError
- HTTP::Request::Writer
- HTTP::RequestError
- HTTP::Response
- HTTP::Response::Body
- HTTP::Response::Caching
- HTTP::Response::IoBody
- HTTP::Response::Parser
- HTTP::Response::Status
- HTTP::Response::StringBody
- HTTP::ResponseError
- HTTP::StateError
- HTTP::Timeout
- HTTP::Timeout::Global
- HTTP::Timeout::Null
- HTTP::Timeout::PerOperation
- HTTP::TimeoutError
- HTTP::URI
- Object

No matching classes.

# HTTP::Client

Clients make requests and receive responses

### Constants

CLOSE
HTTP_OR_HTTPS_RE
KEEP_ALIVE

### Public Class Methods

new(default_options = {}) click to toggle source

    # File lib/http/client.rb, line 24
    def initialize(default_options = {})
      @default_options = HTTP::Options.new(default_options)
      @connection = nil
      @state = :clean
    end

### Public Instance Methods

close() click to toggle source

    # File lib/http/client.rb, line 91
    def close
      @connection.close if @connection
      @connection = nil
      @state = :clean
    end

make_request(req, options) click to toggle source

    # File lib/http/client.rb, line 60
    def make_request(req, options)
      verify_connection!(req.uri)

      @state = :dirty

      @connection ||= HTTP::Connection.new(req, options)

      unless @connection.failed_proxy_connect?
        @connection.send_request(req)
        @connection.read_headers!
      end

      res = Response.new(
        @connection.status_code,
        @connection.http_version,
        @connection.headers,
        Response::Body.new(@connection),
        req.uri
      )

      @connection.finish_response if req.verb == :head
      @state = :clean

      res
    rescue
      # On any exception we reset the conn. This is a safety measure, to ensure
      # we don't have conns in a bad state resulting in mixed requests/responses
      close if persistent?
      raise
    end

perform(req, options) click to toggle source

Perform a single (no follow) HTTP request

    # File lib/http/client.rb, line 49
    def perform(req, options)
      options.cache.perform(req, options) do |r, opts|
        make_request(r, opts)
      end
    end

request(verb, uri, opts = {}) click to toggle source

Make an HTTP request

    # File lib/http/client.rb, line 31
    def request(verb, uri, opts = {})
      opts    = @default_options.merge(opts)
      uri     = make_request_uri(uri, opts)
      headers = make_request_headers(opts)
      body    = make_request_body(opts, headers)
      proxy   = opts.proxy

      req = HTTP::Request.new(verb, uri, headers, proxy, body)
      res = perform req, opts

      return res unless opts.follow

      Redirector.new(opts.follow).perform req, res do |request|
        perform request, opts
      end
    end

[Validate]

Generated with the Darkfish Rdoc Generator 2.