module Ronin::Support::Network::HTTP::Mixin

Provides helper methods for communicating with HTTP Servers.

Public Instance Methods

http_allowed_methods(url, ssl: nil, **kwargs) click to toggle source

Performs a ‘OPTIONS` HTTP request for the given URI and parses the `Allow` response header.

@param [URI::HTTP, Addressable::URI, String] url

The URL to create the HTTP request for.

@!macro request_kwargs @!macro connect_kwargs

@return [Array<Symbol>]

The allowed HTTP request methods for the given URL.

@see Network::HTTP.allowed_methods

@api public

# File lib/ronin/support/network/http/mixin.rb, line 684
def http_allowed_methods(url, ssl: nil, **kwargs)
  Network::HTTP.allowed_methods(url, ssl: ssl, **kwargs)
end
http_connect(host,port, ssl: nil, **kwargs,&block) click to toggle source

Creates a HTTP connection to the host nad port.

@param [String] host

The host to connect to.

@param [Integer] port

The port to connect to.

@!macro connect_kwargs

@yield [http]

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

@yieldparam [HTTP] http

The HTTP session object.

@return [HTTP, nil]

The HTTP session object. If a block is given, then `nil` will be
returned.

@since 1.0.0

@api public

# File lib/ronin/support/network/http/mixin.rb, line 133
def http_connect(host,port, ssl: nil, **kwargs,&block)
  Network::HTTP.connect(host,port, ssl: ssl, **kwargs,&block)
end
http_connect_uri(url, ssl: nil, **kwargs,&block) click to toggle source

Creates a HTTP connection using the URI.

@param [URI::HTTP, Addressable::URI, String] url

The URI to connect to.

@!macro connect_kwargs

@yield [http]

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

@yieldparam [HTTP] http

The HTTP session object.

@return [HTTP, nil]

The HTTP session object. If a block is given, then `nil` will be
returned.

@since 1.0.0

@api public

# File lib/ronin/support/network/http/mixin.rb, line 161
def http_connect_uri(url, ssl: nil, **kwargs,&block)
  Network::HTTP.connect_uri(url, ssl: ssl, **kwargs,&block)
end
http_copy(url, ssl: nil, **kwargs,&block) click to toggle source

Performs a ‘COPY` request for the given URI.

@param [URI::HTTP, Addressable::URI, String] url

The URL to create the HTTP request for.

@!macro request_kwargs @!macro connect_kwargs

@yield [response]

If a block is given it will be passed the received HTTP response.

@yieldparam [Net::HTTPRresponse] response

The received HTTP response object.

@return [Net::HTTPResponse]

The new HTTP Request object.

@see Network::HTTP.copy

@api public

# File lib/ronin/support/network/http/mixin.rb, line 396
def http_copy(url, ssl: nil, **kwargs,&block)
  Network::HTTP.copy(url, ssl: ssl, **kwargs,&block)
end
http_delete(url, ssl: nil, **kwargs,&block) click to toggle source

Performs a ‘DELETE` request for the given URI.

@param [URI::HTTP, Addressable::URI, String] url

The URL to create the HTTP request for.

@!macro request_kwargs @!macro connect_kwargs

@yield [response]

If a block is given it will be passed the received HTTP response.

@yieldparam [Net::HTTPRresponse] response

The received HTTP response object.

@return [Net::HTTPResponse]

The new HTTP Request object.

@see Network::HTTP.delete

@api public

# File lib/ronin/support/network/http/mixin.rb, line 422
def http_delete(url, ssl: nil, **kwargs,&block)
  Network::HTTP.delete(url, ssl: ssl, **kwargs,&block)
end
http_get(url, ssl: nil, **kwargs,&block) click to toggle source

Performs a ‘GET` request for the given URI.

@param [URI::HTTP, Addressable::URI, String] url

The URL to create the HTTP request for.

@!macro request_kwargs @!macro connect_kwargs

@yield [response]

If a block is given it will be passed the received HTTP response.

@yieldparam [Net::HTTPRresponse] response

The received HTTP response object.

@return [Net::HTTPResponse]

The new HTTP Request object.

@see Network::HTTP.get

@api public

# File lib/ronin/support/network/http/mixin.rb, line 448
def http_get(url, ssl: nil, **kwargs,&block)
  Network::HTTP.get(url, ssl: ssl, **kwargs,&block)
end
http_get_body(url, ssl: nil, **kwargs) click to toggle source

