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

Includes:
Mixin
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

Instance Method Details

#disable_http_proxyObject (protected)

Resets the HTTP proxy settings.



83
84
85
# File 'lib/ronin/network/mixins/http.rb', line 83

def disable_http_proxy
  @http_proxy = nil
end

#http_copy(options = {}) {|response| ... } ⇒ Net::HTTP::Response (protected)

Performs an HTTP Copy request.

Yields:

  • (response)

    If a block is given, it will be passed the response received from the request.

Yield Parameters:

  • response (Net::HTTP::Response)

    The HTTP response object.

Returns:

  • (Net::HTTP::Response)

    The response of the HTTP request.

See Also:



303
304
305
306
307
308
# File 'lib/ronin/network/mixins/http.rb', line 303

def http_copy(options={},&block)
  options = http_merge_options(options)
  print_info "HTTP COPY #{http_options_to_s(options)}"

  return Net.http_copy(options,&block)
end

#http_delete(options = {}) {|response| ... } ⇒ Net::HTTP::Response (protected)

Performs an HTTP Delete request.

Yields:

  • (response)

    If a block is given, it will be passed the response received from the request.

Yield Parameters:

  • response (Net::HTTP::Response)

    The HTTP response object.

Returns:

  • (Net::HTTP::Response)

    The response of the HTTP request.

See Also:



327
328
329
330
331
332
# File 'lib/ronin/network/mixins/http.rb', line 327

def http_delete(options={},&block)
  options = http_merge_options(options)
  print_info "HTTP DELETE #{http_options_to_s(options)}"

  return Net.http_delete(options,&block)
end

#http_get(options = {}) {|response| ... } ⇒ Net::HTTP::Response (protected)

Performs an HTTP Get request.

Yields:

  • (response)

    If a block is given, it will be passed the response received from the request.

Yield Parameters:

  • response (Net::HTTP::Response)

    The HTTP response object.

Returns:

  • (Net::HTTP::Response)

    The response of the HTTP request.

See Also:



351
352
353
354
355
356
# File 'lib/ronin/network/mixins/http.rb', line 351

def http_get(options={},&block)
  options = http_merge_options(options)
  print_info "HTTP GET #{http_options_to_s(options)}"

  return Net.http_get(options,&block)
end

#http_get_body(options = {}) {|response| ... } ⇒ String (protected)

Performs an HTTP Get request.

Yields:

  • (response)

    If a block is given, it will be passed the response received from the request.

Yield Parameters:

  • response (Net::HTTP::Response)

    The HTTP response object.

Returns:

  • (String)

    The body of the HTTP Get request.

See Also:



375
376
377
378
379
380
# File 'lib/ronin/network/mixins/http.rb', line 375

def http_get_body(options={},&block)
  options = http_merge_options(options)
  print_info "HTTP GET #{http_options_to_s(options)}"

  return Net.http_get_body(options,&block)
end

#http_head(options = {}) {|response| ... } ⇒ Net::HTTP::Response (protected)

Performs an HTTP Head request.

Yields:

  • (response)

    If a block is given, it will be passed the response received from the request.

Yield Parameters:

  • response (Net::HTTP::Response)

    The HTTP response object.

Returns:

  • (Net::HTTP::Response)

    The response of the HTTP request.

See Also:



399
400
401
402
403
404
# File 'lib/ronin/network/mixins/http.rb', line 399

def http_head(options={},&block)
  options = http_merge_options(options)
  print_info "HTTP HEAD #{http_options_to_s(options)}"

  return Net.http_head(options,&block)
end

#http_lock(options = {}) {|response| ... } ⇒ Net::HTTP::Response (protected)

Performs an HTTP Lock request.

Yields:

  • (response)

    If a block is given, it will be passed the response received from the request.

Yield Parameters:

  • response (Net::HTTP::Response)

    The HTTP response object.

Returns:

  • (Net::HTTP::Response)

    The response of the HTTP request.

See Also:



423
424
425
426
427
428
# File 'lib/ronin/network/mixins/http.rb', line 423

def http_lock(options={},&block)
  options = http_merge_options(options)
  print_info "HTTP LOCK #{http_options_to_s(options)}"

  return Net.http_lock(options,&block)
end

#http_mkcol(options = {}) {|response| ... } ⇒ Net::HTTP::Response (protected)

Performs an HTTP Mkcol request.

Yields:

  • (response)

    If a block is given, it will be passed the response received from the request.

Yield Parameters:

  • response (Net::HTTP::Response)

    The HTTP response object.

Returns:

  • (Net::HTTP::Response)

    The response of the HTTP request.

See Also:



447
448
449
450
451
452
# File 'lib/ronin/network/mixins/http.rb', line 447

def http_mkcol(options={},&block)
  options = http_merge_options(options)
  print_info "HTTP MKCOL #{http_options_to_s(options)}"

  return Net.http_mkcol(options,&block)
