Module: Ronin::Network::Mixins::HTTP

Includes:
Mixin, HTTP
Defined in:
lib/ronin/network/mixins/http.rb

Overview

Adds HTTP convenience methods and connection parameters to a class.

Defines the following parameters:

  • host (String) - HTTP host.
  • port (Integer) - HTTP port. Defaults to Net::HTTP.default_port.
  • http_vhost (String) - HTTP Host header to send.
  • http_user (String) - HTTP user to authenticate as.
  • http_password (String) - HTTP password to authenticate with.
  • http_proxy - HTTP proxy information.
  • http_user_agent (String) - HTTP User-Agent header to send.

Instance Method Summary (collapse)

Methods included from Mixin

included

Methods included from HTTP

expand_options, expand_url, header_name, headers, #http_copy, #http_delete, #http_get, #http_get_body, #http_get_headers, #http_head, #http_lock, #http_mkcol, #http_move, #http_ok?, #http_options, #http_post, #http_post_body, #http_post_headers, #http_powered_by, #http_prop_find, #http_prop_patch, #http_put, #http_server, #http_session, #http_status, #http_trace, #http_unlock, proxy, proxy=, request, user_agent, user_agent=

Instance Method Details

- (Object) disable_http_proxy (protected)

Resets the HTTP proxy settings.



76
77
78
# File 'lib/ronin/network/mixins/http.rb', line 76

def disable_http_proxy
  @http_proxy = nil
end

- (Net::HTTP) http_connect(options = {}) {|http| ... } (protected)

Starts a HTTP connection with the server.

Parameters:

  • options (Hash) (defaults to: {})

    Additional options

  • :ssl (Hash)

    a customizable set of options

Options Hash (options):

  • :url (String, URI::HTTP)

    The full URL to request.

  • :host (String)

    The host the HTTP server is running on.

  • :port (Integer) — default: Net::HTTP.default_port

    The port the HTTP server is listening on.

  • :proxy (String, Hash) — default: HTTP.proxy

    A Hash of proxy settings to use when connecting to the HTTP server.

  • :user (String)

    The user to authenticate with when connecting to the HTTP server.

  • :password (String)

    The password to authenticate with when connecting to the HTTP server.

  • :ssl (Boolean, Hash)

    Enables SSL for the HTTP connection.

Yields:

  • (http)

    If a block is given, it will be passed the newly created HTTP session object.

Yield Parameters:

  • http (Net::HTTP)

    The newly created HTTP session.

Returns:

  • (Net::HTTP)

    The HTTP session object.

See Also:

Since:

  • 0.5.0



127
128
129
# File 'lib/ronin/network/mixins/http.rb', line 127

def http_connect(options={},&block)
  super(http_merge_options(options),&block)
end

- (Net::HTTPResponse) http_request(options = {}) {|request, (options)| ... } (protected)

Connects to the HTTP server and sends an HTTP Request.

Parameters:

  • options (Hash) (defaults to: {})

    Additional options.

Options Hash (options):

  • :headers (Hash{String,Symbol => Object})

    The Hash of the HTTP headers to send with the request. May contain either Strings or Symbols, lower-case or camel-case keys.

Yields:

  • (request, (options))

    If a block is given, it will be passed the HTTP request object. If the block has an arity of 2, it will also be passed the expanded version of the given options.

Yield Parameters:

  • request (Net::HTTPRequest)

    The HTTP request object to use in the request.

  • options (Hash)

    The expanded version of the given options.

Returns:

  • (Net::HTTPResponse)

    The response of the HTTP request.

See Also:



160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
# File 'lib/ronin/network/mixins/http.rb', line 160

def http_request(options={},&block)
  response = super(options) do |request,expanded_options|
    if block
      if block.arity == 2
        block.call(request,expanded_options)
      else
        block.call(request)
      end
    end

    host = options.fetch(:host,self.host)
    port = options.fetch(:port,self.port)

    print_info "HTTP #{request.method} #{host}:#{port} #{request.path}"

    request.each_capitalized do |name,value|
      print_debug "  #{name}: #{value}"
    end
  end

  print_info "HTTP #{response.code} #{response.message}"

  response.each_capitalized do |name,value|
    print_debug "  #{name}: #{value}"
  end

  return response
end