Performs a ‘GET` request for the given URI and returns the response body.

@param [URI::HTTP, Addressable::URI, String] url

The URL to create the HTTP request for.

@!macro request_kwargs @!macro connect_kwargs

@return [String]

The response body.

@see Network::HTTP.get_body

@api public

# File lib/ronin/support/network/http/mixin.rb, line 533
def http_get_body(url, ssl: nil, **kwargs)
  Network::HTTP.get_body(url, ssl: ssl, **kwargs)
end
http_get_cookies(url, ssl: nil, **kwargs) click to toggle source

Sends an HTTP request and returns the parsed ‘Set-Cookie` header(s).

@param [URI::HTTP, Addressable::URI, String] url

The URL to create the HTTP request for.

@!macro request_kwargs @!macro connect_kwargs

@return [Array<SetCookie>, nil]

The parsed `SetCookie` header(s).

@see Network::HTTP.get_cookies

@api public

# File lib/ronin/support/network/http/mixin.rb, line 492
def http_get_cookies(url, ssl: nil, **kwargs)
  Network::HTTP.get_cookies(url, ssl: ssl, **kwargs)
end
http_get_headers(url, ssl: nil, **kwargs) click to toggle source

Performs a ‘GET` request for the given URI and returns the response headers.

@param [URI::HTTP, Addressable::URI, String] url

The URL to create the HTTP request for.

@!macro request_kwargs @!macro connect_kwargs

@return [Hash{String => String}]

The response headers.

@see Network::HTTP.get_headers

@since 0.2.0

@api public

# File lib/ronin/support/network/http/mixin.rb, line 471
def http_get_headers(url, ssl: nil, **kwargs)
  Network::HTTP.get_headers(url, ssl: ssl, **kwargs)
end
http_head(url, ssl: nil, **kwargs,&block) click to toggle source

Performs a ‘HEAD` request for the given URI.

@param [URI::HTTP, Addressable::URI, String] url

The URL to create the HTTP request for.

@!macro request_kwargs @!macro connect_kwargs

@yield [response]

If a block is given it will be passed the received HTTP response.

@yieldparam [Net::HTTPRresponse] response

The received HTTP response object.

@return [Net::HTTPResponse]

The new HTTP Request object.

@see Network::HTTP.head

@api public

# File lib/ronin/support/network/http/mixin.rb, line 559
def http_head(url, ssl: nil, **kwargs,&block)
  Network::HTTP.head(url, ssl: ssl, **kwargs,&block)
end
http_lock(url, ssl: nil, **kwargs,&block) click to toggle source

Performs a ‘LOCK` request for the given URI.

@param [URI::HTTP, Addressable::URI, String] url

The URL to create the HTTP request for.

@!macro request_kwargs @!macro connect_kwargs

@yield [response]

If a block is given it will be passed the received HTTP response.

@yieldparam [Net::HTTPRresponse] response

The received HTTP response object.

@return [Net::HTTPResponse]

The new HTTP Request object.

@see Network::HTTP.lock

@api public

# File lib/ronin/support/network/http/mixin.rb, line 585
def http_lock(url, ssl: nil, **kwargs,&block)
  Network::HTTP.lock(url, ssl: ssl, **kwargs,&block)
end
http_mkcol(url, ssl: nil, **kwargs,&block) click to toggle source

Performs a ‘MKCOL` request for the given URI.

@param [URI::HTTP, Addressable::URI, String] url

The URL to create the HTTP request for.

@!macro request_kwargs @!macro connect_kwargs

@yield [response]

If a block is given it will be passed the received HTTP response.

@yieldparam [Net::HTTPRresponse] response

The received HTTP response object.

@return [Net::HTTPResponse]

The new HTTP Request object.

@see Network::HTTP.mkcol

@api public

# File lib/ronin/support/network/http/mixin.rb, line 611
def http_mkcol(url, ssl: nil, **kwargs,&block)
  Network::HTTP.mkcol(url, ssl: ssl, **kwargs,&block)
end
http_move(url, ssl: nil, **kwargs,&block) click to toggle source

