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.

Class Method Summary collapse

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=

Class Method Details

.hostObject

HTTP host



43
44
# File 'lib/ronin/network/mixins/http.rb', line 43

parameter :host, :type => String,
:description => 'HTTP host'

.host=(value) ⇒ Object

HTTP host



43
44
# File 'lib/ronin/network/mixins/http.rb', line 43

parameter :host, :type => String,
:description => 'HTTP host'

.http_passwordObject

HTTP password to authenticate with



59
60
# File 'lib/ronin/network/mixins/http.rb', line 59

parameter :http_password, :type => String,
:description => 'HTTP password to authenticate with'

.http_password=(value) ⇒ Object

HTTP password to authenticate with



59
60
# File 'lib/ronin/network/mixins/http.rb', line 59

parameter :http_password, :type => String,
:description => 'HTTP password to authenticate with'

.http_proxyObject

HTTP proxy information



63
# File 'lib/ronin/network/mixins/http.rb', line 63

parameter :http_proxy, :description => 'HTTP proxy information'

.http_proxy=(value) ⇒ Object

HTTP proxy information



63
# File 'lib/ronin/network/mixins/http.rb', line 63

parameter :http_proxy, :description => 'HTTP proxy information'

.http_userObject

HTTP user to authenticate as



55
56
# File 'lib/ronin/network/mixins/http.rb', line 55

parameter :http_user, :type => String,
:description => 'HTTP user to authenticate as'

.http_user=(value) ⇒ Object

HTTP user to authenticate as



55
56
# File 'lib/ronin/network/mixins/http.rb', line 55

parameter :http_user, :type => String,
:description => 'HTTP user to authenticate as'

.http_user_agentObject

HTTP User-Agent header to send



66
67
# File 'lib/ronin/network/mixins/http.rb', line 66

parameter :http_user_agent, :type => String,
:description => 'HTTP User-Agent header to send'

.http_user_agent=(value) ⇒ Object

HTTP User-Agent header to send



66
67
# File 'lib/ronin/network/mixins/http.rb', line 66

parameter :http_user_agent, :type => String,
:description => 'HTTP User-Agent header to send'

.http_vhostObject

HTTP Host header to send



51
52
# File 'lib/ronin/network/mixins/http.rb', line 51

parameter :http_vhost, :type => String,
:description => 'HTTP Host header to send'

.http_vhost=(value) ⇒ Object

HTTP Host header to send



51
52
# File 'lib/ronin/network/mixins/http.rb', line 51

parameter :http_vhost, :type => String,
:description => 'HTTP Host header to send'

.portObject

HTTP port



47
48
# File 'lib/ronin/network/mixins/http.rb', line 47

parameter :port, :default => Net::HTTP.default_port,
:description => 'HTTP port'

.port=(value) ⇒ Object

HTTP port



47
48
# File 'lib/ronin/network/mixins/http.rb', line 47

parameter :port, :default => Net::HTTP.default_port,
:description => 'HTTP port'

Instance Method Details

#disable_http_proxyObject (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

#hostObject

HTTP host



43
44
# File 'lib/ronin/network/mixins/http.rb', line 43

parameter :host, :type => String,
:description => 'HTTP host'

#host=(value) ⇒ Object

HTTP host



43
44
# File 'lib/ronin/network/mixins/http.rb', line 43

parameter :host, :type => String,
:description => 'HTTP host'

#http_connect(options = {}) {|http| ... } ⇒ Net::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

#http_passwordObject

HTTP password to authenticate with



59
60
# File 'lib/ronin/network/mixins/http.rb', line 59

parameter :http_password, :type => String,
:description => 'HTTP password to authenticate with'

#http_password=(value) ⇒ Object

HTTP password to authenticate with



59
60
# File 'lib/ronin/network/mixins/http.rb', line 59

parameter :http_password, :type => String,
:description => 'HTTP password to authenticate with'

#http_proxyObject

HTTP proxy information



63
# File 'lib/ronin/network/mixins/http.rb', line 63

parameter :http_proxy, :description => 'HTTP proxy information'

#http_proxy=(value) ⇒ Object

HTTP proxy information



63
# File 'lib/ronin/network/mixins/http.rb', line 63

parameter :http_proxy, :description => 'HTTP proxy information'

#http_request(options = {}) {|request, (options)| ... } ⇒ Net::HTTPResponse (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

#http_userObject

HTTP user to authenticate as



55
56
# File 'lib/ronin/network/mixins/http.rb', line 55

parameter :http_user, :type => String,
:description => 'HTTP user to authenticate as'

#http_user=(value) ⇒ Object

HTTP user to authenticate as



55
56
# File 'lib/ronin/network/mixins/http.rb', line 55

parameter :http_user, :type => String,
:description => 'HTTP user to authenticate as'

#http_user_agentObject

HTTP User-Agent header to send



66
67
# File 'lib/ronin/network/mixins/http.rb', line 66

parameter :http_user_agent, :type => String,
:description => 'HTTP User-Agent header to send'

#http_user_agent=(value) ⇒ Object

HTTP User-Agent header to send



66
67
# File 'lib/ronin/network/mixins/http.rb', line 66

parameter :http_user_agent, :type => String,
:description => 'HTTP User-Agent header to send'

#http_vhostObject

HTTP Host header to send



51
52
# File 'lib/ronin/network/mixins/http.rb', line 51

parameter :http_vhost, :type => String,
:description => 'HTTP Host header to send'

#http_vhost=(value) ⇒ Object

HTTP Host header to send



51
52
# File 'lib/ronin/network/mixins/http.rb', line 51

parameter :http_vhost, :type => String,
:description => 'HTTP Host header to send'

#portObject

HTTP port



47
48
# File 'lib/ronin/network/mixins/http.rb', line 47

parameter :port, :default => Net::HTTP.default_port,
:description => 'HTTP port'

#port=(value) ⇒ Object

HTTP port



47
48
# File 'lib/ronin/network/mixins/http.rb', line 47

parameter :port, :default => Net::HTTP.default_port,
:description => 'HTTP port'