end

#http_move(options = {}) {|response| ... } ⇒ Net::HTTP::Response (protected)

Performs an HTTP Move request.

Yields:

  • (response)

    If a block is given, it will be passed the response received from the request.

Yield Parameters:

  • response (Net::HTTP::Response)

    The HTTP response object.

Returns:

  • (Net::HTTP::Response)

    The response of the HTTP request.

See Also:



471
472
473
474
475
476
# File 'lib/ronin/network/mixins/http.rb', line 471

def http_move(options={},&block)
  options = http_merge_options(options)
  print_info "HTTP MOVE #{http_options_to_s(options)}"

  return Net.http_move(options,&block)
end

#http_ok?(options = {}) ⇒ Boolean (protected)

Checks if the response has an HTTP OK status code.

Parameters:

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

    Additional options.

Options Hash (options):

  • :method (Symbol, String) — default: :head

    The method to use for the request.

Returns:

  • (Boolean)

    Specifies whether the response had an HTTP OK status code or not.

See Also:

Since:

  • 1.1.0



220
221
222
223
224
225
226
227
228
# File 'lib/ronin/network/mixins/http.rb', line 220

def http_ok?(options={})
  options = http_merge_options(options)

  if (result = Net.http_ok?(options))
    print_debug "HTTP 200 OK #{http_options_to_s(options)}"
  end

  return result
end

#http_options(options = {}) {|response| ... } ⇒ Net::HTTP::Response (protected)

Performs an HTTP Options request.

Yields:

  • (response)

    If a block is given, it will be passed the response received from the request.

Yield Parameters:

  • response (Net::HTTP::Response)

    The HTTP response object.

Returns:

  • (Net::HTTP::Response)

    The response of the HTTP request.

See Also:



495
496
497
498
499
500
# File 'lib/ronin/network/mixins/http.rb', line 495

def http_options(options={},&block)
  options = http_merge_options(options)
  print_info "HTTP OPTIONS #{http_options_to_s(options)}"

  return Net.http_options(options,&block)
end

#http_post(options = {}) {|response| ... } ⇒ Net::HTTP::Response (protected)

Performs an HTTP Post request.

Parameters:

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

    Additional options.

Options Hash (options):

  • :post_data (String)

    The POSTDATA to send with the HTTP Post request.

Yields:

  • (response)

    If a block is given, it will be passed the response received from the request.

Yield Parameters:

  • response (Net::HTTP::Response)

    The HTTP response object.

Returns:

  • (Net::HTTP::Response)

    The response of the HTTP request.

See Also:



525
526
527
528
529
530
# File 'lib/ronin/network/mixins/http.rb', line 525

def http_post(options={},&block)
  options = http_merge_options(options)
  print_info "HTTP POST #{http_options_to_s(options)}"

  return Net.http_post(options,&block)
end

#http_post_body(options = {}) {|response| ... } ⇒ String (protected)

Performs an HTTP Post request.

Yields:

  • (response)

    If a block is given, it will be passed the response received from the request.

Yield Parameters:

  • response (Net::HTTP::Response)

    The HTTP response object.

Returns:

  • (String)

    The body of the Post request.

See Also:



549
550
551
552
553
554
# File 'lib/ronin/network/mixins/http.rb', line 549

def http_post_body(options={},&block)
  options = http_merge_options(options)
  print_info "HTTP POST #{http_options_to_s(options)}"

  return Net.http_post_body(options,&block)
end

#http_powered_by(options = {}) ⇒ String (protected)

Sends an HTTP Head request and returns the HTTP X-Powered-By header.

Parameters:

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

    Additional options.

Options Hash (options):

  • :method (Symbol, String) — default: :get

    The method to use for the request.

Returns:

  • (String)

    The HTTP X-Powered-By header.

See Also:

Since:

  • 1.1.0



276
277
278
279
280
281
282
283
284
# File 'lib/ronin/network/mixins/http.rb', line 276

def http_powered_by(options={})
  options = http_merge_options(options)

  if (result = Net.http_powered_by(options))
    print_debug "HTTP X-Powered-By: #{result}"
  end

  return result
end

#http_prop_find(options = {}) {|response| ... } ⇒ Net::HTTP::Response (protected)

Performs an HTTP Propfind request.

Yields:

  • (response)

    If a block is given, it will be passed the response received from the request.

Yield Parameters:

  • response (Net::HTTP::Response)

    The HTTP response object.

Returns:

  • (Net::HTTP::Response)

    The response of the HTTP request.

See Also:



573
574
575
576
577
578
# File 'lib/ronin/network/mixins/http.rb', line 573

def http_prop_find(options={},&block)
  options = http_merge_options(options)
  print_info "HTTP PROPFIND #{http_options_to_s(options)}"

  return Net.http_prop_find(options,&block)