Performs a ‘MOVE` request for the given URI.

@param [URI::HTTP, Addressable::URI, String] url

The URL to create the HTTP request for.

@!macro request_kwargs @!macro connect_kwargs

@yield [response]

If a block is given it will be passed the received HTTP response.

@yieldparam [Net::HTTPRresponse] response

The received HTTP response object.

@return [Net::HTTPResponse]

The new HTTP Request object.

@see Network::HTTP.move

@api public

# File lib/ronin/support/network/http/mixin.rb, line 637
def http_move(url, ssl: nil, **kwargs,&block)
  Network::HTTP.move(url, ssl: ssl, **kwargs,&block)
end
http_ok?(method=:head,url, ssl: nil, **kwargs) click to toggle source

Sends a HTTP request and determines if the response status was 200.

@param [Symbol, String] method

The HTTP method to use for the request.

@param [URI::HTTP, Addressable::URI, String] url

The URL to create the HTTP request for.

@!macro request_kwargs @!macro connect_kwargs

@return [Boolean]

Indicates that the response status was 200.

@see Network::HTTP.ok?

@api public

# File lib/ronin/support/network/http/mixin.rb, line 276
def http_ok?(method=:head,url, ssl: nil, **kwargs)
  Network::HTTP.ok?(method,url, ssl: ssl, **kwargs)
end
http_options(url, ssl: nil, **kwargs,&block) click to toggle source

Performs a ‘OPTIONS` request for the given URI.

@param [URI::HTTP, Addressable::URI, String] url

The URL to create the HTTP request for.

@!macro request_kwargs @!macro connect_kwargs

@yield [response]

If a block is given it will be passed the received HTTP response.

@yieldparam [Net::HTTPRresponse] response

The received HTTP response object.

@return [Net::HTTPResponse]

The new HTTP Request object.

@see Network::HTTP.options

@api public

# File lib/ronin/support/network/http/mixin.rb, line 663
def http_options(url, ssl: nil, **kwargs,&block)
  Network::HTTP.options(url, ssl: ssl, **kwargs,&block)
end
http_patch(url, ssl: nil, **kwargs,&block) click to toggle source

Performs a ‘PATCH` request for the given URI.

@param [URI::HTTP, Addressable::URI, String] url

The URL to create the HTTP request for.

@!macro request_kwargs @!macro connect_kwargs

@yield [response]

If a block is given it will be passed the received HTTP response.

@yieldparam [Net::HTTPRresponse] response

The received HTTP response object.

@return [Net::HTTPResponse]

The new HTTP Request object.

@see Network::HTTP.patch

@since 1.0.0

@api public

# File lib/ronin/support/network/http/mixin.rb, line 712
def http_patch(url, ssl: nil, **kwargs,&block)
  Network::HTTP.patch(url, ssl: ssl, **kwargs,&block)
end
http_post(url, ssl: nil, **kwargs,&block) click to toggle source

Performs a ‘POST` request for the given URI.

@param [URI::HTTP, Addressable::URI, String] url

The URL to create the HTTP request for.

@!macro request_kwargs @!macro connect_kwargs

@yield [response]

If a block is given it will be passed the received HTTP response.

@yieldparam [Net::HTTPRresponse] response

The received HTTP response object.

@return [Net::HTTPResponse]

The new HTTP Request object.

@see Network::HTTP.post

@api public

# File lib/ronin/support/network/http/mixin.rb, line 738
def http_post(url, ssl: nil, **kwargs,&block)
  Network::HTTP.post(url, ssl: ssl, **kwargs,&block)
end
http_post_body(url, ssl: nil, **kwargs) click to toggle source

Performs a ‘POST` request for the given URI and returns the response body.

@param [URI::HTTP, Addressable::URI, String] url

The URL to create the HTTP request for.

@!macro request_kwargs @!macro connect_kwargs

@return [String]

The response body.

@see Network::HTTP.post_body

@api public

# File lib/ronin/support/network/http/mixin.rb, line 782
def http_post_body(url, ssl: nil, **kwargs)
  Network::HTTP.post_body(url, ssl: ssl, **kwargs)
end
http_post_cookies(url, ssl: nil, **kwargs) click to toggle source

Sends an HTTP request and returns the parsed ‘Set-Cookie` header(s).

@param [URI::HTTP, Addressable::URI, String] url

Optional URL to create the HTTP request for.

@!macro request_kwargs @!macro connect_kwargs

@return [Array<SetCookie>, nil]

The parsed `Cookie` header(s).

@see Network::HTTP.post_cookies

@api public

# File lib/ronin/support/network/http/mixin.rb, line 512
def http_post_cookies(url, ssl: nil, **kwargs)
  Network::HTTP.post_cookies(url, ssl: ssl, **kwargs)
