Class: HTTP::Options

### Home Classes Methods

### In Files

- lib/http/options.rb

### Parent

Object

### Methods

- ::new
- ::new
- #[]
- #dup
- #merge
- #to_hash
- #with_headers

### Class/Module Index

Quicksearch

- HTTP
- HTTP::Chainable
- HTTP::Client
- HTTP::Error
- HTTP::Headers
- HTTP::Headers::Mixin
- HTTP::MimeType
- HTTP::MimeType::Adapter
- HTTP::MimeType::JSON
- HTTP::Options
- HTTP::Redirector
- HTTP::Redirector::EndlessRedirectError
- HTTP::Redirector::TooManyRedirectsError
- HTTP::Request
- HTTP::Request::UnsupportedMethodError
- HTTP::Request::UnsupportedSchemeError
- HTTP::Request::Writer
- HTTP::RequestError
- HTTP::Response
- HTTP::Response::Body
- HTTP::Response::Parser
- HTTP::Response::Status
- HTTP::ResponseError
- HTTP::StateError
- Object

No matching classes.

# HTTP::Options

### Attributes

default_socket_class[RW]
default_ssl_socket_class[RW]
body[RW]

Explicit request body of the request

follow[RW]

Follow redirects

form[RW]

Form data to embed in the request

headers[RW]

HTTP headers to include in the request

json[RW]

JSON data to embed in the request

params[RW]

Query string params to add to the url

proxy[RW]

HTTP proxy to route request

response[RW]

How to format the response [:object, :body, :parse_body]

socket_class[RW]

Socket classes

ssl_context[RW]

SSL context

ssl_socket_class[RW]

Socket classes

### Public Class Methods

new(options = {}) click to toggle source

    # File lib/http/options.rb, line 45
    def new(options = {})
      return options if options.is_a?(self)
      super
    end

new(options = {}) click to toggle source

    # File lib/http/options.rb, line 51
    def initialize(options = {})
      @response  = options[:response]  || :auto
      @proxy     = options[:proxy]     || {}
      @body      = options[:body]
      @params    = options[:params]
      @form      = options[:form]
      @json      = options[:json]
      @follow    = options[:follow]

      @headers   = HTTP::Headers.coerce(options[:headers] || {})

      @socket_class     = options[:socket_class]     || self.class.default_socket_class
      @ssl_socket_class = options[:ssl_socket_class] || self.class.default_ssl_socket_class
      @ssl_context      = options[:ssl_context]
    end

### Public Instance Methods

[](option) click to toggle source

    # File lib/http/options.rb, line 81
    def [](option)
      send(option) rescue nil
    end

dup() click to toggle source

    # File lib/http/options.rb, line 118
    def dup
      dupped = super
      yield(dupped) if block_given?
      dupped
    end

merge(other) click to toggle source

    # File lib/http/options.rb, line 85
    def merge(other)
      h1, h2 = to_hash, other.to_hash
      merged = h1.merge(h2) do |k, v1, v2|
        case k
        when :headers
          v1.merge(v2)
        else
          v2
        end
      end

      self.class.new(merged)
    end

to_hash() click to toggle source

    # File lib/http/options.rb, line 99
    def to_hash
      # FIXME: hardcoding these fields blows! We should have a declarative
      # way of specifying all the options fields, and ensure they *all*
      # get serialized here, rather than manually having to add them each time
      {
        :response         => response,
        :headers          => headers.to_h,
        :proxy            => proxy,
        :params           => params,
        :form             => form,
        :json             => json,
        :body             => body,
        :follow           => follow,
        :socket_class     => socket_class,
        :ssl_socket_class => ssl_socket_class,
        :ssl_context      => ssl_context
      }
    end

with_headers(headers) click to toggle source

    # File lib/http/options.rb, line 67
    def with_headers(headers)
      dup do |opts|
        opts.headers = self.headers.merge(headers)
      end
    end

[Validate]

Generated with the Darkfish Rdoc Generator 2.