end

#http_prop_patch(options = {}) {|response| ... } ⇒ Net::HTTP::Response (protected)

Performs an HTTP Proppatch request.

Yields:

  • (response)

    If a block is given, it will be passed the response received from the request.

Yield Parameters:

  • response (Net::HTTP::Response)

    The HTTP response object.

Returns:

  • (Net::HTTP::Response)

    The response of the HTTP request.

See Also:



597
598
599
600
601
602
# File 'lib/ronin/network/mixins/http.rb', line 597

def http_prop_patch(options={},&block)
  options = http_merge_options(options)
  print_info "HTTP PROPPATCH #{http_options_to_s(options)}"

  return Net.http_prop_patch(options,&block)
end

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

    The HTTP request object to use in the request.

  • options (Hash)

    The expanded version of the given options.

Returns:

  • (Net::HTTP::Response)

    The response of the HTTP request.

See Also:



167
168
169
170
171
172
# File 'lib/ronin/network/mixins/http.rb', line 167

def http_request(options={},&block)
  options = http_merge_options(options)
  print_info "HTTP #{options[:method]} #{http_options_to_s(options)}"

  return Net.http_request(options,&block)
end

#http_server(options = {}) ⇒ String (protected)

Sends a HTTP Head request and returns the HTTP Server header.

Parameters:

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

    Additional options.

Options Hash (options):

  • :method (Symbol, String) — default: :head

    The method to use for the request.

Returns:

  • (String)

    The HTTP Server header.

See Also:

Since:

  • 1.1.0



248
249
250
251
252
253
254
255
256
# File 'lib/ronin/network/mixins/http.rb', line 248

def http_server(options={})
  options = http_merge_options(options)

  if (result = Net.http_server(options))
    print_debug "HTTP Server: #{result}"
  end

  return result
end

#http_session(options = {}) {|session| ... } ⇒ Net::HTTP (protected)

Connects to the HTTP server.

Parameters:

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

    Additional options

Options Hash (options):

  • :url (String, URI::HTTP)

    The full URL to request.

  • :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.

  • :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.

  • :path (String)

    The path to request from the HTTP server.

Yields:

  • (session)

    If a block is given, it will be passes the new HTTP session object.

Yield Parameters:

  • session (Net::HTTP)

    The newly created HTTP session.

Returns:

  • (Net::HTTP)

    The HTTP session object.



125
126
127
128
129
130
131
132
133
134
135
136
# File 'lib/ronin/network/mixins/http.rb', line 125

def http_session(options={})
  options = http_merge_options(options)
  host_port = "#{options[:host]}:#{options[:port]}"

  Net.http_session(options) do |http|
    print_info "Starting HTTP Session with #{host_port}"

    yield http

    print_info "Closing HTTP Session with #{host_port}"
  end
end

#http_status(options = {}) ⇒ Integer (protected)

Returns the Status Code of the Response.

Parameters:

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

    Additional options.

Options Hash (options):

  • :method (Symbol, String) — default: :head

    The method to use for the request.

Returns:

  • (Integer)

    The HTTP Response Status.

See Also:

Since:

  • 1.1.0



192
193
194
195
196
197
198
199
200
# File 'lib/ronin/network/mixins/http.rb', line 192

def http_status(options={})
  options = http_merge_options(options)

  if (result = Net.http_status(options))
    print_debug "HTTP #{result} #{http_options_to_s(options)}"
  end

  return result
end

#http_trace(options = {}) {|response| ... } ⇒ Net::HTTP::Response (protected)

Performs an HTTP Trace request.

Yields:

  • (response)

    If a block is given, it will be passed the response received from the request.

Yield Parameters:

  • response (Net::HTTP::Response)

    The HTTP response object.

Returns:

  • (Net::HTTP::Response)

    The response of the HTTP request.

See Also:



621
622
623
624
625
626
# File 'lib/ronin/network/mixins/http.rb', line 621

def http_trace(options={},&block)
  options = http_merge_options(options)
  print_info "HTTP TRACE #{http_options_to_s(options)}"

  return Net.http_trace(options,&block)
end

#http_unlock(options = {}) {|response| ... } ⇒ Net::HTTP::Response (protected)

Performs an HTTP Unlock request.

Yields:

  • (response)

    If a block is given, it will be passed the response received from the request.

Yield Parameters:

  • response (Net::HTTP::Response)

    The HTTP response object.

Returns:

  • (Net::HTTP::Response)

    The response of the HTTP request.

See Also:



645
646
647
648
649
650
# File 'lib/ronin/network/mixins/http.rb', line 645

def http_unlock(options={},&block)
  options = http_merge_options(options)
  print_info "HTTP UNLOCK #{http_options_to_s(options)}"

  return Net.http_unlock(options,&block)
end