end
http_post_headers(url, ssl: nil, **kwargs) click to toggle source

Performs a ‘POST` request on the given URI and returns the response headers.

@param [URI::HTTP, Addressable::URI, String] url

The URL to create the HTTP request for.

@!macro request_kwargs @!macro connect_kwargs

@return [Hash{String => String}]

The response headers.

@see Network::HTTP.post_headers

@since 0.2.0

@api public

# File lib/ronin/support/network/http/mixin.rb, line 761
def http_post_headers(url, ssl: nil, **kwargs)
  Network::HTTP.post_headers(url, ssl: ssl, **kwargs)
end
http_powered_by_header(url, ssl: nil, **kwargs) click to toggle source

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

@param [URI::HTTP, Addressable::URI, String] url

The URL to create the HTTP request for.

@!macro request_kwargs @!macro connect_kwargs

@return [String, nil]

The `X-Powered-By` header.

@see Network::HTTP.powered_by_header

@since 1.0.0

@api public

# File lib/ronin/support/network/http/mixin.rb, line 345
def http_powered_by_header(url, ssl: nil, **kwargs)
  Network::HTTP.powered_by_header(url, ssl: ssl, **kwargs)
end
http_prop_find(url, ssl: nil, **kwargs,&block)
Alias for: http_propfind
http_prop_patch(url, ssl: nil, **kwargs,&block)
Alias for: http_proppatch
http_propfind(url, ssl: nil, **kwargs,&block) click to toggle source

Performs a ‘PROPFIND` request for the given URI.

@param [URI::HTTP, Addressable::URI, String] url

The URL to create the HTTP request for.

@!macro request_kwargs @!macro connect_kwargs

@yield [response]

If a block is given it will be passed the received HTTP response.

@yieldparam [Net::HTTPRresponse] response

The received HTTP response object.

@return [Net::HTTPResponse]

The new HTTP Request object.

@see Network::HTTP.propfind

@api public

# File lib/ronin/support/network/http/mixin.rb, line 808
def http_propfind(url, ssl: nil, **kwargs,&block)
  Network::HTTP.propfind(url, ssl: ssl, **kwargs,&block)
end
Also aliased as: http_prop_find
http_proppatch(url, ssl: nil, **kwargs,&block) click to toggle source

Performs a ‘PROPPATCH` request for the given URI.

@param [URI::HTTP, Addressable::URI, String] url

The URL to create the HTTP request for.

@!macro request_kwargs @!macro connect_kwargs

@yield [response]

If a block is given it will be passed the received HTTP response.

@yieldparam [Net::HTTPRresponse] response

The received HTTP response object.

@return [Net::HTTPResponse]

The new HTTP Request object.

@see Network::HTTP.proppatch

@api public

# File lib/ronin/support/network/http/mixin.rb, line 836
def http_proppatch(url, ssl: nil, **kwargs,&block)
  Network::HTTP.proppatch(url, ssl: ssl, **kwargs,&block)
end
Also aliased as: http_prop_patch
http_put(url, ssl: nil, **kwargs,&block) click to toggle source

Performs a ‘PUT` request for the given URI.

@param [URI::HTTP, Addressable::URI, String] url

The URL to create the HTTP request for.

@!macro request_kwargs @!macro connect_kwargs

@yield [response]

If a block is given it will be passed the received HTTP response.

@yieldparam [Net::HTTPRresponse] response

The received HTTP response object.

@return [Net::HTTPResponse]

The new HTTP Request object.

@see Network::HTTP.put

@since 0.4.0

@api public

# File lib/ronin/support/network/http/mixin.rb, line 866
def http_put(url, ssl: nil, **kwargs,&block)
  Network::HTTP.put(url, ssl: ssl, **kwargs,&block)
end
http_request(method,url, ssl: nil, **kwargs,&block) click to toggle source

Performs and arbitrary HTTP request.

@param [Symbol, String] method

The HTTP method to use for the request.

@param [URI::HTTP, Addressable::URI, String] url

The URL to create the HTTP request for.

@!macro request_kwargs @!macro connect_kwargs

@yield [response]

If a block is given it will be passed the received HTTP response.

@yieldparam [Net::HTTPRresponse] response

The received HTTP response object.

@return [Net::HTTPResponse]

The new HTTP Request object.

@raise [ArgumentError]

The `:method` option did not match a known `Net::HTTP` request
class.

@see Network::HTTP.request

@api public

# File lib/ronin/support/network/http/mixin.rb, line 228
def http_request(method,url, ssl: nil, **kwargs,&block)
  Network::HTTP.request(method,url, ssl: ssl, **kwargs,&block)
end
http_response_body(method=:get,url, ssl: nil, **kwargs) click to toggle source

Sends an arbitrary HTTP request and returns the response body.

@param [Symbol, String] method

The HTTP method to use for the request.

@param [URI::HTTP, Addressable::URI, String] url

The URL to create the HTTP request for.

@!macro request_kwargs @!macro connect_kwargs

@return [String]

The response body.

@see Network::HTTP.response_body

@since 1.0.0

@api public

# File lib/ronin/support/network/http/mixin.rb, line 370
def http_response_body(method=:get,url, ssl: nil, **kwargs)
  Network::HTTP.response_body(method,url, ssl: ssl, **kwargs)
end
http_response_headers(method=:head,url, ssl: nil, **kwargs) click to toggle source

Sends an arbitrary HTTP request and returns the response headers.

@param [Symbol, String] method

The HTTP method to use for the request.

@param [URI::HTTP, Addressable::URI, String] url

The URL to create the HTTP request for.

@!macro request_kwargs @!macro connect_kwargs

@return [Hash{String => String}]

The response headers.

@see Network::HTTP.response_headers

@since 1.0.0

@api public

# File lib/ronin/support/network/http/mixin.rb, line 301
def http_response_headers(method=:head,url, ssl: nil, **kwargs)
  Network::HTTP.response_headers(method,url, ssl: ssl, **kwargs)
end
http_response_status(method=:head,url, ssl: nil, **kwargs) click to toggle source

Sends an arbitrary HTTP request and returns the response status.

@param [Symbol, String] method

The HTTP method to use for the request.

@param [URI::HTTP, Addressable::URI, String] url

The URL to create the HTTP request for.

@!macro request_kwargs @!macro connect_kwargs

@return [Integer]

The status code of the response.

@see Network::HTTP.response_status

@since 1.0.0

@api public

# File lib/ronin/support/network/http/mixin.rb, line 253
def http_response_status(method=:head,url, ssl: nil, **kwargs)
  Network::HTTP.response_status(method,url, ssl: ssl, **kwargs)
end
http_server_header(url, ssl: nil, **kwargs) click to toggle source

Sends an HTTP request and returns the ‘Server` header.

@param [URI::HTTP, Addressable::URI, String] url

The URL to create the HTTP request for.

@!macro connect_kwargs @!macro request_kwargs

@return [String, nil]

The `Server` header.

@see Network::HTTP.server_header

@since 1.0.0

@api public

# File lib/ronin/support/network/http/mixin.rb, line 323
def http_server_header(url, ssl: nil, **kwargs)
  Network::HTTP.server_header(url, ssl: ssl, **kwargs)
end
http_trace(url, ssl: nil, **kwargs,&block) click to toggle source

Performs a ‘TRACE` request for the given URI.

@param [URI::HTTP, Addressable::URI, String] url

The URL to create the HTTP request for.

@!macro request_kwargs @!macro connect_kwargs

@yield [response]

If a block is given it will be passed the received HTTP response.

@yieldparam [Net::HTTPRresponse] response

The received HTTP response object.

@return [Net::HTTPResponse]

The new HTTP Request object.

@see Network::HTTP.trace

@api public

# File lib/ronin/support/network/http/mixin.rb, line 892
def http_trace(url, ssl: nil, **kwargs,&block)
  Network::HTTP.trace(url, ssl: ssl, **kwargs,&block)
end
http_unlock(url, ssl: nil, **kwargs,&block) click to toggle source

Performs a ‘UNLOCK` request for the given URI.

@param [URI::HTTP, Addressable::URI, String] url

The URL to create the HTTP request for.

@!macro request_kwargs @!macro connect_kwargs

@yield [response]

If a block is given it will be passed the received HTTP response.

@yieldparam [Net::HTTPRresponse] response

The received HTTP response object.

@return [Net::HTTPResponse]

The new HTTP Request object.

@see Network::HTTP.unlock

@api public

# File lib/ronin/support/network/http/mixin.rb, line 918
def http_unlock(url, ssl: nil, **kwargs,&block)
  Network::HTTP.unlock(url, ssl: ssl, **kwargs,&block)
end