Class: Ronin::Support::Network::HTTP

Inherits:
Object
  • Object
show all
Defined in:
lib/ronin/support/network/http.rb,
lib/ronin/support/network/http/mixin.rb,
lib/ronin/support/network/http/cookie.rb,
lib/ronin/support/network/http/request.rb,
lib/ronin/support/network/http/set_cookie.rb,
lib/ronin/support/network/http/user_agents.rb

Overview

Provides helper methods for communicating with HTTP Servers.

Core-Ext Methods

Defined Under Namespace

Modules: Mixin, Request, UserAgents Classes: Cookie, SetCookie

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(host, port, proxy: nil, ssl: port == 443, headers: {}, user_agent: self.class.user_agent, cookie: nil, user: nil, password: nil) {|_self| ... } ⇒ HTTP

Initializes an HTTP connection.

Parameters:

  • host (String)

    The host to connect to.

  • port (Integer)

    The port to connect tto.

  • proxy (String, URI::HTTP, Addressable::URI, nil) (defaults to: nil)

    Optional proxy to use for the request.

  • headers (Hash{Symbol,String => String,Array}, nil) (defaults to: {})

    Additional headers to add to each request.

  • user_agent (String, :random, :chrome, :chrome_linux, :chrome_macos, :chrome_windows, :chrome_iphone, :chrome_ipad, :chrome_android, :firefox, :firefox_linux, :firefox_macos, :firefox_windows, :firefox_iphone, :firefox_ipad, :firefox_android, :safari, :safari_macos, :safari_iphone, :safari_ipad, :edge, :linux, :macos, :windows, :iphone, :ipad, :android, nil) (defaults to: self.class.user_agent)

    The default User-Agent value to add to each request.

  • cookie (Cookie, Hash, String, nil) (defaults to: nil)

    The default cookie params to add to each request.

  • user (String, nil) (defaults to: nil)

    The HTTP Basic-Auth user to add to each request.

  • password (String, nil) (defaults to: nil)

    The HTTP Basic-Auth password to add to each request.

  • ssl (Boolean, Hash{Symbol => Object}, nil) (defaults to: port == 443)

    Specifies whether to enable SSL and/or the SSL context configuration.

Options Hash (ssl:):

  • :ca_bundle (String, nil)

    The path to the CA bundle directory or file.

  • :cert (Crypto::Cert, OpenSSL::X509::Certificate, nil)

    The certificate to use for the SSL/TLS connection.

  • :cert_store (OpenSSL::X509::Store, nil)

    The certificate store to use for the SSL/TLS connection.

  • :ciphers (Array<(name, version, bits, alg_bits)>, nil)

    The accepted ciphers to use for the SSL/TLS connection.

  • :extra_chain_cert (Crypto::Cert, OpenSSL::X509::Certificate, nil)

    The extra certificate to add to the SSL/TLS certificate chain.

  • :key (Crypto::Key::RSA, Crypto::Key::DSA, OpenSSL::PKey::RSA, OpenSSL::PKey::DSA, nil)

    The RSA or DSA key to use for the SSL/TLS connection.

  • :timeout (Integer, nil)

    The connection timeout limit.

  • :version (1, 1.1, 1.2, Symbol, nil)

    The desired SSL/TLS version.

  • :min_version (1, 1.1, 1.2, Symbol, nil)

    The minimum SSL/TLS version.

  • :max_version (1, 1.1, 1.2, Symbol, nil)

    The maximum SSL/TLS version.

  • :verify_callback (Proc, nil)

    The callback to use when verifying the server's certificate.

  • :verify_depth (Integer, nil)

    The verification depth limit.

  • :verify (:none, :peer, :fail_if_no_peer_cert, true, false, Integer, nil)

    The verification mode.

  • :verify_hostname (Boolean, nil)

    Indicates whether to verify the server's hostname.

Yields:

  • (_self)

Yield Parameters:

Since:

  • 1.0.0



249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
# File 'lib/ronin/support/network/http.rb', line 249

def initialize(host,port, proxy:      nil,
                          ssl:        port == 443,
                          # header options
                          headers:    {},
                          user_agent: self.class.user_agent,
                          cookie:     nil,
                          # Basic-Auth options
                          user:       nil,
                          password:   nil)
  @host  = DNS::IDN.to_ascii(host)
  @port  = port.to_i

  @headers        = headers
  self.user_agent = user_agent if user_agent
  self.cookie     = cookie     if cookie

  @user     = user
  @password = password

  if proxy
    @proxy = URI(proxy)
    @http  = Net::HTTP.new(
      @host, @port,
      @proxy.host, @proxy.port, @proxy.user, @proxy.password
    )
  else
    @http = Net::HTTP.new(@host,@port)
  end

  case ssl
  when true then initialize_ssl
  when Hash then initialize_ssl(**ssl)
  end

  yield self if block_given?
end

Instance Attribute Details

The default cookie params to add to every request.

Returns:



167
168
169
# File 'lib/ronin/support/network/http.rb', line 167

def cookie
  @cookie
end

#headersHash{String => String,Array} (readonly)

Additional headers to add to every request.

Returns:



152
153
154
# File 'lib/ronin/support/network/http.rb', line 152

def headers
  @headers
end

#hostString (readonly)

The host to connect to.

Returns:



142
143
144
# File 'lib/ronin/support/network/http.rb', line 142

def host
  @host
end

#passwordString? (readonly)

The HTTP Baic-Auth password to add to every request.

Returns:



162
163
164
# File 'lib/ronin/support/network/http.rb', line 162

def password
  @password
end

#portInteger (readonly)

The port to connect to.

Returns:



147
148
149
# File 'lib/ronin/support/network/http.rb', line 147

def port
  @port
end

#proxyURI::HTTP, ... (readonly)

The proxy to send requests through.

Returns:



137
138
139
# File 'lib/ronin/support/network/http.rb', line 137

def proxy
  @proxy
end

#userString? (readonly)

The HTTP Baic-Auth user to add to every request.

Returns:



157
158
159
# File 'lib/ronin/support/network/http.rb', line 157

def user
  @user
end

#user_agentString?

The User-Agent header value.

Returns:

Since:

  • 1.0.0



578
579
580
# File 'lib/ronin/support/network/http.rb', line 578

def user_agent
  @user_agent
end

Class Method Details

.allowed_methods(url, proxy: self.proxy, ssl: nil, headers: {}, user_agent: nil, cookie: nil, user: nil, password: nil, **kwargs) ⇒ Array<Symbol>

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

Parameters:

  • url (URI::HTTP, Addressable::URI, String)

    Optional URL to create the HTTP request for.

  • kwargs (Hash{Symbol => Object})

    Aditional keyword arguments and headers for #request.

  • proxy (String, URI::HTTP, Addressable::URI, nil) (defaults to: self.proxy)

    Optional proxy to use for the request.

  • headers (Hash{Symbol,String => String,Array}, nil) (defaults to: {})

    Additional headers to add to each request.

  • user_agent (String, :random, :chrome, :chrome_linux, :chrome_macos, :chrome_windows, :chrome_iphone, :chrome_ipad, :chrome_android, :firefox, :firefox_linux, :firefox_macos, :firefox_windows, :firefox_iphone, :firefox_ipad, :firefox_android, :safari, :safari_macos, :safari_iphone, :safari_ipad, :edge, :linux, :macos, :windows, :iphone, :ipad, :android, nil) (defaults to: nil)

    The default User-Agent value to add to each request.

  • cookie (Cookie, Hash, String, nil) (defaults to: nil)

    The default cookie params to add to each request.

  • user (String, nil) (defaults to: nil)

    The HTTP Basic-Auth user to add to each request.

  • password (String, nil) (defaults to: nil)

    The HTTP Basic-Auth password to add to each request.

  • ssl (Boolean, Hash{Symbol => Object}, nil) (defaults to: nil)

    Specifies whether to enable SSL and/or the SSL context configuration.

Options Hash (ssl:):

  • :ca_bundle (String, nil)

    The path to the CA bundle directory or file.

  • :cert (Crypto::Cert, OpenSSL::X509::Certificate, nil)

    The certificate to use for the SSL/TLS connection.

  • :cert_store (OpenSSL::X509::Store, nil)

    The certificate store to use for the SSL/TLS connection.

  • :ciphers (Array<(name, version, bits, alg_bits)>, nil)

    The accepted ciphers to use for the SSL/TLS connection.

  • :extra_chain_cert (Crypto::Cert, OpenSSL::X509::Certificate, nil)

    The extra certificate to add to the SSL/TLS certificate chain.

  • :key (Crypto::Key::RSA, Crypto::Key::DSA, OpenSSL::PKey::RSA, OpenSSL::PKey::DSA, nil)

    The RSA or DSA key to use for the SSL/TLS connection.

  • :timeout (Integer, nil)

    The connection timeout limit.

  • :version (1, 1.1, 1.2, Symbol, nil)

    The desired SSL/TLS version.

  • :min_version (1, 1.1, 1.2, Symbol, nil)

    The minimum SSL/TLS version.

  • :max_version (1, 1.1, 1.2, Symbol, nil)

    The maximum SSL/TLS version.

  • :verify_callback (Proc, nil)

    The callback to use when verifying the server's certificate.

  • :verify_depth (Integer, nil)

    The verification depth limit.

  • :verify (:none, :peer, :fail_if_no_peer_cert, true, false, Integer, nil)

    The verification mode.

  • :verify_hostname (Boolean, nil)

    Indicates whether to verify the server's hostname.

Options Hash (**kwargs):

  • :query (String, nil)

    The query-string to append to the request path.

  • :query_params (Hash, nil)

    The query-params to append to the request path.

  • :user (String, nil)

    The user to authenticate as.

  • :password (String, nil)

    The password to authenticate with.

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

    Additional HTTP header names and values to add to the request.

  • :content_type (String, :text, :xml, :html, :json, nil)

    The Content-Type header value for the request. If a Symbol is given it will be resolved to a common MIME type:

    • :text - text/plain
    • :xml - text/xml
    • :html - text/html
    • :json - application/json
  • :accept (String, :text, :xml, :html, :json, nil)

    The Accept header value for the request. If a Symbol is given it will be resolved to a common MIME type:

    • :text - text/plain
    • :xml - text/xml
    • :html - text/html
    • :json - application/json
  • :cookie (String, Hash{String => String}, Cookie, nil)

    Additional Cookie header. If a Hash is given, it will be converted to a String using Cookie. If the cookie value is empty, the Cookie header will not be set.

  • :body (String, nil)

    The body of the request.

  • :form_data (Hash, String, nil)

    The form data that may be sent in the body of the request.

  • :json (#to_json, nil)

    The JSON data that will be sent in the body of the request. Will also default the Content-Type header to application/json, unless already set.

Returns:

  • (Array<Symbol>)

    The allowed HTTP request methods for the given URL.

See Also:

Since:

  • 1.0.0



2416
2417
2418
2419
2420
2421
2422
2423
2424
2425
2426
2427
2428
2429
2430
2431
2432
2433
2434
2435
2436
2437
2438
2439
2440
2441
2442
2443
# File 'lib/ronin/support/network/http.rb', line 2416

def self.allowed_methods(url, proxy:      self.proxy,
                              ssl:        nil,
                              headers:    {},
                              user_agent: nil,
                              cookie:     nil,
                              user:       nil,
                              password:   nil,
                              **kwargs)
  uri = case url
        when Addressable::URI, URI::HTTP
          url
        when String
          Addressable::URI.parse(url)
        else
          raise(ArgumentError,"URL argument must be either a Addressable::URI, URI::HTTP, or a String: #{url.inspect}")
        end

  path = uri.request_uri
  http = connect_uri(url, proxy:      proxy,
                          ssl:        ssl,
                          headers:    headers,
                          user_agent: user_agent,
                          cookie:     cookie,
                          user:       user,
                          password:   password)

  http.allowed_methods(path,**kwargs)
end

.connect(host, port, ssl: port == 443, **kwargs) {|http| ... } ⇒ HTTP?

Creates a HTTP connection to the host nad port.

Parameters:

  • host (String)

    The host to connect to.

  • port (Integer)

    The port to connect to.

  • ssl (Boolean, Hash{Symbol => Object}, nil) (defaults to: port == 443)

    Specifies whether to enable SSL and/or the SSL context configuration.

  • kwargs (Hash{Symbol => Object})

    Additional keyword arguments for #initialize.

Options Hash (ssl:):

  • :ca_bundle (String, nil)

    The path to the CA bundle directory or file.

  • :cert (Crypto::Cert, OpenSSL::X509::Certificate, nil)

    The certificate to use for the SSL/TLS connection.

  • :cert_store (OpenSSL::X509::Store, nil)

    The certificate store to use for the SSL/TLS connection.

  • :ciphers (Array<(name, version, bits, alg_bits)>, nil)

    The accepted ciphers to use for the SSL/TLS connection.

  • :extra_chain_cert (Crypto::Cert, OpenSSL::X509::Certificate, nil)

    The extra certificate to add to the SSL/TLS certificate chain.

  • :key (Crypto::Key::RSA, Crypto::Key::DSA, OpenSSL::PKey::RSA, OpenSSL::PKey::DSA, nil)

    The RSA or DSA key to use for the SSL/TLS connection.

  • :timeout (Integer, nil)

    The connection timeout limit.

  • :version (1, 1.1, 1.2, Symbol, nil)

    The desired SSL/TLS version.

  • :min_version (1, 1.1, 1.2, Symbol, nil)

    The minimum SSL/TLS version.

  • :max_version (1, 1.1, 1.2, Symbol, nil)

    The maximum SSL/TLS version.

  • :verify_callback (Proc, nil)

    The callback to use when verifying the server's certificate.

  • :verify_depth (Integer, nil)

    The verification depth limit.

  • :verify (:none, :peer, :fail_if_no_peer_cert, true, false, Integer, nil)

    The verification mode.

  • :verify_hostname (Boolean, nil)

    Indicates whether to verify the server's hostname.

Options Hash (**kwargs):

  • :proxy (String, URI::HTTP, Addressable::URI, nil)

    The optional proxy to send requests through.

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

    Additional headers to add to each request.

  • :user_agent (String, :random, :chrome, :chrome_linux, :chrome_macos, :chrome_windows, :chrome_iphone, :chrome_ipad, :chrome_android, :firefox, :firefox_linux, :firefox_macos, :firefox_windows, :firefox_iphone, :firefox_ipad, :firefox_android, :safari, :safari_macos, :safari_iphone, :safari_ipad, :edge, :linux, :macos, :windows, :iphone, :ipad, :android, nil) — default: HTTP.user_agent

    The default User-Agent string to add to each request.

  • :user (String, nil)

    The HTTP Basic-Auth user to add to each request.

  • :password (String, nil)

    The HTTP Basic-Auth password to add to each request.

Yields:

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

Yield Parameters:

  • http (HTTP)

    The HTTP session object.

Returns:

  • (HTTP, nil)

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

Since:

  • 1.0.0



486
487
488
489
490
491
492
493
494
495
496
497
498
# File 'lib/ronin/support/network/http.rb', line 486

def self.connect(host,port, ssl: port == 443, **kwargs)
  http = new(host,port, ssl: ssl, **kwargs)

  if block_given?
    begin
      yield http
    ensure
      http.close
    end
  else
    return http
  end
end

.connect_uri(url, ssl: nil, user: nil, password: nil, **kwargs) {|http| ... } ⇒ HTTP?

Creates a HTTP connection using the URI.

Parameters:

  • url (URI::HTTP, Addressable::URI, String)

    The URI to connect to.

  • ssl (Boolean, Hash{Symbol => Object}, nil) (defaults to: nil)

    Specifies whether to enable SSL and/or the SSL context configuration.

  • kwargs (Hash{Symbol => Object})

    Additional keyword arguments for #initialize.

Options Hash (ssl:):

  • :ca_bundle (String, nil)

    The path to the CA bundle directory or file.

  • :cert (Crypto::Cert, OpenSSL::X509::Certificate, nil)

    The certificate to use for the SSL/TLS connection.

  • :cert_store (OpenSSL::X509::Store, nil)

    The certificate store to use for the SSL/TLS connection.

  • :ciphers (Array<(name, version, bits, alg_bits)>, nil)

    The accepted ciphers to use for the SSL/TLS connection.

  • :extra_chain_cert (Crypto::Cert, OpenSSL::X509::Certificate, nil)

    The extra certificate to add to the SSL/TLS certificate chain.

  • :key (Crypto::Key::RSA, Crypto::Key::DSA, OpenSSL::PKey::RSA, OpenSSL::PKey::DSA, nil)

    The RSA or DSA key to use for the SSL/TLS connection.

  • :timeout (Integer, nil)

    The connection timeout limit.

  • :version (1, 1.1, 1.2, Symbol, nil)

    The desired SSL/TLS version.

  • :min_version (1, 1.1, 1.2, Symbol, nil)

    The minimum SSL/TLS version.

  • :max_version (1, 1.1, 1.2, Symbol, nil)

    The maximum SSL/TLS version.

  • :verify_callback (Proc, nil)

    The callback to use when verifying the server's certificate.

  • :verify_depth (Integer, nil)

    The verification depth limit.

  • :verify (:none, :peer, :fail_if_no_peer_cert, true, false, Integer, nil)

    The verification mode.

  • :verify_hostname (Boolean, nil)

    Indicates whether to verify the server's hostname.

Options Hash (**kwargs):

  • :proxy (String, URI::HTTP, Addressable::URI, nil)

    The optional proxy to send requests through.

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

    Additional headers to add to each request.

  • :user_agent (String, :random, :chrome, :chrome_linux, :chrome_macos, :chrome_windows, :chrome_iphone, :chrome_ipad, :chrome_android, :firefox, :firefox_linux, :firefox_macos, :firefox_windows, :firefox_iphone, :firefox_ipad, :firefox_android, :safari, :safari_macos, :safari_iphone, :safari_ipad, :edge, :linux, :macos, :windows, :iphone, :ipad, :android, nil) — default: HTTP.user_agent

    The default User-Agent string to add to each request.

  • :user (String, nil)

    The HTTP Basic-Auth user to add to each request.

  • :password (String, nil)

    The HTTP Basic-Auth password to add to each request.

Yields:

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

Yield Parameters:

  • http (HTTP)

    The HTTP session object.

Returns:

  • (HTTP, nil)

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

Raises:

  • (ArgumentError)

    The URL was not a URI::HTTP, Addressable::URI, or a String object.

Since:

  • 1.0.0



525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
# File 'lib/ronin/support/network/http.rb', line 525

def self.connect_uri(url, ssl:      nil,
                          user:     nil,
                          password: nil,
                          **kwargs, &block)
  case url
  when URI::HTTP
    host       = url.host
    port       = url.port
    user     ||= url.user
    password ||= url.password
    ssl      ||= (url.scheme == 'https')
  when String
    uri = Addressable::URI.parse(url)

    host       = uri.host
    port       = uri.inferred_port
    user     ||= uri.user
    password ||= uri.password
    ssl      ||= (uri.scheme == 'https')
  when Addressable::URI
    host       = url.host
    port       = url.inferred_port
    user     ||= url.user
    password ||= url.password
    ssl      ||= (url.scheme == 'https')
  else
    raise(ArgumentError,"url must be a URI::HTTP, Addressable::URI, or a String: #{url.inspect}")
  end

  return connect(host,port, ssl:      ssl,
                            user:     user,
                            password: password,
                            **kwargs, &block)
end

.copy(url, proxy: self.proxy, ssl: nil, headers: {}, user_agent: nil, cookie: nil, user: nil, password: nil, **kwargs) {|response| ... } ⇒ Net::HTTPResponse

Performs a COPY request for the given URI.

Parameters:

  • url (URI::HTTP, Addressable::URI, String)

    Optional URL to create the HTTP request for.

  • kwargs (Hash{Symbol => Object})

    Aditional keyword arguments and headers for #request.

  • proxy (String, URI::HTTP, Addressable::URI, nil) (defaults to: self.proxy)

    Optional proxy to use for the request.

  • headers (Hash{Symbol,String => String,Array}, nil) (defaults to: {})

    Additional headers to add to each request.

  • user_agent (String, :random, :chrome, :chrome_linux, :chrome_macos, :chrome_windows, :chrome_iphone, :chrome_ipad, :chrome_android, :firefox, :firefox_linux, :firefox_macos, :firefox_windows, :firefox_iphone, :firefox_ipad, :firefox_android, :safari, :safari_macos, :safari_iphone, :safari_ipad, :edge, :linux, :macos, :windows, :iphone, :ipad, :android, nil) (defaults to: nil)

    The default User-Agent value to add to each request.

  • cookie (Cookie, Hash, String, nil) (defaults to: nil)

    The default cookie params to add to each request.

  • user (String, nil) (defaults to: nil)

    The HTTP Basic-Auth user to add to each request.

  • password (String, nil) (defaults to: nil)

    The HTTP Basic-Auth password to add to each request.

  • ssl (Boolean, Hash{Symbol => Object}, nil) (defaults to: nil)

    Specifies whether to enable SSL and/or the SSL context configuration.

Options Hash (ssl:):

  • :ca_bundle (String, nil)

    The path to the CA bundle directory or file.

  • :cert (Crypto::Cert, OpenSSL::X509::Certificate, nil)

    The certificate to use for the SSL/TLS connection.

  • :cert_store (OpenSSL::X509::Store, nil)

    The certificate store to use for the SSL/TLS connection.

  • :ciphers (Array<(name, version, bits, alg_bits)>, nil)

    The accepted ciphers to use for the SSL/TLS connection.

  • :extra_chain_cert (Crypto::Cert, OpenSSL::X509::Certificate, nil)

    The extra certificate to add to the SSL/TLS certificate chain.

  • :key (Crypto::Key::RSA, Crypto::Key::DSA, OpenSSL::PKey::RSA, OpenSSL::PKey::DSA, nil)

    The RSA or DSA key to use for the SSL/TLS connection.

  • :timeout (Integer, nil)

    The connection timeout limit.

  • :version (1, 1.1, 1.2, Symbol, nil)

    The desired SSL/TLS version.

  • :min_version (1, 1.1, 1.2, Symbol, nil)

    The minimum SSL/TLS version.

  • :max_version (1, 1.1, 1.2, Symbol, nil)

    The maximum SSL/TLS version.

  • :verify_callback (Proc, nil)

    The callback to use when verifying the server's certificate.

  • :verify_depth (Integer, nil)

    The verification depth limit.

  • :verify (:none, :peer, :fail_if_no_peer_cert, true, false, Integer, nil)

    The verification mode.

  • :verify_hostname (Boolean, nil)

    Indicates whether to verify the server's hostname.

Options Hash (**kwargs):

  • :query (String, nil)

    The query-string to append to the request path.

  • :query_params (Hash, nil)

    The query-params to append to the request path.

  • :user (String, nil)

    The user to authenticate as.

  • :password (String, nil)

    The password to authenticate with.

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

    Additional HTTP header names and values to add to the request.

  • :content_type (String, :text, :xml, :html, :json, nil)

    The Content-Type header value for the request. If a Symbol is given it will be resolved to a common MIME type:

    • :text - text/plain
    • :xml - text/xml
    • :html - text/html
    • :json - application/json
  • :accept (String, :text, :xml, :html, :json, nil)

    The Accept header value for the request. If a Symbol is given it will be resolved to a common MIME type:

    • :text - text/plain
    • :xml - text/xml
    • :html - text/html
    • :json - application/json
  • :cookie (String, Hash{String => String}, Cookie, nil)

    Additional Cookie header. If a Hash is given, it will be converted to a String using Cookie. If the cookie value is empty, the Cookie header will not be set.

  • :body (String, nil)

    The body of the request.

  • :form_data (Hash, String, nil)

    The form data that may be sent in the body of the request.

  • :json (#to_json, nil)

    The JSON data that will be sent in the body of the request. Will also default the Content-Type header to application/json, unless already set.

Yields:

  • (response)

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

Yield Parameters:

  • response (Net::HTTPRresponse)

    The received HTTP response object.

Returns:

  • (Net::HTTPResponse)

    The new HTTP Request object.

See Also:

Since:

  • 1.0.0



1857
1858
1859
1860
1861
1862
1863
1864
1865
1866
1867
1868
1869
1870
1871
1872
1873
1874
1875
1876
1877
1878
1879
1880
1881
1882
1883
1884
1885
# File 'lib/ronin/support/network/http.rb', line 1857

def self.copy(url, proxy:      self.proxy,
                   ssl:        nil,
                   headers:    {},
                   user_agent: nil,
                   cookie:     nil,
                   user:       nil,
                   password:   nil,
                   **kwargs,
                   &block)
  uri = case url
        when Addressable::URI, URI::HTTP
          url
        when String
          Addressable::URI.parse(url)
        else
          raise(ArgumentError,"URL argument must be either a Addressable::URI, URI::HTTP, or a String: #{url.inspect}")
        end

  path = uri.request_uri
  http = connect_uri(url, proxy:      proxy,
                          ssl:        ssl,
                          headers:    headers,
                          user_agent: user_agent,
                          cookie:     cookie,
                          user:       user,
                          password:   password)

  http.copy(path,**kwargs,&block)
end

.delete(url, proxy: self.proxy, ssl: nil, headers: {}, user_agent: nil, cookie: nil, user: nil, password: nil, **kwargs) {|response| ... } ⇒ Net::HTTPResponse

Performs a DELETE request for the given URI.

Parameters:

  • url (URI::HTTP, Addressable::URI, String)

    Optional URL to create the HTTP request for.

  • kwargs (Hash{Symbol => Object})

    Aditional keyword arguments and headers for #request.

  • proxy (String, URI::HTTP, Addressable::URI, nil) (defaults to: self.proxy)

    Optional proxy to use for the request.

  • headers (Hash{Symbol,String => String,Array}, nil) (defaults to: {})

    Additional headers to add to each request.

  • user_agent (String, :random, :chrome, :chrome_linux, :chrome_macos, :chrome_windows, :chrome_iphone, :chrome_ipad, :chrome_android, :firefox, :firefox_linux, :firefox_macos, :firefox_windows, :firefox_iphone, :firefox_ipad, :firefox_android, :safari, :safari_macos, :safari_iphone, :safari_ipad, :edge, :linux, :macos, :windows, :iphone, :ipad, :android, nil) (defaults to: nil)

    The default User-Agent value to add to each request.

  • cookie (Cookie, Hash, String, nil) (defaults to: nil)

    The default cookie params to add to each request.

  • user (String, nil) (defaults to: nil)

    The HTTP Basic-Auth user to add to each request.

  • password (String, nil) (defaults to: nil)

    The HTTP Basic-Auth password to add to each request.

  • ssl (Boolean, Hash{Symbol => Object}, nil) (defaults to: nil)

    Specifies whether to enable SSL and/or the SSL context configuration.

Options Hash (ssl:):

  • :ca_bundle (String, nil)

    The path to the CA bundle directory or file.

  • :cert (Crypto::Cert, OpenSSL::X509::Certificate, nil)

    The certificate to use for the SSL/TLS connection.

  • :cert_store (OpenSSL::X509::Store, nil)

    The certificate store to use for the SSL/TLS connection.

  • :ciphers (Array<(name, version, bits, alg_bits)>, nil)

    The accepted ciphers to use for the SSL/TLS connection.

  • :extra_chain_cert (Crypto::Cert, OpenSSL::X509::Certificate, nil)

    The extra certificate to add to the SSL/TLS certificate chain.

  • :key (Crypto::Key::RSA, Crypto::Key::DSA, OpenSSL::PKey::RSA, OpenSSL::PKey::DSA, nil)

    The RSA or DSA key to use for the SSL/TLS connection.

  • :timeout (Integer, nil)

    The connection timeout limit.

  • :version (1, 1.1, 1.2, Symbol, nil)

    The desired SSL/TLS version.

  • :min_version (1, 1.1, 1.2, Symbol, nil)

    The minimum SSL/TLS version.

  • :max_version (1, 1.1, 1.2, Symbol, nil)

    The maximum SSL/TLS version.

  • :verify_callback (Proc, nil)

    The callback to use when verifying the server's certificate.

  • :verify_depth (Integer, nil)

    The verification depth limit.

  • :verify (:none, :peer, :fail_if_no_peer_cert, true, false, Integer, nil)

    The verification mode.

  • :verify_hostname (Boolean, nil)

    Indicates whether to verify the server's hostname.

Options Hash (**kwargs):

  • :query (String, nil)

    The query-string to append to the request path.

  • :query_params (Hash, nil)

    The query-params to append to the request path.

  • :user (String, nil)

    The user to authenticate as.

  • :password (String, nil)

    The password to authenticate with.

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

    Additional HTTP header names and values to add to the request.

  • :content_type (String, :text, :xml, :html, :json, nil)

    The Content-Type header value for the request. If a Symbol is given it will be resolved to a common MIME type:

    • :text - text/plain
    • :xml - text/xml
    • :html - text/html
    • :json - application/json
  • :accept (String, :text, :xml, :html, :json, nil)

    The Accept header value for the request. If a Symbol is given it will be resolved to a common MIME type:

    • :text - text/plain
    • :xml - text/xml
    • :html - text/html
    • :json - application/json
  • :cookie (String, Hash{String => String}, Cookie, nil)

    Additional Cookie header. If a Hash is given, it will be converted to a String using Cookie. If the cookie value is empty, the Cookie header will not be set.

  • :body (String, nil)

    The body of the request.

  • :form_data (Hash, String, nil)

    The form data that may be sent in the body of the request.

  • :json (#to_json, nil)

    The JSON data that will be sent in the body of the request. Will also default the Content-Type header to application/json, unless already set.

Yields:

  • (response)

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

Yield Parameters:

  • response (Net::HTTPRresponse)

    The received HTTP response object.

Returns:

  • (Net::HTTPResponse)

    The new HTTP Request object.

See Also:

Since:

  • 1.0.0



1910
1911
1912
1913
1914
1915
1916
1917
1918
1919
1920
1921
1922
1923
1924
1925
1926
1927
1928
1929
1930
1931
1932
1933
1934
1935
1936
1937
1938
# File 'lib/ronin/support/network/http.rb', line 1910

def self.delete(url, proxy:      self.proxy,
                     ssl:        nil,
                     headers:    {},
                     user_agent: nil,
                     cookie:     nil,
                     user:       nil,
                     password:   nil,
                     **kwargs,
                     &block)
  uri = case url
        when Addressable::URI, URI::HTTP
          url
        when String
          Addressable::URI.parse(url)
        else
          raise(ArgumentError,"URL argument must be either a Addressable::URI, URI::HTTP, or a String: #{url.inspect}")
        end

  path = uri.request_uri
  http = connect_uri(url, proxy:      proxy,
                          ssl:        ssl,
                          headers:    headers,
                          user_agent: user_agent,
                          cookie:     cookie,
                          user:       user,
                          password:   password)

  http.delete(path,**kwargs,&block)
end

.get(url, proxy: self.proxy, ssl: nil, headers: {}, user_agent: nil, cookie: nil, user: nil, password: nil, **kwargs) {|response| ... } ⇒ Net::HTTPResponse

Performs a GET request for the given URI.

Parameters:

  • url (URI::HTTP, Addressable::URI, String)

    Optional URL to create the HTTP request for.

  • kwargs (Hash{Symbol => Object})

    Aditional keyword arguments and headers for #request.

  • proxy (String, URI::HTTP, Addressable::URI, nil) (defaults to: self.proxy)

    Optional proxy to use for the request.

  • headers (Hash{Symbol,String => String,Array}, nil) (defaults to: {})

    Additional headers to add to each request.

  • user_agent (String, :random, :chrome, :chrome_linux, :chrome_macos, :chrome_windows, :chrome_iphone, :chrome_ipad, :chrome_android, :firefox, :firefox_linux, :firefox_macos, :firefox_windows, :firefox_iphone, :firefox_ipad, :firefox_android, :safari, :safari_macos, :safari_iphone, :safari_ipad, :edge, :linux, :macos, :windows, :iphone, :ipad, :android, nil) (defaults to: nil)

    The default User-Agent value to add to each request.

  • cookie (Cookie, Hash, String, nil) (defaults to: nil)

    The default cookie params to add to each request.

  • user (String, nil) (defaults to: nil)

    The HTTP Basic-Auth user to add to each request.

  • password (String, nil) (defaults to: nil)

    The HTTP Basic-Auth password to add to each request.

  • ssl (Boolean, Hash{Symbol => Object}, nil) (defaults to: nil)

    Specifies whether to enable SSL and/or the SSL context configuration.

Options Hash (ssl:):

  • :ca_bundle (String, nil)

    The path to the CA bundle directory or file.

  • :cert (Crypto::Cert, OpenSSL::X509::Certificate, nil)

    The certificate to use for the SSL/TLS connection.

  • :cert_store (OpenSSL::X509::Store, nil)

    The certificate store to use for the SSL/TLS connection.

  • :ciphers (Array<(name, version, bits, alg_bits)>, nil)

    The accepted ciphers to use for the SSL/TLS connection.

  • :extra_chain_cert (Crypto::Cert, OpenSSL::X509::Certificate, nil)

    The extra certificate to add to the SSL/TLS certificate chain.

  • :key (Crypto::Key::RSA, Crypto::Key::DSA, OpenSSL::PKey::RSA, OpenSSL::PKey::DSA, nil)

    The RSA or DSA key to use for the SSL/TLS connection.

  • :timeout (Integer, nil)

    The connection timeout limit.

  • :version (1, 1.1, 1.2, Symbol, nil)

    The desired SSL/TLS version.

  • :min_version (1, 1.1, 1.2, Symbol, nil)

    The minimum SSL/TLS version.

  • :max_version (1, 1.1, 1.2, Symbol, nil)

    The maximum SSL/TLS version.

  • :verify_callback (Proc, nil)

    The callback to use when verifying the server's certificate.

  • :verify_depth (Integer, nil)

    The verification depth limit.

  • :verify (:none, :peer, :fail_if_no_peer_cert, true, false, Integer, nil)

    The verification mode.

  • :verify_hostname (Boolean, nil)

    Indicates whether to verify the server's hostname.

Options Hash (**kwargs):

  • :query (String, nil)

    The query-string to append to the request path.

  • :query_params (Hash, nil)

    The query-params to append to the request path.

  • :user (String, nil)

    The user to authenticate as.

  • :password (String, nil)

    The password to authenticate with.

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

    Additional HTTP header names and values to add to the request.

  • :content_type (String, :text, :xml, :html, :json, nil)

    The Content-Type header value for the request. If a Symbol is given it will be resolved to a common MIME type:

    • :text - text/plain
    • :xml - text/xml
    • :html - text/html
    • :json - application/json
  • :accept (String, :text, :xml, :html, :json, nil)

    The Accept header value for the request. If a Symbol is given it will be resolved to a common MIME type:

    • :text - text/plain
    • :xml - text/xml
    • :html - text/html
    • :json - application/json
  • :cookie (String, Hash{String => String}, Cookie, nil)

    Additional Cookie header. If a Hash is given, it will be converted to a String using Cookie. If the cookie value is empty, the Cookie header will not be set.

  • :body (String, nil)

    The body of the request.

  • :form_data (Hash, String, nil)

    The form data that may be sent in the body of the request.

  • :json (#to_json, nil)

    The JSON data that will be sent in the body of the request. Will also default the Content-Type header to application/json, unless already set.

Yields:

  • (response)

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

Yield Parameters:

  • response (Net::HTTPRresponse)

    The received HTTP response object.

Returns:

  • (Net::HTTPResponse)

    The new HTTP Request object.

See Also:

Since:

  • 1.0.0



1963
1964
1965
1966
1967
1968
1969
1970
1971
1972
1973
1974
1975
1976
1977
1978
1979
1980
1981
1982
1983
1984
1985
1986
1987
1988
1989
1990
1991
# File 'lib/ronin/support/network/http.rb', line 1963

def self.get(url, proxy:      self.proxy,
                  ssl:        nil,
                  headers:    {},
                  user_agent: nil,
                  cookie:     nil,
                  user:       nil,
                  password:   nil,
                  **kwargs,
                  &block)
  uri = case url
        when Addressable::URI, URI::HTTP
          url
        when String
          Addressable::URI.parse(url)
        else
          raise(ArgumentError,"URL argument must be either a Addressable::URI, URI::HTTP, or a String: #{url.inspect}")
        end

  path = uri.request_uri
  http = connect_uri(url, proxy:      proxy,
                          ssl:        ssl,
                          headers:    headers,
                          user_agent: user_agent,
                          cookie:     cookie,
                          user:       user,
                          password:   password)

  http.get(path,**kwargs,&block)
end

.get_body(url, proxy: self.proxy, ssl: nil, headers: {}, user_agent: nil, cookie: nil, user: nil, password: nil, **kwargs) ⇒ String

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

Parameters:

  • url (URI::HTTP, Addressable::URI, String)

    Optional URL to create the HTTP request for.

  • kwargs (Hash{Symbol => Object})

    Aditional keyword arguments and headers for #request.

  • proxy (String, URI::HTTP, Addressable::URI, nil) (defaults to: self.proxy)

    Optional proxy to use for the request.

  • headers (Hash{Symbol,String => String,Array}, nil) (defaults to: {})

    Additional headers to add to each request.

  • user_agent (String, :random, :chrome, :chrome_linux, :chrome_macos, :chrome_windows, :chrome_iphone, :chrome_ipad, :chrome_android, :firefox, :firefox_linux, :firefox_macos, :firefox_windows, :firefox_iphone, :firefox_ipad, :firefox_android, :safari, :safari_macos, :safari_iphone, :safari_ipad, :edge, :linux, :macos, :windows, :iphone, :ipad, :android, nil) (defaults to: nil)

    The default User-Agent value to add to each request.

  • cookie (Cookie, Hash, String, nil) (defaults to: nil)

    The default cookie params to add to each request.

  • user (String, nil) (defaults to: nil)

    The HTTP Basic-Auth user to add to each request.

  • password (String, nil) (defaults to: nil)

    The HTTP Basic-Auth password to add to each request.

  • ssl (Boolean, Hash{Symbol => Object}, nil) (defaults to: nil)

    Specifies whether to enable SSL and/or the SSL context configuration.

Options Hash (ssl:):

  • :ca_bundle (String, nil)

    The path to the CA bundle directory or file.

  • :cert (Crypto::Cert, OpenSSL::X509::Certificate, nil)

    The certificate to use for the SSL/TLS connection.

  • :cert_store (OpenSSL::X509::Store, nil)

    The certificate store to use for the SSL/TLS connection.

  • :ciphers (Array<(name, version, bits, alg_bits)>, nil)

    The accepted ciphers to use for the SSL/TLS connection.

  • :extra_chain_cert (Crypto::Cert, OpenSSL::X509::Certificate, nil)

    The extra certificate to add to the SSL/TLS certificate chain.

  • :key (Crypto::Key::RSA, Crypto::Key::DSA, OpenSSL::PKey::RSA, OpenSSL::PKey::DSA, nil)

    The RSA or DSA key to use for the SSL/TLS connection.

  • :timeout (Integer, nil)

    The connection timeout limit.

  • :version (1, 1.1, 1.2, Symbol, nil)

    The desired SSL/TLS version.

  • :min_version (1, 1.1, 1.2, Symbol, nil)

    The minimum SSL/TLS version.

  • :max_version (1, 1.1, 1.2, Symbol, nil)

    The maximum SSL/TLS version.

  • :verify_callback (Proc, nil)

    The callback to use when verifying the server's certificate.

  • :verify_depth (Integer, nil)

    The verification depth limit.

  • :verify (:none, :peer, :fail_if_no_peer_cert, true, false, Integer, nil)

    The verification mode.

  • :verify_hostname (Boolean, nil)

    Indicates whether to verify the server's hostname.

Options Hash (**kwargs):

  • :query (String, nil)

    The query-string to append to the request path.

  • :query_params (Hash, nil)

    The query-params to append to the request path.

  • :user (String, nil)

    The user to authenticate as.

  • :password (String, nil)

    The password to authenticate with.

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

    Additional HTTP header names and values to add to the request.

  • :content_type (String, :text, :xml, :html, :json, nil)

    The Content-Type header value for the request. If a Symbol is given it will be resolved to a common MIME type:

    • :text - text/plain
    • :xml - text/xml
    • :html - text/html
    • :json - application/json
  • :accept (String, :text, :xml, :html, :json, nil)

    The Accept header value for the request. If a Symbol is given it will be resolved to a common MIME type:

    • :text - text/plain
    • :xml - text/xml
    • :html - text/html
    • :json - application/json
  • :cookie (String, Hash{String => String}, Cookie, nil)

    Additional Cookie header. If a Hash is given, it will be converted to a String using Cookie. If the cookie value is empty, the Cookie header will not be set.

  • :body (String, nil)

    The body of the request.

  • :form_data (Hash, String, nil)

    The form data that may be sent in the body of the request.

  • :json (#to_json, nil)

    The JSON data that will be sent in the body of the request. Will also default the Content-Type header to application/json, unless already set.

Returns:

  • (String)

    The response body.

See Also:

Since:

  • 1.0.0



2104
2105
2106
2107
2108
2109
2110
2111
2112
2113
2114
2115
2116
2117
2118
2119
2120
2121
2122
2123
2124
2125
2126
2127
2128
2129
2130
2131
# File 'lib/ronin/support/network/http.rb', line 2104

def self.get_body(url, proxy:      self.proxy,
                       ssl:        nil,
                       headers:    {},
                       user_agent: nil,
                       cookie:     nil,
                       user:       nil,
                       password:   nil,
                       **kwargs)
  uri = case url
        when Addressable::URI, URI::HTTP
          url
        when String
          Addressable::URI.parse(url)
        else
          raise(ArgumentError,"URL argument must be either a Addressable::URI, URI::HTTP, or a String: #{url.inspect}")
        end

  path = uri.request_uri
  http = connect_uri(url, proxy:      proxy,
                          ssl:        ssl,
                          headers:    headers,
                          user_agent: user_agent,
                          cookie:     cookie,
                          user:       user,
                          password:   password)

  http.get_body(path,**kwargs)
end

.get_cookies(url, proxy: self.proxy, ssl: nil, headers: {}, user_agent: nil, cookie: nil, user: nil, password: nil, **kwargs) ⇒ Array<SetCookie>?

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

Parameters:

  • url (URI::HTTP, Addressable::URI, String)

    Optional URL to create the HTTP request for.

  • kwargs (Hash{Symbol => Object})

    Aditional keyword arguments and headers for #request.

  • proxy (String, URI::HTTP, Addressable::URI, nil) (defaults to: self.proxy)

    Optional proxy to use for the request.

  • headers (Hash{Symbol,String => String,Array}, nil) (defaults to: {})

    Additional headers to add to each request.

  • user_agent (String, :random, :chrome, :chrome_linux, :chrome_macos, :chrome_windows, :chrome_iphone, :chrome_ipad, :chrome_android, :firefox, :firefox_linux, :firefox_macos, :firefox_windows, :firefox_iphone, :firefox_ipad, :firefox_android, :safari, :safari_macos, :safari_iphone, :safari_ipad, :edge, :linux, :macos, :windows, :iphone, :ipad, :android, nil) (defaults to: nil)

    The default User-Agent value to add to each request.

  • cookie (Cookie, Hash, String, nil) (defaults to: nil)

    The default cookie params to add to each request.

  • user (String, nil) (defaults to: nil)

    The HTTP Basic-Auth user to add to each request.

  • password (String, nil) (defaults to: nil)

    The HTTP Basic-Auth password to add to each request.

  • ssl (Boolean, Hash{Symbol => Object}, nil) (defaults to: nil)

    Specifies whether to enable SSL and/or the SSL context configuration.

Options Hash (ssl:):

  • :ca_bundle (String, nil)

    The path to the CA bundle directory or file.

  • :cert (Crypto::Cert, OpenSSL::X509::Certificate, nil)

    The certificate to use for the SSL/TLS connection.

  • :cert_store (OpenSSL::X509::Store, nil)

    The certificate store to use for the SSL/TLS connection.

  • :ciphers (Array<(name, version, bits, alg_bits)>, nil)

    The accepted ciphers to use for the SSL/TLS connection.

  • :extra_chain_cert (Crypto::Cert, OpenSSL::X509::Certificate, nil)

    The extra certificate to add to the SSL/TLS certificate chain.

  • :key (Crypto::Key::RSA, Crypto::Key::DSA, OpenSSL::PKey::RSA, OpenSSL::PKey::DSA, nil)

    The RSA or DSA key to use for the SSL/TLS connection.

  • :timeout (Integer, nil)

    The connection timeout limit.

  • :version (1, 1.1, 1.2, Symbol, nil)

    The desired SSL/TLS version.

  • :min_version (1, 1.1, 1.2, Symbol, nil)

    The minimum SSL/TLS version.

  • :max_version (1, 1.1, 1.2, Symbol, nil)

    The maximum SSL/TLS version.

  • :verify_callback (Proc, nil)

    The callback to use when verifying the server's certificate.

  • :verify_depth (Integer, nil)

    The verification depth limit.

  • :verify (:none, :peer, :fail_if_no_peer_cert, true, false, Integer, nil)

    The verification mode.

  • :verify_hostname (Boolean, nil)

    Indicates whether to verify the server's hostname.

Options Hash (**kwargs):

  • :query (String, nil)

    The query-string to append to the request path.

  • :query_params (Hash, nil)

    The query-params to append to the request path.

  • :user (String, nil)

    The user to authenticate as.

  • :password (String, nil)

    The password to authenticate with.

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

    Additional HTTP header names and values to add to the request.

  • :content_type (String, :text, :xml, :html, :json, nil)

    The Content-Type header value for the request. If a Symbol is given it will be resolved to a common MIME type:

    • :text - text/plain
    • :xml - text/xml
    • :html - text/html
    • :json - application/json
  • :accept (String, :text, :xml, :html, :json, nil)

    The Accept header value for the request. If a Symbol is given it will be resolved to a common MIME type:

    • :text - text/plain
    • :xml - text/xml
    • :html - text/html
    • :json - application/json
  • :cookie (String, Hash{String => String}, Cookie, nil)

    Additional Cookie header. If a Hash is given, it will be converted to a String using Cookie. If the cookie value is empty, the Cookie header will not be set.

  • :body (String, nil)

    The body of the request.

  • :form_data (Hash, String, nil)

    The form data that may be sent in the body of the request.

  • :json (#to_json, nil)

    The JSON data that will be sent in the body of the request. Will also default the Content-Type header to application/json, unless already set.

Returns:

See Also:

Since:

  • 1.0.0



2057
2058
2059
2060
2061
2062
2063
2064
2065
2066
2067
2068
2069
2070
2071
2072
2073
2074
2075
2076
2077
2078
2079
2080
2081
2082
2083
2084
# File 'lib/ronin/support/network/http.rb', line 2057

def self.get_cookies(url, proxy:      self.proxy,
                          ssl:        nil,
                          headers:    {},
                          user_agent: nil,
                          cookie:     nil,
                          user:       nil,
                          password:   nil,
                          **kwargs)
  uri = case url
        when Addressable::URI, URI::HTTP
          url
        when String
          Addressable::URI.parse(url)
        else
          raise(ArgumentError,"URL argument must be either a Addressable::URI, URI::HTTP, or a String: #{url.inspect}")
        end

  path = uri.request_uri
  http = connect_uri(url, proxy:      proxy,
                          ssl:        ssl,
                          headers:    headers,
                          user_agent: user_agent,
                          cookie:     cookie,
                          user:       user,
                          password:   password)

  http.get_cookies(path, **kwargs)
end

.get_headers(url, proxy: self.proxy, ssl: nil, headers: {}, user_agent: nil, cookie: nil, user: nil, password: nil, **kwargs) ⇒ Hash{String => String}

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

Parameters:

  • url (URI::HTTP, Addressable::URI, String)

    Optional URL to create the HTTP request for.

  • kwargs (Hash{Symbol => Object})

    Aditional keyword arguments and headers for #request.

  • proxy (String, URI::HTTP, Addressable::URI, nil) (defaults to: self.proxy)

    Optional proxy to use for the request.

  • headers (Hash{Symbol,String => String,Array}, nil) (defaults to: {})

    Additional headers to add to each request.

  • user_agent (String, :random, :chrome, :chrome_linux, :chrome_macos, :chrome_windows, :chrome_iphone, :chrome_ipad, :chrome_android, :firefox, :firefox_linux, :firefox_macos, :firefox_windows, :firefox_iphone, :firefox_ipad, :firefox_android, :safari, :safari_macos, :safari_iphone, :safari_ipad, :edge, :linux, :macos, :windows, :iphone, :ipad, :android, nil) (defaults to: nil)

    The default User-Agent value to add to each request.

  • cookie (Cookie, Hash, String, nil) (defaults to: nil)

    The default cookie params to add to each request.

  • user (String, nil) (defaults to: nil)

    The HTTP Basic-Auth user to add to each request.

  • password (String, nil) (defaults to: nil)

    The HTTP Basic-Auth password to add to each request.

  • ssl (Boolean, Hash{Symbol => Object}, nil) (defaults to: nil)

    Specifies whether to enable SSL and/or the SSL context configuration.

Options Hash (ssl:):

  • :ca_bundle (String, nil)

    The path to the CA bundle directory or file.

  • :cert (Crypto::Cert, OpenSSL::X509::Certificate, nil)

    The certificate to use for the SSL/TLS connection.

  • :cert_store (OpenSSL::X509::Store, nil)

    The certificate store to use for the SSL/TLS connection.

  • :ciphers (Array<(name, version, bits, alg_bits)>, nil)

    The accepted ciphers to use for the SSL/TLS connection.

  • :extra_chain_cert (Crypto::Cert, OpenSSL::X509::Certificate, nil)

    The extra certificate to add to the SSL/TLS certificate chain.

  • :key (Crypto::Key::RSA, Crypto::Key::DSA, OpenSSL::PKey::RSA, OpenSSL::PKey::DSA, nil)

    The RSA or DSA key to use for the SSL/TLS connection.

  • :timeout (Integer, nil)

    The connection timeout limit.

  • :version (1, 1.1, 1.2, Symbol, nil)

    The desired SSL/TLS version.

  • :min_version (1, 1.1, 1.2, Symbol, nil)

    The minimum SSL/TLS version.

  • :max_version (1, 1.1, 1.2, Symbol, nil)

    The maximum SSL/TLS version.

  • :verify_callback (Proc, nil)

    The callback to use when verifying the server's certificate.

  • :verify_depth (Integer, nil)

    The verification depth limit.

  • :verify (:none, :peer, :fail_if_no_peer_cert, true, false, Integer, nil)

    The verification mode.

  • :verify_hostname (Boolean, nil)

    Indicates whether to verify the server's hostname.

Options Hash (**kwargs):

  • :query (String, nil)

    The query-string to append to the request path.

  • :query_params (Hash, nil)

    The query-params to append to the request path.

  • :user (String, nil)

    The user to authenticate as.

  • :password (String, nil)

    The password to authenticate with.

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

    Additional HTTP header names and values to add to the request.

  • :content_type (String, :text, :xml, :html, :json, nil)

    The Content-Type header value for the request. If a Symbol is given it will be resolved to a common MIME type:

    • :text - text/plain
    • :xml - text/xml
    • :html - text/html
    • :json - application/json
  • :accept (String, :text, :xml, :html, :json, nil)

    The Accept header value for the request. If a Symbol is given it will be resolved to a common MIME type:

    • :text - text/plain
    • :xml - text/xml
    • :html - text/html
    • :json - application/json
  • :cookie (String, Hash{String => String}, Cookie, nil)

    Additional Cookie header. If a Hash is given, it will be converted to a String using Cookie. If the cookie value is empty, the Cookie header will not be set.

  • :body (String, nil)

    The body of the request.

  • :form_data (Hash, String, nil)

    The form data that may be sent in the body of the request.

  • :json (#to_json, nil)

    The JSON data that will be sent in the body of the request. Will also default the Content-Type header to application/json, unless already set.

Returns:

See Also:

Since:

  • 1.0.0



2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
2025
2026
2027
2028
2029
2030
2031
2032
2033
2034
2035
2036
2037
2038
# File 'lib/ronin/support/network/http.rb', line 2011

def self.get_headers(url, proxy:      self.proxy,
                          ssl:        nil,
                          headers:    {},
                          user_agent: nil,
                          cookie:     nil,
                          user:       nil,
                          password:   nil,
                          **kwargs)
  uri = case url
        when Addressable::URI, URI::HTTP
          url
        when String
          Addressable::URI.parse(url)
        else
          raise(ArgumentError,"URL argument must be either a Addressable::URI, URI::HTTP, or a String: #{url.inspect}")
        end

  path = uri.request_uri
  http = connect_uri(url, proxy:      proxy,
                          ssl:        ssl,
                          headers:    headers,
                          user_agent: user_agent,
                          cookie:     cookie,
                          user:       user,
                          password:   password)

  http.get_headers(path,**kwargs)
end

.head(url, proxy: self.proxy, ssl: nil, headers: {}, user_agent: nil, cookie: nil, user: nil, password: nil, **kwargs) {|response| ... } ⇒ Net::HTTPResponse

Performs a HEAD request for the given URI.

Parameters:

  • url (URI::HTTP, Addressable::URI, String)

    Optional URL to create the HTTP request for.

  • kwargs (Hash{Symbol => Object})

    Aditional keyword arguments and headers for #request.

  • proxy (String, URI::HTTP, Addressable::URI, nil) (defaults to: self.proxy)

    Optional proxy to use for the request.

  • headers (Hash{Symbol,String => String,Array}, nil) (defaults to: {})

    Additional headers to add to each request.

  • user_agent (String, :random, :chrome, :chrome_linux, :chrome_macos, :chrome_windows, :chrome_iphone, :chrome_ipad, :chrome_android, :firefox, :firefox_linux, :firefox_macos, :firefox_windows, :firefox_iphone, :firefox_ipad, :firefox_android, :safari, :safari_macos, :safari_iphone, :safari_ipad, :edge, :linux, :macos, :windows, :iphone, :ipad, :android, nil) (defaults to: nil)

    The default User-Agent value to add to each request.

  • cookie (Cookie, Hash, String, nil) (defaults to: nil)

    The default cookie params to add to each request.

  • user (String, nil) (defaults to: nil)

    The HTTP Basic-Auth user to add to each request.

  • password (String, nil) (defaults to: nil)

    The HTTP Basic-Auth password to add to each request.

  • ssl (Boolean, Hash{Symbol => Object}, nil) (defaults to: nil)

    Specifies whether to enable SSL and/or the SSL context configuration.

Options Hash (ssl:):

  • :ca_bundle (String, nil)

    The path to the CA bundle directory or file.

  • :cert (Crypto::Cert, OpenSSL::X509::Certificate, nil)

    The certificate to use for the SSL/TLS connection.

  • :cert_store (OpenSSL::X509::Store, nil)

    The certificate store to use for the SSL/TLS connection.

  • :ciphers (Array<(name, version, bits, alg_bits)>, nil)

    The accepted ciphers to use for the SSL/TLS connection.

  • :extra_chain_cert (Crypto::Cert, OpenSSL::X509::Certificate, nil)

    The extra certificate to add to the SSL/TLS certificate chain.

  • :key (Crypto::Key::RSA, Crypto::Key::DSA, OpenSSL::PKey::RSA, OpenSSL::PKey::DSA, nil)

    The RSA or DSA key to use for the SSL/TLS connection.

  • :timeout (Integer, nil)

    The connection timeout limit.

  • :version (1, 1.1, 1.2, Symbol, nil)

    The desired SSL/TLS version.

  • :min_version (1, 1.1, 1.2, Symbol, nil)

    The minimum SSL/TLS version.

  • :max_version (1, 1.1, 1.2, Symbol, nil)

    The maximum SSL/TLS version.

  • :verify_callback (Proc, nil)

    The callback to use when verifying the server's certificate.

  • :verify_depth (Integer, nil)

    The verification depth limit.

  • :verify (:none, :peer, :fail_if_no_peer_cert, true, false, Integer, nil)

    The verification mode.

  • :verify_hostname (Boolean, nil)

    Indicates whether to verify the server's hostname.

Options Hash (**kwargs):

  • :query (String, nil)

    The query-string to append to the request path.

  • :query_params (Hash, nil)

    The query-params to append to the request path.

  • :user (String, nil)

    The user to authenticate as.

  • :password (String, nil)

    The password to authenticate with.

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

    Additional HTTP header names and values to add to the request.

  • :content_type (String, :text, :xml, :html, :json, nil)

    The Content-Type header value for the request. If a Symbol is given it will be resolved to a common MIME type:

    • :text - text/plain
    • :xml - text/xml
    • :html - text/html
    • :json - application/json
  • :accept (String, :text, :xml, :html, :json, nil)

    The Accept header value for the request. If a Symbol is given it will be resolved to a common MIME type:

    • :text - text/plain
    • :xml - text/xml
    • :html - text/html
    • :json - application/json
  • :cookie (String, Hash{String => String}, Cookie, nil)

    Additional Cookie header. If a Hash is given, it will be converted to a String using Cookie. If the cookie value is empty, the Cookie header will not be set.

  • :body (String, nil)

    The body of the request.

  • :form_data (Hash, String, nil)

    The form data that may be sent in the body of the request.

  • :json (#to_json, nil)

    The JSON data that will be sent in the body of the request. Will also default the Content-Type header to application/json, unless already set.

Yields:

  • (response)

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

Yield Parameters:

  • response (Net::HTTPRresponse)

    The received HTTP response object.

Returns:

  • (Net::HTTPResponse)

    The new HTTP Request object.

See Also:

Since:

  • 1.0.0



2156
2157
2158
2159
2160
2161
2162
2163
2164
2165
2166
2167
2168
2169
2170
2171
2172
2173
2174
2175
2176
2177
2178
2179
2180
2181
2182
2183
2184
# File 'lib/ronin/support/network/http.rb', line 2156

def self.head(url, proxy:      self.proxy,
                   ssl:        nil,
                   headers:    {},
                   user_agent: nil,
                   cookie:     nil,
                   user:       nil,
                   password:   nil,
                   **kwargs,
                   &block)
  uri = case url
        when Addressable::URI, URI::HTTP
          url
        when String
          Addressable::URI.parse(url)
        else
          raise(ArgumentError,"URL argument must be either a Addressable::URI, URI::HTTP, or a String: #{url.inspect}")
        end

  path = uri.request_uri
  http = connect_uri(url, proxy:      proxy,
                          ssl:        ssl,
                          headers:    headers,
                          user_agent: user_agent,
                          cookie:     cookie,
                          user:       user,
                          password:   password)

  http.head(path,**kwargs,&block)
end

.lock(url, proxy: self.proxy, ssl: nil, headers: {}, user_agent: nil, cookie: nil, user: nil, password: nil, **kwargs) {|response| ... } ⇒ Net::HTTPResponse

Performs a LOCK request for the given URI.

Parameters:

  • url (URI::HTTP, Addressable::URI, String)

    Optional URL to create the HTTP request for.

  • kwargs (Hash{Symbol => Object})

    Aditional keyword arguments and headers for #request.

  • proxy (String, URI::HTTP, Addressable::URI, nil) (defaults to: self.proxy)

    Optional proxy to use for the request.

  • headers (Hash{Symbol,String => String,Array}, nil) (defaults to: {})

    Additional headers to add to each request.

  • user_agent (String, :random, :chrome, :chrome_linux, :chrome_macos, :chrome_windows, :chrome_iphone, :chrome_ipad, :chrome_android, :firefox, :firefox_linux, :firefox_macos, :firefox_windows, :firefox_iphone, :firefox_ipad, :firefox_android, :safari, :safari_macos, :safari_iphone, :safari_ipad, :edge, :linux, :macos, :windows, :iphone, :ipad, :android, nil) (defaults to: nil)

    The default User-Agent value to add to each request.

  • cookie (Cookie, Hash, String, nil) (defaults to: nil)

    The default cookie params to add to each request.

  • user (String, nil) (defaults to: nil)

    The HTTP Basic-Auth user to add to each request.

  • password (String, nil) (defaults to: nil)

    The HTTP Basic-Auth password to add to each request.

  • ssl (Boolean, Hash{Symbol => Object}, nil) (defaults to: nil)

    Specifies whether to enable SSL and/or the SSL context configuration.

Options Hash (ssl:):

  • :ca_bundle (String, nil)

    The path to the CA bundle directory or file.

  • :cert (Crypto::Cert, OpenSSL::X509::Certificate, nil)

    The certificate to use for the SSL/TLS connection.

  • :cert_store (OpenSSL::X509::Store, nil)

    The certificate store to use for the SSL/TLS connection.

  • :ciphers (Array<(name, version, bits, alg_bits)>, nil)

    The accepted ciphers to use for the SSL/TLS connection.

  • :extra_chain_cert (Crypto::Cert, OpenSSL::X509::Certificate, nil)

    The extra certificate to add to the SSL/TLS certificate chain.

  • :key (Crypto::Key::RSA, Crypto::Key::DSA, OpenSSL::PKey::RSA, OpenSSL::PKey::DSA, nil)

    The RSA or DSA key to use for the SSL/TLS connection.

  • :timeout (Integer, nil)

    The connection timeout limit.

  • :version (1, 1.1, 1.2, Symbol, nil)

    The desired SSL/TLS version.

  • :min_version (1, 1.1, 1.2, Symbol, nil)

    The minimum SSL/TLS version.

  • :max_version (1, 1.1, 1.2, Symbol, nil)

    The maximum SSL/TLS version.

  • :verify_callback (Proc, nil)

    The callback to use when verifying the server's certificate.

  • :verify_depth (Integer, nil)

    The verification depth limit.

  • :verify (:none, :peer, :fail_if_no_peer_cert, true, false, Integer, nil)

    The verification mode.

  • :verify_hostname (Boolean, nil)

    Indicates whether to verify the server's hostname.

Options Hash (**kwargs):

  • :query (String, nil)

    The query-string to append to the request path.

  • :query_params (Hash, nil)

    The query-params to append to the request path.

  • :user (String, nil)

    The user to authenticate as.

  • :password (String, nil)

    The password to authenticate with.

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

    Additional HTTP header names and values to add to the request.

  • :content_type (String, :text, :xml, :html, :json, nil)

    The Content-Type header value for the request. If a Symbol is given it will be resolved to a common MIME type:

    • :text - text/plain
    • :xml - text/xml
    • :html - text/html
    • :json - application/json
  • :accept (String, :text, :xml, :html, :json, nil)

    The Accept header value for the request. If a Symbol is given it will be resolved to a common MIME type:

    • :text - text/plain
    • :xml - text/xml
    • :html - text/html
    • :json - application/json
  • :cookie (String, Hash{String => String}, Cookie, nil)

    Additional Cookie header. If a Hash is given, it will be converted to a String using Cookie. If the cookie value is empty, the Cookie header will not be set.

  • :body (String, nil)

    The body of the request.

  • :form_data (Hash, String, nil)

    The form data that may be sent in the body of the request.

  • :json (#to_json, nil)

    The JSON data that will be sent in the body of the request. Will also default the Content-Type header to application/json, unless already set.

Yields:

  • (response)

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

Yield Parameters:

  • response (Net::HTTPRresponse)

    The received HTTP response object.

Returns:

  • (Net::HTTPResponse)

    The new HTTP Request object.

See Also:

Since:

  • 1.0.0



2209
2210
2211
2212
2213
2214
2215
2216
2217
2218
2219
2220
2221
2222
2223
2224
2225
2226
2227
2228
2229
2230
2231
2232
2233
2234
2235
2236
2237
# File 'lib/ronin/support/network/http.rb', line 2209

def self.lock(url, proxy:      self.proxy,
                   ssl:        nil,
                   headers:    {},
                   user_agent: nil,
                   cookie:     nil,
                   user:       nil,
                   password:   nil,
                   **kwargs,
                   &block)
  uri = case url
        when Addressable::URI, URI::HTTP
          url
        when String
          Addressable::URI.parse(url)
        else
          raise(ArgumentError,"URL argument must be either a Addressable::URI, URI::HTTP, or a String: #{url.inspect}")
        end

  path = uri.request_uri
  http = connect_uri(url, proxy:      proxy,
                          ssl:        ssl,
                          headers:    headers,
                          user_agent: user_agent,
                          cookie:     cookie,
                          user:       user,
                          password:   password)

  http.lock(path,**kwargs,&block)
end

.mkcol(url, proxy: self.proxy, ssl: nil, headers: {}, user_agent: nil, cookie: nil, user: nil, password: nil, **kwargs) {|response| ... } ⇒ Net::HTTPResponse

Performs a MKCOL request for the given URI.

Parameters:

  • url (URI::HTTP, Addressable::URI, String)

    Optional URL to create the HTTP request for.

  • kwargs (Hash{Symbol => Object})

    Aditional keyword arguments and headers for #request.

  • proxy (String, URI::HTTP, Addressable::URI, nil) (defaults to: self.proxy)

    Optional proxy to use for the request.

  • headers (Hash{Symbol,String => String,Array}, nil) (defaults to: {})

    Additional headers to add to each request.

  • user_agent (String, :random, :chrome, :chrome_linux, :chrome_macos, :chrome_windows, :chrome_iphone, :chrome_ipad, :chrome_android, :firefox, :firefox_linux, :firefox_macos, :firefox_windows, :firefox_iphone, :firefox_ipad, :firefox_android, :safari, :safari_macos, :safari_iphone, :safari_ipad, :edge, :linux, :macos, :windows, :iphone, :ipad, :android, nil) (defaults to: nil)

    The default User-Agent value to add to each request.

  • cookie (Cookie, Hash, String, nil) (defaults to: nil)

    The default cookie params to add to each request.

  • user (String, nil) (defaults to: nil)

    The HTTP Basic-Auth user to add to each request.

  • password (String, nil) (defaults to: nil)

    The HTTP Basic-Auth password to add to each request.

  • ssl (Boolean, Hash{Symbol => Object}, nil) (defaults to: nil)

    Specifies whether to enable SSL and/or the SSL context configuration.

Options Hash (ssl:):

  • :ca_bundle (String, nil)

    The path to the CA bundle directory or file.

  • :cert (Crypto::Cert, OpenSSL::X509::Certificate, nil)

    The certificate to use for the SSL/TLS connection.

  • :cert_store (OpenSSL::X509::Store, nil)

    The certificate store to use for the SSL/TLS connection.

  • :ciphers (Array<(name, version, bits, alg_bits)>, nil)

    The accepted ciphers to use for the SSL/TLS connection.

  • :extra_chain_cert (Crypto::Cert, OpenSSL::X509::Certificate, nil)

    The extra certificate to add to the SSL/TLS certificate chain.

  • :key (Crypto::Key::RSA, Crypto::Key::DSA, OpenSSL::PKey::RSA, OpenSSL::PKey::DSA, nil)

    The RSA or DSA key to use for the SSL/TLS connection.

  • :timeout (Integer, nil)

    The connection timeout limit.

  • :version (1, 1.1, 1.2, Symbol, nil)

    The desired SSL/TLS version.

  • :min_version (1, 1.1, 1.2, Symbol, nil)

    The minimum SSL/TLS version.

  • :max_version (1, 1.1, 1.2, Symbol, nil)

    The maximum SSL/TLS version.

  • :verify_callback (Proc, nil)

    The callback to use when verifying the server's certificate.

  • :verify_depth (Integer, nil)

    The verification depth limit.

  • :verify (:none, :peer, :fail_if_no_peer_cert, true, false, Integer, nil)

    The verification mode.

  • :verify_hostname (Boolean, nil)

    Indicates whether to verify the server's hostname.

Options Hash (**kwargs):

  • :query (String, nil)

    The query-string to append to the request path.

  • :query_params (Hash, nil)

    The query-params to append to the request path.

  • :user (String, nil)

    The user to authenticate as.

  • :password (String, nil)

    The password to authenticate with.

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

    Additional HTTP header names and values to add to the request.

  • :content_type (String, :text, :xml, :html, :json, nil)

    The Content-Type header value for the request. If a Symbol is given it will be resolved to a common MIME type:

    • :text - text/plain
    • :xml - text/xml
    • :html - text/html
    • :json - application/json
  • :accept (String, :text, :xml, :html, :json, nil)

    The Accept header value for the request. If a Symbol is given it will be resolved to a common MIME type:

    • :text - text/plain
    • :xml - text/xml
    • :html - text/html
    • :json - application/json
  • :cookie (String, Hash{String => String}, Cookie, nil)

    Additional Cookie header. If a Hash is given, it will be converted to a String using Cookie. If the cookie value is empty, the Cookie header will not be set.

  • :body (String, nil)

    The body of the request.

  • :form_data (Hash, String, nil)

    The form data that may be sent in the body of the request.

  • :json (#to_json, nil)

    The JSON data that will be sent in the body of the request. Will also default the Content-Type header to application/json, unless already set.

Yields:

  • (response)

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

Yield Parameters:

  • response (Net::HTTPRresponse)

    The received HTTP response object.

Returns:

  • (Net::HTTPResponse)

    The new HTTP Request object.

See Also:

Since:

  • 1.0.0



2262
2263
2264
2265
2266
2267
2268
2269
2270
2271
2272
2273
2274
2275
2276
2277
2278
2279
2280
2281
2282
2283
2284
2285
2286
2287
2288
2289
2290
# File 'lib/ronin/support/network/http.rb', line 2262

def self.mkcol(url, proxy:      self.proxy,
                    ssl:        nil,
                    headers:    {},
                    user_agent: nil,
                    cookie:     nil,
                    user:       nil,
                    password:   nil,
                    **kwargs,
                    &block)
  uri = case url
        when Addressable::URI, URI::HTTP
          url
        when String
          Addressable::URI.parse(url)
        else
          raise(ArgumentError,"URL argument must be either a Addressable::URI, URI::HTTP, or a String: #{url.inspect}")
        end

  path = uri.request_uri
  http = connect_uri(url, proxy:      proxy,
                          ssl:        ssl,
                          headers:    headers,
                          user_agent: user_agent,
                          cookie:     cookie,
                          user:       user,
                          password:   password)

  http.mkcol(path,**kwargs,&block)
end

.move(url, proxy: self.proxy, ssl: nil, headers: {}, user_agent: nil, cookie: nil, user: nil, password: nil, **kwargs) {|response| ... } ⇒ Net::HTTPResponse

Performs a MOVE request for the given URI.

Parameters:

  • url (URI::HTTP, Addressable::URI, String)

    Optional URL to create the HTTP request for.

  • kwargs (Hash{Symbol => Object})

    Aditional keyword arguments and headers for #request.

  • proxy (String, URI::HTTP, Addressable::URI, nil) (defaults to: self.proxy)

    Optional proxy to use for the request.

  • headers (Hash{Symbol,String => String,Array}, nil) (defaults to: {})

    Additional headers to add to each request.

  • user_agent (String, :random, :chrome, :chrome_linux, :chrome_macos, :chrome_windows, :chrome_iphone, :chrome_ipad, :chrome_android, :firefox, :firefox_linux, :firefox_macos, :firefox_windows, :firefox_iphone, :firefox_ipad, :firefox_android, :safari, :safari_macos, :safari_iphone, :safari_ipad, :edge, :linux, :macos, :windows, :iphone, :ipad, :android, nil) (defaults to: nil)

    The default User-Agent value to add to each request.

  • cookie (Cookie, Hash, String, nil) (defaults to: nil)

    The default cookie params to add to each request.

  • user (String, nil) (defaults to: nil)

    The HTTP Basic-Auth user to add to each request.

  • password (String, nil) (defaults to: nil)

    The HTTP Basic-Auth password to add to each request.

  • ssl (Boolean, Hash{Symbol => Object}, nil) (defaults to: nil)

    Specifies whether to enable SSL and/or the SSL context configuration.

Options Hash (ssl:):

  • :ca_bundle (String, nil)

    The path to the CA bundle directory or file.

  • :cert (Crypto::Cert, OpenSSL::X509::Certificate, nil)

    The certificate to use for the SSL/TLS connection.

  • :cert_store (OpenSSL::X509::Store, nil)

    The certificate store to use for the SSL/TLS connection.

  • :ciphers (Array<(name, version, bits, alg_bits)>, nil)

    The accepted ciphers to use for the SSL/TLS connection.

  • :extra_chain_cert (Crypto::Cert, OpenSSL::X509::Certificate, nil)

    The extra certificate to add to the SSL/TLS certificate chain.

  • :key (Crypto::Key::RSA, Crypto::Key::DSA, OpenSSL::PKey::RSA, OpenSSL::PKey::DSA, nil)

    The RSA or DSA key to use for the SSL/TLS connection.

  • :timeout (Integer, nil)

    The connection timeout limit.

  • :version (1, 1.1, 1.2, Symbol, nil)

    The desired SSL/TLS version.

  • :min_version (1, 1.1, 1.2, Symbol, nil)

    The minimum SSL/TLS version.

  • :max_version (1, 1.1, 1.2, Symbol, nil)

    The maximum SSL/TLS version.

  • :verify_callback (Proc, nil)

    The callback to use when verifying the server's certificate.

  • :verify_depth (Integer, nil)

    The verification depth limit.

  • :verify (:none, :peer, :fail_if_no_peer_cert, true, false, Integer, nil)

    The verification mode.

  • :verify_hostname (Boolean, nil)

    Indicates whether to verify the server's hostname.

Options Hash (**kwargs):

  • :query (String, nil)

    The query-string to append to the request path.

  • :query_params (Hash, nil)

    The query-params to append to the request path.

  • :user (String, nil)

    The user to authenticate as.

  • :password (String, nil)

    The password to authenticate with.

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

    Additional HTTP header names and values to add to the request.

  • :content_type (String, :text, :xml, :html, :json, nil)

    The Content-Type header value for the request. If a Symbol is given it will be resolved to a common MIME type:

    • :text - text/plain
    • :xml - text/xml
    • :html - text/html
    • :json - application/json
  • :accept (String, :text, :xml, :html, :json, nil)

    The Accept header value for the request. If a Symbol is given it will be resolved to a common MIME type:

    • :text - text/plain
    • :xml - text/xml
    • :html - text/html
    • :json - application/json
  • :cookie (String, Hash{String => String}, Cookie, nil)

    Additional Cookie header. If a Hash is given, it will be converted to a String using Cookie. If the cookie value is empty, the Cookie header will not be set.

  • :body (String, nil)

    The body of the request.

  • :form_data (Hash, String, nil)

    The form data that may be sent in the body of the request.

  • :json (#to_json, nil)

    The JSON data that will be sent in the body of the request. Will also default the Content-Type header to application/json, unless already set.

Yields:

  • (response)

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

Yield Parameters:

  • response (Net::HTTPRresponse)

    The received HTTP response object.

Returns:

  • (Net::HTTPResponse)

    The new HTTP Request object.

See Also:

Since:

  • 1.0.0



2315
2316
2317
2318
2319
2320
2321
2322
2323
2324
2325
2326
2327
2328
2329
2330
2331
2332
2333
2334
2335
2336
2337
2338
2339
2340
2341
2342
2343
# File 'lib/ronin/support/network/http.rb', line 2315

def self.move(url, proxy:      self.proxy,
                   ssl:        nil,
                   headers:    {},
                   user_agent: nil,
                   cookie:     nil,
                   user:       nil,
                   password:   nil,
                   **kwargs,
                   &block)
  uri = case url
        when Addressable::URI, URI::HTTP
          url
        when String
          Addressable::URI.parse(url)
        else
          raise(ArgumentError,"URL argument must be either a Addressable::URI, URI::HTTP, or a String: #{url.inspect}")
        end

  path = uri.request_uri
  http = connect_uri(url, proxy:      proxy,
                          ssl:        ssl,
                          headers:    headers,
                          user_agent: user_agent,
                          cookie:     cookie,
                          user:       user,
                          password:   password)

  http.move(path,**kwargs,&block)
end

.ok?(method = :head, url, proxy: self.proxy, ssl: nil, headers: {}, user_agent: nil, cookie: nil, user: nil, password: nil, **kwargs) ⇒ Boolean

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

The HTTP method to use for the request.

Parameters:

  • method (:copy, :delete, :get, :head, :lock, :mkcol, :move, :options, :patch, :post, :propfind, :proppatch, :put, :trace, :unlock) (defaults to: :head)
  • url (URI::HTTP, Addressable::URI, String)

    Optional URL to create the HTTP request for.

  • kwargs (Hash{Symbol => Object})

    Aditional keyword arguments and headers for #request.

  • proxy (String, URI::HTTP, Addressable::URI, nil) (defaults to: self.proxy)

    Optional proxy to use for the request.

  • headers (Hash{Symbol,String => String,Array}, nil) (defaults to: {})

    Additional headers to add to each request.

  • user_agent (String, :random, :chrome, :chrome_linux, :chrome_macos, :chrome_windows, :chrome_iphone, :chrome_ipad, :chrome_android, :firefox, :firefox_linux, :firefox_macos, :firefox_windows, :firefox_iphone, :firefox_ipad, :firefox_android, :safari, :safari_macos, :safari_iphone, :safari_ipad, :edge, :linux, :macos, :windows, :iphone, :ipad, :android, nil) (defaults to: nil)

    The default User-Agent value to add to each request.

  • cookie (Cookie, Hash, String, nil) (defaults to: nil)

    The default cookie params to add to each request.

  • user (String, nil) (defaults to: nil)

    The HTTP Basic-Auth user to add to each request.

  • password (String, nil) (defaults to: nil)

    The HTTP Basic-Auth password to add to each request.

  • ssl (Boolean, Hash{Symbol => Object}, nil) (defaults to: nil)

    Specifies whether to enable SSL and/or the SSL context configuration.

Options Hash (ssl:):

  • :ca_bundle (String, nil)

    The path to the CA bundle directory or file.

  • :cert (Crypto::Cert, OpenSSL::X509::Certificate, nil)

    The certificate to use for the SSL/TLS connection.

  • :cert_store (OpenSSL::X509::Store, nil)

    The certificate store to use for the SSL/TLS connection.

  • :ciphers (Array<(name, version, bits, alg_bits)>, nil)

    The accepted ciphers to use for the SSL/TLS connection.

  • :extra_chain_cert (Crypto::Cert, OpenSSL::X509::Certificate, nil)

    The extra certificate to add to the SSL/TLS certificate chain.

  • :key (Crypto::Key::RSA, Crypto::Key::DSA, OpenSSL::PKey::RSA, OpenSSL::PKey::DSA, nil)

    The RSA or DSA key to use for the SSL/TLS connection.

  • :timeout (Integer, nil)

    The connection timeout limit.

  • :version (1, 1.1, 1.2, Symbol, nil)

    The desired SSL/TLS version.

  • :min_version (1, 1.1, 1.2, Symbol, nil)

    The minimum SSL/TLS version.

  • :max_version (1, 1.1, 1.2, Symbol, nil)

    The maximum SSL/TLS version.

  • :verify_callback (Proc, nil)

    The callback to use when verifying the server's certificate.

  • :verify_depth (Integer, nil)

    The verification depth limit.

  • :verify (:none, :peer, :fail_if_no_peer_cert, true, false, Integer, nil)

    The verification mode.

  • :verify_hostname (Boolean, nil)

    Indicates whether to verify the server's hostname.

Options Hash (**kwargs):

  • :query (String, nil)

    The query-string to append to the request path.

  • :query_params (Hash, nil)

    The query-params to append to the request path.

  • :user (String, nil)

    The user to authenticate as.

  • :password (String, nil)

    The password to authenticate with.

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

    Additional HTTP header names and values to add to the request.

  • :content_type (String, :text, :xml, :html, :json, nil)

    The Content-Type header value for the request. If a Symbol is given it will be resolved to a common MIME type:

    • :text - text/plain
    • :xml - text/xml
    • :html - text/html
    • :json - application/json
  • :accept (String, :text, :xml, :html, :json, nil)

    The Accept header value for the request. If a Symbol is given it will be resolved to a common MIME type:

    • :text - text/plain
    • :xml - text/xml
    • :html - text/html
    • :json - application/json
  • :cookie (String, Hash{String => String}, Cookie, nil)

    Additional Cookie header. If a Hash is given, it will be converted to a String using Cookie. If the cookie value is empty, the Cookie header will not be set.

  • :body (String, nil)

    The body of the request.

  • :form_data (Hash, String, nil)

    The form data that may be sent in the body of the request.

  • :json (#to_json, nil)

    The JSON data that will be sent in the body of the request. Will also default the Content-Type header to application/json, unless already set.

Returns:

  • (Boolean)

    Indicates that the response status was 200.

See Also:

Since:

  • 1.0.0



1611
1612
1613
1614
1615
1616
1617
1618
1619
1620
1621
1622
1623
1624
1625
1626
1627
1628
1629
1630
1631
1632
1633
1634
1635
1636
1637
1638
# File 'lib/ronin/support/network/http.rb', line 1611

def self.ok?(method=:head,url, proxy:      self.proxy,
                               ssl:        nil,
                               headers:    {},
                               user_agent: nil,
                               cookie:     nil,
                               user:       nil,
                               password:   nil,
                               **kwargs)
  uri  = case url
         when Addressable::URI, URI::HTTP
           url
         when String
           Addressable::URI.parse(url)
         else
           raise(ArgumentError,"URL argument must be either a Addressable::URI, URI::HTTP, or a String: #{url.inspect}")
         end

  path = uri.request_uri
  http = connect_uri(url, proxy:      proxy,
                          ssl:        ssl,
                          headers:    headers,
                          user_agent: user_agent,
                          cookie:     cookie,
                          user:       user,
                          password:   password)

  http.ok?(method,path,**kwargs)
end

.options(url, proxy: self.proxy, ssl: nil, headers: {}, user_agent: nil, cookie: nil, user: nil, password: nil, **kwargs) {|response| ... } ⇒ Net::HTTPResponse

Performs a OPTIONS request for the given URI.

Parameters:

  • url (URI::HTTP, Addressable::URI, String)

    Optional URL to create the HTTP request for.

  • kwargs (Hash{Symbol => Object})

    Aditional keyword arguments and headers for #request.

  • proxy (String, URI::HTTP, Addressable::URI, nil) (defaults to: self.proxy)

    Optional proxy to use for the request.

  • headers (Hash{Symbol,String => String,Array}, nil) (defaults to: {})

    Additional headers to add to each request.

  • user_agent (String, :random, :chrome, :chrome_linux, :chrome_macos, :chrome_windows, :chrome_iphone, :chrome_ipad, :chrome_android, :firefox, :firefox_linux, :firefox_macos, :firefox_windows, :firefox_iphone, :firefox_ipad, :firefox_android, :safari, :safari_macos, :safari_iphone, :safari_ipad, :edge, :linux, :macos, :windows, :iphone, :ipad, :android, nil) (defaults to: nil)

    The default User-Agent value to add to each request.

  • cookie (Cookie, Hash, String, nil) (defaults to: nil)

    The default cookie params to add to each request.

  • user (String, nil) (defaults to: nil)

    The HTTP Basic-Auth user to add to each request.

  • password (String, nil) (defaults to: nil)

    The HTTP Basic-Auth password to add to each request.

  • ssl (Boolean, Hash{Symbol => Object}, nil) (defaults to: nil)

    Specifies whether to enable SSL and/or the SSL context configuration.

Options Hash (ssl:):

  • :ca_bundle (String, nil)

    The path to the CA bundle directory or file.

  • :cert (Crypto::Cert, OpenSSL::X509::Certificate, nil)

    The certificate to use for the SSL/TLS connection.

  • :cert_store (OpenSSL::X509::Store, nil)

    The certificate store to use for the SSL/TLS connection.

  • :ciphers (Array<(name, version, bits, alg_bits)>, nil)

    The accepted ciphers to use for the SSL/TLS connection.

  • :extra_chain_cert (Crypto::Cert, OpenSSL::X509::Certificate, nil)

    The extra certificate to add to the SSL/TLS certificate chain.

  • :key (Crypto::Key::RSA, Crypto::Key::DSA, OpenSSL::PKey::RSA, OpenSSL::PKey::DSA, nil)

    The RSA or DSA key to use for the SSL/TLS connection.

  • :timeout (Integer, nil)

    The connection timeout limit.

  • :version (1, 1.1, 1.2, Symbol, nil)

    The desired SSL/TLS version.

  • :min_version (1, 1.1, 1.2, Symbol, nil)

    The minimum SSL/TLS version.

  • :max_version (1, 1.1, 1.2, Symbol, nil)

    The maximum SSL/TLS version.

  • :verify_callback (Proc, nil)

    The callback to use when verifying the server's certificate.

  • :verify_depth (Integer, nil)

    The verification depth limit.

  • :verify (:none, :peer, :fail_if_no_peer_cert, true, false, Integer, nil)

    The verification mode.

  • :verify_hostname (Boolean, nil)

    Indicates whether to verify the server's hostname.

Options Hash (**kwargs):

  • :query (String, nil)

    The query-string to append to the request path.

  • :query_params (Hash, nil)

    The query-params to append to the request path.

  • :user (String, nil)

    The user to authenticate as.

  • :password (String, nil)

    The password to authenticate with.

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

    Additional HTTP header names and values to add to the request.

  • :content_type (String, :text, :xml, :html, :json, nil)

    The Content-Type header value for the request. If a Symbol is given it will be resolved to a common MIME type:

    • :text - text/plain
    • :xml - text/xml
    • :html - text/html
    • :json - application/json
  • :accept (String, :text, :xml, :html, :json, nil)

    The Accept header value for the request. If a Symbol is given it will be resolved to a common MIME type:

    • :text - text/plain
    • :xml - text/xml
    • :html - text/html
    • :json - application/json
  • :cookie (String, Hash{String => String}, Cookie, nil)

    Additional Cookie header. If a Hash is given, it will be converted to a String using Cookie. If the cookie value is empty, the Cookie header will not be set.

  • :body (String, nil)

    The body of the request.

  • :form_data (Hash, String, nil)

    The form data that may be sent in the body of the request.

  • :json (#to_json, nil)

    The JSON data that will be sent in the body of the request. Will also default the Content-Type header to application/json, unless already set.

Yields:

  • (response)

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

Yield Parameters:

  • response (Net::HTTPRresponse)

    The received HTTP response object.

Returns:

  • (Net::HTTPResponse)

    The new HTTP Request object.

See Also:

Since:

  • 1.0.0



2368
2369
2370
2371
2372
2373
2374
2375
2376
2377
2378
2379
2380
2381
2382
2383
2384
2385
2386
2387
2388
2389
2390
2391
2392
2393
2394
2395
2396
# File 'lib/ronin/support/network/http.rb', line 2368

def self.options(url, proxy:      self.proxy,
                      ssl:        nil,
                      headers:    {},
                      user_agent: nil,
                      cookie:     nil,
                      user:       nil,
                      password:   nil,
                      **kwargs,
                      &block)
  uri = case url
        when Addressable::URI, URI::HTTP
          url
        when String
          Addressable::URI.parse(url)
        else
          raise(ArgumentError,"URL argument must be either a Addressable::URI, URI::HTTP, or a String: #{url.inspect}")
        end

  path = uri.request_uri
  http = connect_uri(url, proxy:      proxy,
                          ssl:        ssl,
                          headers:    headers,
                          user_agent: user_agent,
                          cookie:     cookie,
                          user:       user,
                          password:   password)

  http.options(path,**kwargs,&block)
end

.patch(url, proxy: self.proxy, ssl: nil, headers: {}, user_agent: nil, cookie: nil, user: nil, password: nil, **kwargs) {|response| ... } ⇒ Net::HTTPResponse

Performs a PATCH request for the given URI.

Parameters:

  • url (URI::HTTP, Addressable::URI, String)

    Optional URL to create the HTTP request for.

  • kwargs (Hash{Symbol => Object})

    Aditional keyword arguments and headers for #request.

  • proxy (String, URI::HTTP, Addressable::URI, nil) (defaults to: self.proxy)

    Optional proxy to use for the request.

  • headers (Hash{Symbol,String => String,Array}, nil) (defaults to: {})

    Additional headers to add to each request.

  • user_agent (String, :random, :chrome, :chrome_linux, :chrome_macos, :chrome_windows, :chrome_iphone, :chrome_ipad, :chrome_android, :firefox, :firefox_linux, :firefox_macos, :firefox_windows, :firefox_iphone, :firefox_ipad, :firefox_android, :safari, :safari_macos, :safari_iphone, :safari_ipad, :edge, :linux, :macos, :windows, :iphone, :ipad, :android, nil) (defaults to: nil)

    The default User-Agent value to add to each request.

  • cookie (Cookie, Hash, String, nil) (defaults to: nil)

    The default cookie params to add to each request.

  • user (String, nil) (defaults to: nil)

    The HTTP Basic-Auth user to add to each request.

  • password (String, nil) (defaults to: nil)

    The HTTP Basic-Auth password to add to each request.

  • ssl (Boolean, Hash{Symbol => Object}, nil) (defaults to: nil)

    Specifies whether to enable SSL and/or the SSL context configuration.

Options Hash (ssl:):

  • :ca_bundle (String, nil)

    The path to the CA bundle directory or file.

  • :cert (Crypto::Cert, OpenSSL::X509::Certificate, nil)

    The certificate to use for the SSL/TLS connection.

  • :cert_store (OpenSSL::X509::Store, nil)

    The certificate store to use for the SSL/TLS connection.

  • :ciphers (Array<(name, version, bits, alg_bits)>, nil)

    The accepted ciphers to use for the SSL/TLS connection.

  • :extra_chain_cert (Crypto::Cert, OpenSSL::X509::Certificate, nil)

    The extra certificate to add to the SSL/TLS certificate chain.

  • :key (Crypto::Key::RSA, Crypto::Key::DSA, OpenSSL::PKey::RSA, OpenSSL::PKey::DSA, nil)

    The RSA or DSA key to use for the SSL/TLS connection.

  • :timeout (Integer, nil)

    The connection timeout limit.

  • :version (1, 1.1, 1.2, Symbol, nil)

    The desired SSL/TLS version.

  • :min_version (1, 1.1, 1.2, Symbol, nil)

    The minimum SSL/TLS version.

  • :max_version (1, 1.1, 1.2, Symbol, nil)

    The maximum SSL/TLS version.

  • :verify_callback (Proc, nil)

    The callback to use when verifying the server's certificate.

  • :verify_depth (Integer, nil)

    The verification depth limit.

  • :verify (:none, :peer, :fail_if_no_peer_cert, true, false, Integer, nil)

    The verification mode.

  • :verify_hostname (Boolean, nil)

    Indicates whether to verify the server's hostname.

Options Hash (**kwargs):

  • :query (String, nil)

    The query-string to append to the request path.

  • :query_params (Hash, nil)

    The query-params to append to the request path.

  • :user (String, nil)

    The user to authenticate as.

  • :password (String, nil)

    The password to authenticate with.

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

    Additional HTTP header names and values to add to the request.

  • :content_type (String, :text, :xml, :html, :json, nil)

    The Content-Type header value for the request. If a Symbol is given it will be resolved to a common MIME type:

    • :text - text/plain
    • :xml - text/xml
    • :html - text/html
    • :json - application/json
  • :accept (String, :text, :xml, :html, :json, nil)

    The Accept header value for the request. If a Symbol is given it will be resolved to a common MIME type:

    • :text - text/plain
    • :xml - text/xml
    • :html - text/html
    • :json - application/json
  • :cookie (String, Hash{String => String}, Cookie, nil)

    Additional Cookie header. If a Hash is given, it will be converted to a String using Cookie. If the cookie value is empty, the Cookie header will not be set.

  • :body (String, nil)

    The body of the request.

  • :form_data (Hash, String, nil)

    The form data that may be sent in the body of the request.

  • :json (#to_json, nil)

    The JSON data that will be sent in the body of the request. Will also default the Content-Type header to application/json, unless already set.

Yields:

  • (response)

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

Yield Parameters:

  • response (Net::HTTPRresponse)

    The received HTTP response object.

Returns:

  • (Net::HTTPResponse)

    The new HTTP Request object.

See Also:

Since:

  • 1.0.0



2468
2469
2470
2471
2472
2473
2474
2475
2476
2477
2478
2479
2480
2481
2482
2483
2484
2485
2486
2487
2488
2489
2490
2491
2492
2493
2494
2495
2496
# File 'lib/ronin/support/network/http.rb', line 2468

def self.patch(url, proxy:      self.proxy,
                    ssl:        nil,
                    headers:    {},
                    user_agent: nil,
                    cookie:     nil,
                    user:       nil,
                    password:   nil,
                    **kwargs,
                    &block)
  uri = case url
        when Addressable::URI, URI::HTTP
          url
        when String
          Addressable::URI.parse(url)
        else
          raise(ArgumentError,"URL argument must be either a Addressable::URI, URI::HTTP, or a String: #{url.inspect}")
        end

  path = uri.request_uri
  http = connect_uri(url, proxy:      proxy,
                          ssl:        ssl,
                          headers:    headers,
                          user_agent: user_agent,
                          cookie:     cookie,
                          user:       user,
                          password:   password)

  http.patch(path,**kwargs,&block)
end

.post(url, proxy: self.proxy, ssl: nil, headers: {}, user_agent: nil, cookie: nil, user: nil, password: nil, **kwargs) {|response| ... } ⇒ Net::HTTPResponse

Performs a POST request for the given URI.

Parameters:

  • url (URI::HTTP, Addressable::URI, String)

    Optional URL to create the HTTP request for.

  • kwargs (Hash{Symbol => Object})

    Aditional keyword arguments and headers for #request.

  • proxy (String, URI::HTTP, Addressable::URI, nil) (defaults to: self.proxy)

    Optional proxy to use for the request.

  • headers (Hash{Symbol,String => String,Array}, nil) (defaults to: {})

    Additional headers to add to each request.

  • user_agent (String, :random, :chrome, :chrome_linux, :chrome_macos, :chrome_windows, :chrome_iphone, :chrome_ipad, :chrome_android, :firefox, :firefox_linux, :firefox_macos, :firefox_windows, :firefox_iphone, :firefox_ipad, :firefox_android, :safari, :safari_macos, :safari_iphone, :safari_ipad, :edge, :linux, :macos, :windows, :iphone, :ipad, :android, nil) (defaults to: nil)

    The default User-Agent value to add to each request.

  • cookie (Cookie, Hash, String, nil) (defaults to: nil)

    The default cookie params to add to each request.

  • user (String, nil) (defaults to: nil)

    The HTTP Basic-Auth user to add to each request.

  • password (String, nil) (defaults to: nil)

    The HTTP Basic-Auth password to add to each request.

  • ssl (Boolean, Hash{Symbol => Object}, nil) (defaults to: nil)

    Specifies whether to enable SSL and/or the SSL context configuration.

Options Hash (ssl:):

  • :ca_bundle (String, nil)

    The path to the CA bundle directory or file.

  • :cert (Crypto::Cert, OpenSSL::X509::Certificate, nil)

    The certificate to use for the SSL/TLS connection.

  • :cert_store (OpenSSL::X509::Store, nil)

    The certificate store to use for the SSL/TLS connection.

  • :ciphers (Array<(name, version, bits, alg_bits)>, nil)

    The accepted ciphers to use for the SSL/TLS connection.

  • :extra_chain_cert (Crypto::Cert, OpenSSL::X509::Certificate, nil)

    The extra certificate to add to the SSL/TLS certificate chain.

  • :key (Crypto::Key::RSA, Crypto::Key::DSA, OpenSSL::PKey::RSA, OpenSSL::PKey::DSA, nil)

    The RSA or DSA key to use for the SSL/TLS connection.

  • :timeout (Integer, nil)

    The connection timeout limit.

  • :version (1, 1.1, 1.2, Symbol, nil)

    The desired SSL/TLS version.

  • :min_version (1, 1.1, 1.2, Symbol, nil)

    The minimum SSL/TLS version.

  • :max_version (1, 1.1, 1.2, Symbol, nil)

    The maximum SSL/TLS version.

  • :verify_callback (Proc, nil)

    The callback to use when verifying the server's certificate.

  • :verify_depth (Integer, nil)

    The verification depth limit.

  • :verify (:none, :peer, :fail_if_no_peer_cert, true, false, Integer, nil)

    The verification mode.

  • :verify_hostname (Boolean, nil)

    Indicates whether to verify the server's hostname.

Options Hash (**kwargs):

  • :query (String, nil)

    The query-string to append to the request path.

  • :query_params (Hash, nil)

    The query-params to append to the request path.

  • :user (String, nil)

    The user to authenticate as.

  • :password (String, nil)

    The password to authenticate with.

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

    Additional HTTP header names and values to add to the request.

  • :content_type (String, :text, :xml, :html, :json, nil)

    The Content-Type header value for the request. If a Symbol is given it will be resolved to a common MIME type:

    • :text - text/plain
    • :xml - text/xml
    • :html - text/html
    • :json - application/json
  • :accept (String, :text, :xml, :html, :json, nil)

    The Accept header value for the request. If a Symbol is given it will be resolved to a common MIME type:

    • :text - text/plain
    • :xml - text/xml
    • :html - text/html
    • :json - application/json
  • :cookie (String, Hash{String => String}, Cookie, nil)

    Additional Cookie header. If a Hash is given, it will be converted to a String using Cookie. If the cookie value is empty, the Cookie header will not be set.

  • :body (String, nil)

    The body of the request.

  • :form_data (Hash, String, nil)

    The form data that may be sent in the body of the request.

  • :json (#to_json, nil)

    The JSON data that will be sent in the body of the request. Will also default the Content-Type header to application/json, unless already set.

Yields:

  • (response)

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

Yield Parameters:

  • response (Net::HTTPRresponse)

    The received HTTP response object.

Returns:

  • (Net::HTTPResponse)

    The new HTTP Request object.

See Also:

Since:

  • 1.0.0



2521
2522
2523
2524
2525
2526
2527
2528
2529
2530
2531
2532
2533
2534
2535
2536
2537
2538
2539
2540
2541
2542
2543
2544
2545
2546
2547
2548
2549
# File 'lib/ronin/support/network/http.rb', line 2521

def self.post(url, proxy:      self.proxy,
                   ssl:        nil,
                   headers:    {},
                   user_agent: nil,
                   cookie:     nil,
                   user:       nil,
                   password:   nil,
                   **kwargs,
                   &block)
  uri = case url
        when Addressable::URI, URI::HTTP
          url
        when String
          Addressable::URI.parse(url)
        else
          raise(ArgumentError,"URL argument must be either a Addressable::URI, URI::HTTP, or a String: #{url.inspect}")
        end

  path = uri.request_uri
  http = connect_uri(url, proxy:      proxy,
                          ssl:        ssl,
                          headers:    headers,
                          user_agent: user_agent,
                          cookie:     cookie,
                          user:       user,
                          password:   password)

  http.post(path,**kwargs,&block)
end

.post_body(url, proxy: self.proxy, ssl: nil, headers: {}, user_agent: nil, cookie: nil, user: nil, password: nil, **kwargs) ⇒ String

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

Parameters:

  • url (URI::HTTP, Addressable::URI, String)

    Optional URL to create the HTTP request for.

  • kwargs (Hash{Symbol => Object})

    Aditional keyword arguments and headers for #request.

  • proxy (String, URI::HTTP, Addressable::URI, nil) (defaults to: self.proxy)

    Optional proxy to use for the request.

  • headers (Hash{Symbol,String => String,Array}, nil) (defaults to: {})

    Additional headers to add to each request.

  • user_agent (String, :random, :chrome, :chrome_linux, :chrome_macos, :chrome_windows, :chrome_iphone, :chrome_ipad, :chrome_android, :firefox, :firefox_linux, :firefox_macos, :firefox_windows, :firefox_iphone, :firefox_ipad, :firefox_android, :safari, :safari_macos, :safari_iphone, :safari_ipad, :edge, :linux, :macos, :windows, :iphone, :ipad, :android, nil) (defaults to: nil)

    The default User-Agent value to add to each request.

  • cookie (Cookie, Hash, String, nil) (defaults to: nil)

    The default cookie params to add to each request.

  • user (String, nil) (defaults to: nil)

    The HTTP Basic-Auth user to add to each request.

  • password (String, nil) (defaults to: nil)

    The HTTP Basic-Auth password to add to each request.

  • ssl (Boolean, Hash{Symbol => Object}, nil) (defaults to: nil)

    Specifies whether to enable SSL and/or the SSL context configuration.

Options Hash (ssl:):

  • :ca_bundle (String, nil)

    The path to the CA bundle directory or file.

  • :cert (Crypto::Cert, OpenSSL::X509::Certificate, nil)

    The certificate to use for the SSL/TLS connection.

  • :cert_store (OpenSSL::X509::Store, nil)

    The certificate store to use for the SSL/TLS connection.

  • :ciphers (Array<(name, version, bits, alg_bits)>, nil)

    The accepted ciphers to use for the SSL/TLS connection.

  • :extra_chain_cert (Crypto::Cert, OpenSSL::X509::Certificate, nil)

    The extra certificate to add to the SSL/TLS certificate chain.

  • :key (Crypto::Key::RSA, Crypto::Key::DSA, OpenSSL::PKey::RSA, OpenSSL::PKey::DSA, nil)

    The RSA or DSA key to use for the SSL/TLS connection.

  • :timeout (Integer, nil)

    The connection timeout limit.

  • :version (1, 1.1, 1.2, Symbol, nil)

    The desired SSL/TLS version.

  • :min_version (1, 1.1, 1.2, Symbol, nil)

    The minimum SSL/TLS version.

  • :max_version (1, 1.1, 1.2, Symbol, nil)

    The maximum SSL/TLS version.

  • :verify_callback (Proc, nil)

    The callback to use when verifying the server's certificate.

  • :verify_depth (Integer, nil)

    The verification depth limit.

  • :verify (:none, :peer, :fail_if_no_peer_cert, true, false, Integer, nil)

    The verification mode.

  • :verify_hostname (Boolean, nil)

    Indicates whether to verify the server's hostname.

Options Hash (**kwargs):

  • :query (String, nil)

    The query-string to append to the request path.

  • :query_params (Hash, nil)

    The query-params to append to the request path.

  • :user (String, nil)

    The user to authenticate as.

  • :password (String, nil)

    The password to authenticate with.

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

    Additional HTTP header names and values to add to the request.

  • :content_type (String, :text, :xml, :html, :json, nil)

    The Content-Type header value for the request. If a Symbol is given it will be resolved to a common MIME type:

    • :text - text/plain
    • :xml - text/xml
    • :html - text/html
    • :json - application/json
  • :accept (String, :text, :xml, :html, :json, nil)

    The Accept header value for the request. If a Symbol is given it will be resolved to a common MIME type:

    • :text - text/plain
    • :xml - text/xml
    • :html - text/html
    • :json - application/json
  • :cookie (String, Hash{String => String}, Cookie, nil)

    Additional Cookie header. If a Hash is given, it will be converted to a String using Cookie. If the cookie value is empty, the Cookie header will not be set.

  • :body (String, nil)

    The body of the request.

  • :form_data (Hash, String, nil)

    The form data that may be sent in the body of the request.

  • :json (#to_json, nil)

    The JSON data that will be sent in the body of the request. Will also default the Content-Type header to application/json, unless already set.

Returns:

  • (String)

    The response body.

See Also:

Since:

  • 1.0.0



2616
2617
2618
2619
2620
2621
2622
2623
2624
2625
2626
2627
2628
2629
2630
2631
2632
2633
2634
2635
2636
2637
2638
2639
2640
2641
2642
2643
# File 'lib/ronin/support/network/http.rb', line 2616

def self.post_body(url, proxy:      self.proxy,
                        ssl:        nil,
                        headers:    {},
                        user_agent: nil,
                        cookie:     nil,
                        user:       nil,
                        password:   nil,
                        **kwargs)
  uri = case url
        when Addressable::URI, URI::HTTP
          url
        when String
          Addressable::URI.parse(url)
        else
          raise(ArgumentError,"URL argument must be either a Addressable::URI, URI::HTTP, or a String: #{url.inspect}")
        end

  path = uri.request_uri
  http = connect_uri(url, proxy:      proxy,
                          ssl:        ssl,
                          headers:    headers,
                          user_agent: user_agent,
                          cookie:     cookie,
                          user:       user,
                          password:   password)

  http.post_body(path,**kwargs)
end

.post_cookies(url, proxy: self.proxy, ssl: nil, headers: {}, user_agent: nil, cookie: nil, user: nil, password: nil, **kwargs, &block) ⇒ Array<SetCookie>?

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

Parameters:

  • url (URI::HTTP, Addressable::URI, String)

    Optional URL to create the HTTP request for.

  • kwargs (Hash{Symbol => Object})

    Aditional keyword arguments and headers for #request.

  • proxy (String, URI::HTTP, Addressable::URI, nil) (defaults to: self.proxy)

    Optional proxy to use for the request.

  • headers (Hash{Symbol,String => String,Array}, nil) (defaults to: {})

    Additional headers to add to each request.

  • user_agent (String, :random, :chrome, :chrome_linux, :chrome_macos, :chrome_windows, :chrome_iphone, :chrome_ipad, :chrome_android, :firefox, :firefox_linux, :firefox_macos, :firefox_windows, :firefox_iphone, :firefox_ipad, :firefox_android, :safari, :safari_macos, :safari_iphone, :safari_ipad, :edge, :linux, :macos, :windows, :iphone, :ipad, :android, nil) (defaults to: nil)

    The default User-Agent value to add to each request.

  • cookie (Cookie, Hash, String, nil) (defaults to: nil)

    The default cookie params to add to each request.

  • user (String, nil) (defaults to: nil)

    The HTTP Basic-Auth user to add to each request.

  • password (String, nil) (defaults to: nil)

    The HTTP Basic-Auth password to add to each request.

  • ssl (Boolean, Hash{Symbol => Object}, nil) (defaults to: nil)

    Specifies whether to enable SSL and/or the SSL context configuration.

Options Hash (ssl:):

  • :ca_bundle (String, nil)

    The path to the CA bundle directory or file.

  • :cert (Crypto::Cert, OpenSSL::X509::Certificate, nil)

    The certificate to use for the SSL/TLS connection.

  • :cert_store (OpenSSL::X509::Store, nil)

    The certificate store to use for the SSL/TLS connection.

  • :ciphers (Array<(name, version, bits, alg_bits)>, nil)

    The accepted ciphers to use for the SSL/TLS connection.

  • :extra_chain_cert (Crypto::Cert, OpenSSL::X509::Certificate, nil)

    The extra certificate to add to the SSL/TLS certificate chain.

  • :key (Crypto::Key::RSA, Crypto::Key::DSA, OpenSSL::PKey::RSA, OpenSSL::PKey::DSA, nil)

    The RSA or DSA key to use for the SSL/TLS connection.

  • :timeout (Integer, nil)

    The connection timeout limit.

  • :version (1, 1.1, 1.2, Symbol, nil)

    The desired SSL/TLS version.

  • :min_version (1, 1.1, 1.2, Symbol, nil)

    The minimum SSL/TLS version.

  • :max_version (1, 1.1, 1.2, Symbol, nil)

    The maximum SSL/TLS version.

  • :verify_callback (Proc, nil)

    The callback to use when verifying the server's certificate.

  • :verify_depth (Integer, nil)

    The verification depth limit.

  • :verify (:none, :peer, :fail_if_no_peer_cert, true, false, Integer, nil)

    The verification mode.

  • :verify_hostname (Boolean, nil)

    Indicates whether to verify the server's hostname.

Options Hash (**kwargs):

  • :query (String, nil)

    The query-string to append to the request path.

  • :query_params (Hash, nil)

    The query-params to append to the request path.

  • :user (String, nil)

    The user to authenticate as.

  • :password (String, nil)

    The password to authenticate with.

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

    Additional HTTP header names and values to add to the request.

  • :content_type (String, :text, :xml, :html, :json, nil)

    The Content-Type header value for the request. If a Symbol is given it will be resolved to a common MIME type:

    • :text - text/plain
    • :xml - text/xml
    • :html - text/html
    • :json - application/json
  • :accept (String, :text, :xml, :html, :json, nil)

    The Accept header value for the request. If a Symbol is given it will be resolved to a common MIME type:

    • :text - text/plain
    • :xml - text/xml
    • :html - text/html
    • :json - application/json
  • :cookie (String, Hash{String => String}, Cookie, nil)

    Additional Cookie header. If a Hash is given, it will be converted to a String using Cookie. If the cookie value is empty, the Cookie header will not be set.

  • :body (String, nil)

    The body of the request.

  • :form_data (Hash, String, nil)

    The form data that may be sent in the body of the request.

  • :json (#to_json, nil)

    The JSON data that will be sent in the body of the request. Will also default the Content-Type header to application/json, unless already set.

Returns:

See Also:

Since:

  • 1.1.0



2927
2928
2929
2930
2931
2932
2933
2934
2935
2936
2937
2938
2939
2940
2941
2942
2943
2944
2945
2946
2947
2948
2949
2950
2951
2952
2953
2954
2955
# File 'lib/ronin/support/network/http.rb', line 2927

def self.post_cookies(url, proxy:      self.proxy,
                           ssl:        nil,
                           headers:    {},
                           user_agent: nil,
                           cookie:     nil,
                           user:       nil,
                           password:   nil,
                           **kwargs,
                           &block)
  uri = case url
        when Addressable::URI, URI::HTTP
          url
        when String
          Addressable::URI.parse(url)
        else
          raise(ArgumentError,"URL argument must be either a Addressable::URI, URI::HTTP, or a String: #{url.inspect}")
        end

  path = uri.request_uri
  http = connect_uri(url, proxy:      proxy,
                          ssl:        ssl,
                          headers:    headers,
                          user_agent: user_agent,
                          cookie:     cookie,
                          user:       user,
                          password:   password)

  http.post_cookies(path,**kwargs)
end

.post_headers(url, proxy: self.proxy, ssl: nil, headers: {}, user_agent: nil, cookie: nil, user: nil, password: nil, **kwargs) ⇒ Hash{String => String}

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

Parameters:

  • url (URI::HTTP, Addressable::URI, String)

    Optional URL to create the HTTP request for.

  • kwargs (Hash{Symbol => Object})

    Aditional keyword arguments and headers for #request.

  • proxy (String, URI::HTTP, Addressable::URI, nil) (defaults to: self.proxy)

    Optional proxy to use for the request.

  • headers (Hash{Symbol,String => String,Array}, nil) (defaults to: {})

    Additional headers to add to each request.

  • user_agent (String, :random, :chrome, :chrome_linux, :chrome_macos, :chrome_windows, :chrome_iphone, :chrome_ipad, :chrome_android, :firefox, :firefox_linux, :firefox_macos, :firefox_windows, :firefox_iphone, :firefox_ipad, :firefox_android, :safari, :safari_macos, :safari_iphone, :safari_ipad, :edge, :linux, :macos, :windows, :iphone, :ipad, :android, nil) (defaults to: nil)

    The default User-Agent value to add to each request.

  • cookie (Cookie, Hash, String, nil) (defaults to: nil)

    The default cookie params to add to each request.

  • user (String, nil) (defaults to: nil)

    The HTTP Basic-Auth user to add to each request.

  • password (String, nil) (defaults to: nil)

    The HTTP Basic-Auth password to add to each request.

  • ssl (Boolean, Hash{Symbol => Object}, nil) (defaults to: nil)

    Specifies whether to enable SSL and/or the SSL context configuration.

Options Hash (ssl:):

  • :ca_bundle (String, nil)

    The path to the CA bundle directory or file.

  • :cert (Crypto::Cert, OpenSSL::X509::Certificate, nil)

    The certificate to use for the SSL/TLS connection.

  • :cert_store (OpenSSL::X509::Store, nil)

    The certificate store to use for the SSL/TLS connection.

  • :ciphers (Array<(name, version, bits, alg_bits)>, nil)

    The accepted ciphers to use for the SSL/TLS connection.

  • :extra_chain_cert (Crypto::Cert, OpenSSL::X509::Certificate, nil)

    The extra certificate to add to the SSL/TLS certificate chain.

  • :key (Crypto::Key::RSA, Crypto::Key::DSA, OpenSSL::PKey::RSA, OpenSSL::PKey::DSA, nil)

    The RSA or DSA key to use for the SSL/TLS connection.

  • :timeout (Integer, nil)

    The connection timeout limit.

  • :version (1, 1.1, 1.2, Symbol, nil)

    The desired SSL/TLS version.

  • :min_version (1, 1.1, 1.2, Symbol, nil)

    The minimum SSL/TLS version.

  • :max_version (1, 1.1, 1.2, Symbol, nil)

    The maximum SSL/TLS version.

  • :verify_callback (Proc, nil)

    The callback to use when verifying the server's certificate.

  • :verify_depth (Integer, nil)

    The verification depth limit.

  • :verify (:none, :peer, :fail_if_no_peer_cert, true, false, Integer, nil)

    The verification mode.

  • :verify_hostname (Boolean, nil)

    Indicates whether to verify the server's hostname.

Options Hash (**kwargs):

  • :query (String, nil)

    The query-string to append to the request path.

  • :query_params (Hash, nil)

    The query-params to append to the request path.

  • :user (String, nil)

    The user to authenticate as.

  • :password (String, nil)

    The password to authenticate with.

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

    Additional HTTP header names and values to add to the request.

  • :content_type (String, :text, :xml, :html, :json, nil)

    The Content-Type header value for the request. If a Symbol is given it will be resolved to a common MIME type:

    • :text - text/plain
    • :xml - text/xml
    • :html - text/html
    • :json - application/json
  • :accept (String, :text, :xml, :html, :json, nil)

    The Accept header value for the request. If a Symbol is given it will be resolved to a common MIME type:

    • :text - text/plain
    • :xml - text/xml
    • :html - text/html
    • :json - application/json
  • :cookie (String, Hash{String => String}, Cookie, nil)

    Additional Cookie header. If a Hash is given, it will be converted to a String using Cookie. If the cookie value is empty, the Cookie header will not be set.

  • :body (String, nil)

    The body of the request.

  • :form_data (Hash, String, nil)

    The form data that may be sent in the body of the request.

  • :json (#to_json, nil)

    The JSON data that will be sent in the body of the request. Will also default the Content-Type header to application/json, unless already set.

Returns:

See Also:

Since:

  • 1.0.0



2569
2570
2571
2572
2573
2574
2575
2576
2577
2578
2579
2580
2581
2582
2583
2584
2585
2586
2587
2588
2589
2590
2591
2592
2593
2594
2595
2596
# File 'lib/ronin/support/network/http.rb', line 2569

def self.post_headers(url, proxy:      self.proxy,
                           ssl:        nil,
                           headers:    {},
                           user_agent: nil,
                           cookie:     nil,
                           user:       nil,
                           password:   nil,
                           **kwargs)
  uri = case url
        when Addressable::URI, URI::HTTP
          url
        when String
          Addressable::URI.parse(url)
        else
          raise(ArgumentError,"URL argument must be either a Addressable::URI, URI::HTTP, or a String: #{url.inspect}")
        end

  path = uri.request_uri
  http = connect_uri(url, proxy:      proxy,
                          ssl:        ssl,
                          headers:    headers,
                          user_agent: user_agent,
                          cookie:     cookie,
                          user:       user,
                          password:   password)

  http.post_headers(path,**kwargs)
end

.powered_by_header(url, proxy: self.proxy, ssl: nil, headers: {}, user_agent: nil, cookie: nil, user: nil, password: nil, **kwargs) ⇒ String?

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

Parameters:

  • url (URI::HTTP, Addressable::URI, String)

    Optional URL to create the HTTP request for.

  • kwargs (Hash{Symbol => Object})

    Aditional keyword arguments and headers for #request.

  • proxy (String, URI::HTTP, Addressable::URI, nil) (defaults to: self.proxy)

    Optional proxy to use for the request.

  • headers (Hash{Symbol,String => String,Array}, nil) (defaults to: {})

    Additional headers to add to each request.

  • user_agent (String, :random, :chrome, :chrome_linux, :chrome_macos, :chrome_windows, :chrome_iphone, :chrome_ipad, :chrome_android, :firefox, :firefox_linux, :firefox_macos, :firefox_windows, :firefox_iphone, :firefox_ipad, :firefox_android, :safari, :safari_macos, :safari_iphone, :safari_ipad, :edge, :linux, :macos, :windows, :iphone, :ipad, :android, nil) (defaults to: nil)

    The default User-Agent value to add to each request.

  • cookie (Cookie, Hash, String, nil) (defaults to: nil)

    The default cookie params to add to each request.

  • user (String, nil) (defaults to: nil)

    The HTTP Basic-Auth user to add to each request.

  • password (String, nil) (defaults to: nil)

    The HTTP Basic-Auth password to add to each request.

  • ssl (Boolean, Hash{Symbol => Object}, nil) (defaults to: nil)

    Specifies whether to enable SSL and/or the SSL context configuration.

Options Hash (ssl:):

  • :ca_bundle (String, nil)

    The path to the CA bundle directory or file.

  • :cert (Crypto::Cert, OpenSSL::X509::Certificate, nil)

    The certificate to use for the SSL/TLS connection.

  • :cert_store (OpenSSL::X509::Store, nil)

    The certificate store to use for the SSL/TLS connection.

  • :ciphers (Array<(name, version, bits, alg_bits)>, nil)

    The accepted ciphers to use for the SSL/TLS connection.

  • :extra_chain_cert (Crypto::Cert, OpenSSL::X509::Certificate, nil)

    The extra certificate to add to the SSL/TLS certificate chain.

  • :key (Crypto::Key::RSA, Crypto::Key::DSA, OpenSSL::PKey::RSA, OpenSSL::PKey::DSA, nil)

    The RSA or DSA key to use for the SSL/TLS connection.

  • :timeout (Integer, nil)

    The connection timeout limit.

  • :version (1, 1.1, 1.2, Symbol, nil)

    The desired SSL/TLS version.

  • :min_version (1, 1.1, 1.2, Symbol, nil)

    The minimum SSL/TLS version.

  • :max_version (1, 1.1, 1.2, Symbol, nil)

    The maximum SSL/TLS version.

  • :verify_callback (Proc, nil)

    The callback to use when verifying the server's certificate.

  • :verify_depth (Integer, nil)

    The verification depth limit.

  • :verify (:none, :peer, :fail_if_no_peer_cert, true, false, Integer, nil)

    The verification mode.

  • :verify_hostname (Boolean, nil)

    Indicates whether to verify the server's hostname.

Options Hash (**kwargs):

  • :query (String, nil)

    The query-string to append to the request path.

  • :query_params (Hash, nil)

    The query-params to append to the request path.

  • :user (String, nil)

    The user to authenticate as.

  • :password (String, nil)

    The password to authenticate with.

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

    Additional HTTP header names and values to add to the request.

  • :content_type (String, :text, :xml, :html, :json, nil)

    The Content-Type header value for the request. If a Symbol is given it will be resolved to a common MIME type:

    • :text - text/plain
    • :xml - text/xml
    • :html - text/html
    • :json - application/json
  • :accept (String, :text, :xml, :html, :json, nil)

    The Accept header value for the request. If a Symbol is given it will be resolved to a common MIME type:

    • :text - text/plain
    • :xml - text/xml
    • :html - text/html
    • :json - application/json
  • :cookie (String, Hash{String => String}, Cookie, nil)

    Additional Cookie header. If a Hash is given, it will be converted to a String using Cookie. If the cookie value is empty, the Cookie header will not be set.

  • :body (String, nil)

    The body of the request.

  • :form_data (Hash, String, nil)

    The form data that may be sent in the body of the request.

  • :json (#to_json, nil)

    The JSON data that will be sent in the body of the request. Will also default the Content-Type header to application/json, unless already set.

Returns:

  • (String, nil)

    The X-Powered-By header.

See Also:

Since:

  • 1.0.0



1754
1755
1756
1757
1758
1759
1760
1761
1762
1763
1764
1765
1766
1767
1768
1769
1770
1771
1772
1773
1774
1775
1776
1777
1778
1779
1780
1781
# File 'lib/ronin/support/network/http.rb', line 1754

def self.powered_by_header(url, proxy:      self.proxy,
                                ssl:        nil,
                                headers:    {},
                                user_agent: nil,
                                cookie:     nil,
                                user:       nil,
                                password:   nil,
                                **kwargs)
  uri = case url
        when Addressable::URI, URI::HTTP
          url
        when String
          Addressable::URI.parse(url)
        else
          raise(ArgumentError,"URL argument must be either a Addressable::URI, URI::HTTP, or a String: #{url.inspect}")
        end

  path = uri.request_uri
  http = connect_uri(url, proxy:      proxy,
                          ssl:        ssl,
                          headers:    headers,
                          user_agent: user_agent,
                          cookie:     cookie,
                          user:       user,
                          password:   password)

  http.powered_by_header(path: path, **kwargs)
end

.propfind(url, proxy: self.proxy, ssl: nil, headers: {}, user_agent: nil, cookie: nil, user: nil, password: nil, **kwargs) {|response| ... } ⇒ Net::HTTPResponse

Performs a PROPFIND request for the given URI.

Parameters:

  • url (URI::HTTP, Addressable::URI, String)

    Optional URL to create the HTTP request for.

  • kwargs (Hash{Symbol => Object})

    Aditional keyword arguments and headers for #request.

  • proxy (String, URI::HTTP, Addressable::URI, nil) (defaults to: self.proxy)

    Optional proxy to use for the request.

  • headers (Hash{Symbol,String => String,Array}, nil) (defaults to: {})

    Additional headers to add to each request.

  • user_agent (String, :random, :chrome, :chrome_linux, :chrome_macos, :chrome_windows, :chrome_iphone, :chrome_ipad, :chrome_android, :firefox, :firefox_linux, :firefox_macos, :firefox_windows, :firefox_iphone, :firefox_ipad, :firefox_android, :safari, :safari_macos, :safari_iphone, :safari_ipad, :edge, :linux, :macos, :windows, :iphone, :ipad, :android, nil) (defaults to: nil)

    The default User-Agent value to add to each request.

  • cookie (Cookie, Hash, String, nil) (defaults to: nil)

    The default cookie params to add to each request.

  • user (String, nil) (defaults to: nil)

    The HTTP Basic-Auth user to add to each request.

  • password (String, nil) (defaults to: nil)

    The HTTP Basic-Auth password to add to each request.

  • ssl (Boolean, Hash{Symbol => Object}, nil) (defaults to: nil)

    Specifies whether to enable SSL and/or the SSL context configuration.

Options Hash (ssl:):

  • :ca_bundle (String, nil)

    The path to the CA bundle directory or file.

  • :cert (Crypto::Cert, OpenSSL::X509::Certificate, nil)

    The certificate to use for the SSL/TLS connection.

  • :cert_store (OpenSSL::X509::Store, nil)

    The certificate store to use for the SSL/TLS connection.

  • :ciphers (Array<(name, version, bits, alg_bits)>, nil)

    The accepted ciphers to use for the SSL/TLS connection.

  • :extra_chain_cert (Crypto::Cert, OpenSSL::X509::Certificate, nil)

    The extra certificate to add to the SSL/TLS certificate chain.

  • :key (Crypto::Key::RSA, Crypto::Key::DSA, OpenSSL::PKey::RSA, OpenSSL::PKey::DSA, nil)

    The RSA or DSA key to use for the SSL/TLS connection.

  • :timeout (Integer, nil)

    The connection timeout limit.

  • :version (1, 1.1, 1.2, Symbol, nil)

    The desired SSL/TLS version.

  • :min_version (1, 1.1, 1.2, Symbol, nil)

    The minimum SSL/TLS version.

  • :max_version (1, 1.1, 1.2, Symbol, nil)

    The maximum SSL/TLS version.

  • :verify_callback (Proc, nil)

    The callback to use when verifying the server's certificate.

  • :verify_depth (Integer, nil)

    The verification depth limit.

  • :verify (:none, :peer, :fail_if_no_peer_cert, true, false, Integer, nil)

    The verification mode.

  • :verify_hostname (Boolean, nil)

    Indicates whether to verify the server's hostname.

Options Hash (**kwargs):

  • :query (String, nil)

    The query-string to append to the request path.

  • :query_params (Hash, nil)

    The query-params to append to the request path.

  • :user (String, nil)

    The user to authenticate as.

  • :password (String, nil)

    The password to authenticate with.

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

    Additional HTTP header names and values to add to the request.

  • :content_type (String, :text, :xml, :html, :json, nil)

    The Content-Type header value for the request. If a Symbol is given it will be resolved to a common MIME type:

    • :text - text/plain
    • :xml - text/xml
    • :html - text/html
    • :json - application/json
  • :accept (String, :text, :xml, :html, :json, nil)

    The Accept header value for the request. If a Symbol is given it will be resolved to a common MIME type:

    • :text - text/plain
    • :xml - text/xml
    • :html - text/html
    • :json - application/json
  • :cookie (String, Hash{String => String}, Cookie, nil)

    Additional Cookie header. If a Hash is given, it will be converted to a String using Cookie. If the cookie value is empty, the Cookie header will not be set.

  • :body (String, nil)

    The body of the request.

  • :form_data (Hash, String, nil)

    The form data that may be sent in the body of the request.

  • :json (#to_json, nil)

    The JSON data that will be sent in the body of the request. Will also default the Content-Type header to application/json, unless already set.

Yields:

  • (response)

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

Yield Parameters:

  • response (Net::HTTPRresponse)

    The received HTTP response object.

Returns:

  • (Net::HTTPResponse)

    The new HTTP Request object.

See Also:

Since:

  • 1.0.0



2668
2669
2670
2671
2672
2673
2674
2675
2676
2677
2678
2679
2680
2681
2682
2683
2684
2685
2686
2687
2688
2689
2690
2691
2692
2693
2694
2695
2696
# File 'lib/ronin/support/network/http.rb', line 2668

def self.propfind(url, proxy:      self.proxy,
                       ssl:        nil,
                       headers:    {},
                       user_agent: nil,
                       cookie:     nil,
                       user:       nil,
                       password:   nil,
                       **kwargs,
                       &block)
  uri = case url
        when Addressable::URI, URI::HTTP
          url
        when String
          Addressable::URI.parse(url)
        else
          raise(ArgumentError,"URL argument must be either a Addressable::URI, URI::HTTP, or a String: #{url.inspect}")
        end

  path = uri.request_uri
  http = connect_uri(url, proxy:      proxy,
                          ssl:        ssl,
                          headers:    headers,
                          user_agent: user_agent,
                          cookie:     cookie,
                          user:       user,
                          password:   password)

  http.propfind(path,**kwargs,&block)
end

.proppatch(url, proxy: self.proxy, ssl: nil, headers: {}, user_agent: nil, cookie: nil, user: nil, password: nil, **kwargs) {|response| ... } ⇒ Net::HTTPResponse

Performs a PROPPATCH request for the given URI.

Parameters:

  • url (URI::HTTP, Addressable::URI, String)

    Optional URL to create the HTTP request for.

  • kwargs (Hash{Symbol => Object})

    Aditional keyword arguments and headers for #request.

  • proxy (String, URI::HTTP, Addressable::URI, nil) (defaults to: self.proxy)

    Optional proxy to use for the request.

  • headers (Hash{Symbol,String => String,Array}, nil) (defaults to: {})

    Additional headers to add to each request.

  • user_agent (String, :random, :chrome, :chrome_linux, :chrome_macos, :chrome_windows, :chrome_iphone, :chrome_ipad, :chrome_android, :firefox, :firefox_linux, :firefox_macos, :firefox_windows, :firefox_iphone, :firefox_ipad, :firefox_android, :safari, :safari_macos, :safari_iphone, :safari_ipad, :edge, :linux, :macos, :windows, :iphone, :ipad, :android, nil) (defaults to: nil)

    The default User-Agent value to add to each request.

  • cookie (Cookie, Hash, String, nil) (defaults to: nil)

    The default cookie params to add to each request.

  • user (String, nil) (defaults to: nil)

    The HTTP Basic-Auth user to add to each request.

  • password (String, nil) (defaults to: nil)

    The HTTP Basic-Auth password to add to each request.

  • ssl (Boolean, Hash{Symbol => Object}, nil) (defaults to: nil)

    Specifies whether to enable SSL and/or the SSL context configuration.

Options Hash (ssl:):

  • :ca_bundle (String, nil)

    The path to the CA bundle directory or file.

  • :cert (Crypto::Cert, OpenSSL::X509::Certificate, nil)

    The certificate to use for the SSL/TLS connection.

  • :cert_store (OpenSSL::X509::Store, nil)

    The certificate store to use for the SSL/TLS connection.

  • :ciphers (Array<(name, version, bits, alg_bits)>, nil)

    The accepted ciphers to use for the SSL/TLS connection.

  • :extra_chain_cert (Crypto::Cert, OpenSSL::X509::Certificate, nil)

    The extra certificate to add to the SSL/TLS certificate chain.

  • :key (Crypto::Key::RSA, Crypto::Key::DSA, OpenSSL::PKey::RSA, OpenSSL::PKey::DSA, nil)

    The RSA or DSA key to use for the SSL/TLS connection.

  • :timeout (Integer, nil)

    The connection timeout limit.

  • :version (1, 1.1, 1.2, Symbol, nil)

    The desired SSL/TLS version.

  • :min_version (1, 1.1, 1.2, Symbol, nil)

    The minimum SSL/TLS version.

  • :max_version (1, 1.1, 1.2, Symbol, nil)

    The maximum SSL/TLS version.

  • :verify_callback (Proc, nil)

    The callback to use when verifying the server's certificate.

  • :verify_depth (Integer, nil)

    The verification depth limit.

  • :verify (:none, :peer, :fail_if_no_peer_cert, true, false, Integer, nil)

    The verification mode.

  • :verify_hostname (Boolean, nil)

    Indicates whether to verify the server's hostname.

Options Hash (**kwargs):

  • :query (String, nil)

    The query-string to append to the request path.

  • :query_params (Hash, nil)

    The query-params to append to the request path.

  • :user (String, nil)

    The user to authenticate as.

  • :password (String, nil)

    The password to authenticate with.

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

    Additional HTTP header names and values to add to the request.

  • :content_type (String, :text, :xml, :html, :json, nil)

    The Content-Type header value for the request. If a Symbol is given it will be resolved to a common MIME type:

    • :text - text/plain
    • :xml - text/xml
    • :html - text/html
    • :json - application/json
  • :accept (String, :text, :xml, :html, :json, nil)

    The Accept header value for the request. If a Symbol is given it will be resolved to a common MIME type:

    • :text - text/plain
    • :xml - text/xml
    • :html - text/html
    • :json - application/json
  • :cookie (String, Hash{String => String}, Cookie, nil)

    Additional Cookie header. If a Hash is given, it will be converted to a String using Cookie. If the cookie value is empty, the Cookie header will not be set.

  • :body (String, nil)

    The body of the request.

  • :form_data (Hash, String, nil)

    The form data that may be sent in the body of the request.

  • :json (#to_json, nil)

    The JSON data that will be sent in the body of the request. Will also default the Content-Type header to application/json, unless already set.

Yields:

  • (response)

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

Yield Parameters:

  • response (Net::HTTPRresponse)

    The received HTTP response object.

Returns:

  • (Net::HTTPResponse)

    The new HTTP Request object.

See Also:

Since:

  • 1.0.0



2721
2722
2723
2724
2725
2726
2727
2728
2729
2730
2731
2732
2733
2734
2735
2736
2737
2738
2739
2740
2741
2742
2743
2744
2745
2746
2747
2748
2749
# File 'lib/ronin/support/network/http.rb', line 2721

def self.proppatch(url, proxy:      self.proxy,
                        ssl:        nil,
                        headers:    {},
                        user_agent: nil,
                        cookie:     nil,
                        user:       nil,
                        password:   nil,
                        **kwargs,
                        &block)
  uri = case url
        when Addressable::URI, URI::HTTP
          url
        when String
          Addressable::URI.parse(url)
        else
          raise(ArgumentError,"URL argument must be either a Addressable::URI, URI::HTTP, or a String: #{url.inspect}")
        end

  path = uri.request_uri
  http = connect_uri(url, proxy:      proxy,
                          ssl:        ssl,
                          headers:    headers,
                          user_agent: user_agent,
                          cookie:     cookie,
                          user:       user,
                          password:   password)

  http.proppatch(path,**kwargs,&block)
end

.proxyURI::HTTP, ...

Note:

If the RONIN_HTTP_PROXY environment variable is specified, it will be used as the default value. If the HTTP_PROXY environment variable is specified, it will be used as the default value.

The Ronin HTTP proxy to use.

Returns:

  • (URI::HTTP, Addressable::URI, nil)

    The Ronin HTTP proxy.



59
60
61
62
63
64
65
# File 'lib/ronin/support/network/http.rb', line 59

def self.proxy
  @proxy ||= if ENV['RONIN_HTTP_PROXY']
               Addressable::URI.parse(ENV['RONIN_HTTP_PROXY'])
             elsif ENV['HTTP_PROXY']
               Addressable::URI.parse(ENV['HTTP_PROXY'])
             end
end

.proxy=(new_proxy) ⇒ URI::HTTP, ...

Sets the Ronin HTTP proxy to use.

Parameters:

  • new_proxy (URI::HTTP, Addressable::URI, String, nil)

    The new proxy information to use.

Returns:

  • (URI::HTTP, Addressable::URI, nil)

    The new proxy.

Raises:

  • (ArgumentError)

    The given proxy information was not a URI::HTTP, Addressable::URI, String, or nil.



82
83
84
85
86
87
88
89
90
91
92
93
# File 'lib/ronin/support/network/http.rb', line 82

def self.proxy=(new_proxy)
  @proxy = case new_proxy
           when URI::HTTP, Addressable::URI
             new_proxy
           when String
             Addressable::URI.parse(new_proxy)
           when nil
             nil
           else
             raise(ArgumentError,"invalid proxy value (#{new_proxy.inspect}), must be either a URI::HTTP, Addressable::URI, String, or nil")
           end
end

.put(url, proxy: self.proxy, ssl: nil, headers: {}, user_agent: nil, cookie: nil, user: nil, password: nil, **kwargs) {|response| ... } ⇒ Net::HTTPResponse

Performs a PUT request for the given URI.

Parameters:

  • url (URI::HTTP, Addressable::URI, String)

    Optional URL to create the HTTP request for.

  • kwargs (Hash{Symbol => Object})

    Aditional keyword arguments and headers for #request.

  • proxy (String, URI::HTTP, Addressable::URI, nil) (defaults to: self.proxy)

    Optional proxy to use for the request.

  • headers (Hash{Symbol,String => String,Array}, nil) (defaults to: {})

    Additional headers to add to each request.

  • user_agent (String, :random, :chrome, :chrome_linux, :chrome_macos, :chrome_windows, :chrome_iphone, :chrome_ipad, :chrome_android, :firefox, :firefox_linux, :firefox_macos, :firefox_windows, :firefox_iphone, :firefox_ipad, :firefox_android, :safari, :safari_macos, :safari_iphone, :safari_ipad, :edge, :linux, :macos, :windows, :iphone, :ipad, :android, nil) (defaults to: nil)

    The default User-Agent value to add to each request.

  • cookie (Cookie, Hash, String, nil) (defaults to: nil)

    The default cookie params to add to each request.

  • user (String, nil) (defaults to: nil)

    The HTTP Basic-Auth user to add to each request.

  • password (String, nil) (defaults to: nil)

    The HTTP Basic-Auth password to add to each request.

  • ssl (Boolean, Hash{Symbol => Object}, nil) (defaults to: nil)

    Specifies whether to enable SSL and/or the SSL context configuration.

Options Hash (ssl:):

  • :ca_bundle (String, nil)

    The path to the CA bundle directory or file.

  • :cert (Crypto::Cert, OpenSSL::X509::Certificate, nil)

    The certificate to use for the SSL/TLS connection.

  • :cert_store (OpenSSL::X509::Store, nil)

    The certificate store to use for the SSL/TLS connection.

  • :ciphers (Array<(name, version, bits, alg_bits)>, nil)

    The accepted ciphers to use for the SSL/TLS connection.

  • :extra_chain_cert (Crypto::Cert, OpenSSL::X509::Certificate, nil)

    The extra certificate to add to the SSL/TLS certificate chain.

  • :key (Crypto::Key::RSA, Crypto::Key::DSA, OpenSSL::PKey::RSA, OpenSSL::PKey::DSA, nil)

    The RSA or DSA key to use for the SSL/TLS connection.

  • :timeout (Integer, nil)

    The connection timeout limit.

  • :version (1, 1.1, 1.2, Symbol, nil)

    The desired SSL/TLS version.

  • :min_version (1, 1.1, 1.2, Symbol, nil)

    The minimum SSL/TLS version.

  • :max_version (1, 1.1, 1.2, Symbol, nil)

    The maximum SSL/TLS version.

  • :verify_callback (Proc, nil)

    The callback to use when verifying the server's certificate.

  • :verify_depth (Integer, nil)

    The verification depth limit.

  • :verify (:none, :peer, :fail_if_no_peer_cert, true, false, Integer, nil)

    The verification mode.

  • :verify_hostname (Boolean, nil)

    Indicates whether to verify the server's hostname.

Options Hash (**kwargs):

  • :query (String, nil)

    The query-string to append to the request path.

  • :query_params (Hash, nil)

    The query-params to append to the request path.

  • :user (String, nil)

    The user to authenticate as.

  • :password (String, nil)

    The password to authenticate with.

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

    Additional HTTP header names and values to add to the request.

  • :content_type (String, :text, :xml, :html, :json, nil)

    The Content-Type header value for the request. If a Symbol is given it will be resolved to a common MIME type:

    • :text - text/plain
    • :xml - text/xml
    • :html - text/html
    • :json - application/json
  • :accept (String, :text, :xml, :html, :json, nil)

    The Accept header value for the request. If a Symbol is given it will be resolved to a common MIME type:

    • :text - text/plain
    • :xml - text/xml
    • :html - text/html
    • :json - application/json
  • :cookie (String, Hash{String => String}, Cookie, nil)

    Additional Cookie header. If a Hash is given, it will be converted to a String using Cookie. If the cookie value is empty, the Cookie header will not be set.

  • :body (String, nil)

    The body of the request.

  • :form_data (Hash, String, nil)

    The form data that may be sent in the body of the request.

  • :json (#to_json, nil)

    The JSON data that will be sent in the body of the request. Will also default the Content-Type header to application/json, unless already set.

Yields:

  • (response)

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

Yield Parameters:

  • response (Net::HTTPRresponse)

    The received HTTP response object.

Returns:

  • (Net::HTTPResponse)

    The new HTTP Request object.

See Also:

Since:

  • 1.0.0



2774
2775
2776
2777
2778
2779
2780
2781
2782
2783
2784
2785
2786
2787
2788
2789
2790
2791
2792
2793
2794
2795
2796
2797
2798
2799
2800
2801
2802
# File 'lib/ronin/support/network/http.rb', line 2774

def self.put(url, proxy:      self.proxy,
                  ssl:        nil,
                  headers:    {},
                  user_agent: nil,
                  cookie:     nil,
                  user:       nil,
                  password:   nil,
                  **kwargs,
                  &block)
  uri = case url
        when Addressable::URI, URI::HTTP
          url
        when String
          Addressable::URI.parse(url)
        else
          raise(ArgumentError,"URL argument must be either a Addressable::URI, URI::HTTP, or a String: #{url.inspect}")
        end

  path = uri.request_uri
  http = connect_uri(url, proxy:      proxy,
                          ssl:        ssl,
                          headers:    headers,
                          user_agent: user_agent,
                          cookie:     cookie,
                          user:       user,
                          password:   password)

  http.put(path,**kwargs,&block)
end

.request(method, url, proxy: self.proxy, ssl: nil, headers: {}, user_agent: nil, cookie: nil, user: nil, password: nil, **kwargs) {|response| ... } ⇒ Net::HTTPResponse

Performs and arbitrary HTTP request.

The HTTP method to use for the request.

Parameters:

  • method (:copy, :delete, :get, :head, :lock, :mkcol, :move, :options, :patch, :post, :propfind, :proppatch, :put, :trace, :unlock)
  • url (URI::HTTP, Addressable::URI, String)

    Optional URL to create the HTTP request for.

  • kwargs (Hash{Symbol => Object})

    Aditional keyword arguments and headers for #request.

  • proxy (String, URI::HTTP, Addressable::URI, nil) (defaults to: self.proxy)

    Optional proxy to use for the request.

  • headers (Hash{Symbol,String => String,Array}, nil) (defaults to: {})

    Additional headers to add to each request.

  • user_agent (String, :random, :chrome, :chrome_linux, :chrome_macos, :chrome_windows, :chrome_iphone, :chrome_ipad, :chrome_android, :firefox, :firefox_linux, :firefox_macos, :firefox_windows, :firefox_iphone, :firefox_ipad, :firefox_android, :safari, :safari_macos, :safari_iphone, :safari_ipad, :edge, :linux, :macos, :windows, :iphone, :ipad, :android, nil) (defaults to: nil)

    The default User-Agent value to add to each request.

  • cookie (Cookie, Hash, String, nil) (defaults to: nil)

    The default cookie params to add to each request.

  • user (String, nil) (defaults to: nil)

    The HTTP Basic-Auth user to add to each request.

  • password (String, nil) (defaults to: nil)

    The HTTP Basic-Auth password to add to each request.

  • ssl (Boolean, Hash{Symbol => Object}, nil) (defaults to: nil)

    Specifies whether to enable SSL and/or the SSL context configuration.

Options Hash (ssl:):

  • :ca_bundle (String, nil)

    The path to the CA bundle directory or file.

  • :cert (Crypto::Cert, OpenSSL::X509::Certificate, nil)

    The certificate to use for the SSL/TLS connection.

  • :cert_store (OpenSSL::X509::Store, nil)

    The certificate store to use for the SSL/TLS connection.

  • :ciphers (Array<(name, version, bits, alg_bits)>, nil)

    The accepted ciphers to use for the SSL/TLS connection.

  • :extra_chain_cert (Crypto::Cert, OpenSSL::X509::Certificate, nil)

    The extra certificate to add to the SSL/TLS certificate chain.

  • :key (Crypto::Key::RSA, Crypto::Key::DSA, OpenSSL::PKey::RSA, OpenSSL::PKey::DSA, nil)

    The RSA or DSA key to use for the SSL/TLS connection.

  • :timeout (Integer, nil)

    The connection timeout limit.

  • :version (1, 1.1, 1.2, Symbol, nil)

    The desired SSL/TLS version.

  • :min_version (1, 1.1, 1.2, Symbol, nil)

    The minimum SSL/TLS version.

  • :max_version (1, 1.1, 1.2, Symbol, nil)

    The maximum SSL/TLS version.

  • :verify_callback (Proc, nil)

    The callback to use when verifying the server's certificate.

  • :verify_depth (Integer, nil)

    The verification depth limit.

  • :verify (:none, :peer, :fail_if_no_peer_cert, true, false, Integer, nil)

    The verification mode.

  • :verify_hostname (Boolean, nil)

    Indicates whether to verify the server's hostname.

Options Hash (**kwargs):

  • :query (String, nil)

    The query-string to append to the request path.

  • :query_params (Hash, nil)

    The query-params to append to the request path.

  • :user (String, nil)

    The user to authenticate as.

  • :password (String, nil)

    The password to authenticate with.

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

    Additional HTTP header names and values to add to the request.

  • :content_type (String, :text, :xml, :html, :json, nil)

    The Content-Type header value for the request. If a Symbol is given it will be resolved to a common MIME type:

    • :text - text/plain
    • :xml - text/xml
    • :html - text/html
    • :json - application/json
  • :accept (String, :text, :xml, :html, :json, nil)

    The Accept header value for the request. If a Symbol is given it will be resolved to a common MIME type:

    • :text - text/plain
    • :xml - text/xml
    • :html - text/html
    • :json - application/json
  • :cookie (String, Hash{String => String}, Cookie, nil)

    Additional Cookie header. If a Hash is given, it will be converted to a String using Cookie. If the cookie value is empty, the Cookie header will not be set.

  • :body (String, nil)

    The body of the request.

  • :form_data (Hash, String, nil)

    The form data that may be sent in the body of the request.

  • :json (#to_json, nil)

    The JSON data that will be sent in the body of the request. Will also default the Content-Type header to application/json, unless already set.

Yields:

  • (response)

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

Yield Parameters:

  • response (Net::HTTPRresponse)

    The received HTTP response object.

Returns:

  • (Net::HTTPResponse)

    The new HTTP Request object.

Raises:

  • (ArgumentError)

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

See Also:



1508
1509
1510
1511
1512
1513
1514
1515
1516
1517
1518
1519
1520
1521
1522
1523
1524
1525
1526
1527
1528
1529
1530
1531
1532
1533
1534
1535
1536
# File 'lib/ronin/support/network/http.rb', line 1508

def self.request(method,url, proxy:      self.proxy,
                             ssl:        nil,
                             headers:    {},
                             user_agent: nil,
                             cookie:     nil,
                             user:       nil,
                             password:   nil,
                             **kwargs,
                             &block)
  uri  = case url
         when Addressable::URI, URI::HTTP
           url
         when String
           Addressable::URI.parse(url)
         else
           raise(ArgumentError,"URL argument must be either a Addressable::URI, URI::HTTP, or a String: #{url.inspect}")
         end

  path = uri.request_uri
  http = connect_uri(uri, proxy:      proxy,
                          ssl:        ssl,
                          headers:    headers,
                          user_agent: user_agent,
                          cookie:     cookie,
                          user:       user,
                          password:   password)

  http.request(method,path,**kwargs,&block)
end

.response_body(method = :get, url, proxy: self.proxy, ssl: nil, headers: {}, user_agent: nil, cookie: nil, user: nil, password: nil, **kwargs) ⇒ String

Sends an arbitrary HTTP request and returns the response body.

The HTTP method to use for the request.

Parameters:

  • method (:copy, :delete, :get, :head, :lock, :mkcol, :move, :options, :patch, :post, :propfind, :proppatch, :put, :trace, :unlock) (defaults to: :get)
  • url (URI::HTTP, Addressable::URI, String)

    Optional URL to create the HTTP request for.

  • kwargs (Hash{Symbol => Object})

    Aditional keyword arguments and headers for #request.

  • proxy (String, URI::HTTP, Addressable::URI, nil) (defaults to: self.proxy)

    Optional proxy to use for the request.

  • headers (Hash{Symbol,String => String,Array}, nil) (defaults to: {})

    Additional headers to add to each request.

  • user_agent (String, :random, :chrome, :chrome_linux, :chrome_macos, :chrome_windows, :chrome_iphone, :chrome_ipad, :chrome_android, :firefox, :firefox_linux, :firefox_macos, :firefox_windows, :firefox_iphone, :firefox_ipad, :firefox_android, :safari, :safari_macos, :safari_iphone, :safari_ipad, :edge, :linux, :macos, :windows, :iphone, :ipad, :android, nil) (defaults to: nil)

    The default User-Agent value to add to each request.

  • cookie (Cookie, Hash, String, nil) (defaults to: nil)

    The default cookie params to add to each request.

  • user (String, nil) (defaults to: nil)

    The HTTP Basic-Auth user to add to each request.

  • password (String, nil) (defaults to: nil)

    The HTTP Basic-Auth password to add to each request.

  • ssl (Boolean, Hash{Symbol => Object}, nil) (defaults to: nil)

    Specifies whether to enable SSL and/or the SSL context configuration.

Options Hash (ssl:):

  • :ca_bundle (String, nil)

    The path to the CA bundle directory or file.

  • :cert (Crypto::Cert, OpenSSL::X509::Certificate, nil)

    The certificate to use for the SSL/TLS connection.

  • :cert_store (OpenSSL::X509::Store, nil)

    The certificate store to use for the SSL/TLS connection.

  • :ciphers (Array<(name, version, bits, alg_bits)>, nil)

    The accepted ciphers to use for the SSL/TLS connection.

  • :extra_chain_cert (Crypto::Cert, OpenSSL::X509::Certificate, nil)

    The extra certificate to add to the SSL/TLS certificate chain.

  • :key (Crypto::Key::RSA, Crypto::Key::DSA, OpenSSL::PKey::RSA, OpenSSL::PKey::DSA, nil)

    The RSA or DSA key to use for the SSL/TLS connection.

  • :timeout (Integer, nil)

    The connection timeout limit.

  • :version (1, 1.1, 1.2, Symbol, nil)

    The desired SSL/TLS version.

  • :min_version (1, 1.1, 1.2, Symbol, nil)

    The minimum SSL/TLS version.

  • :max_version (1, 1.1, 1.2, Symbol, nil)

    The maximum SSL/TLS version.

  • :verify_callback (Proc, nil)

    The callback to use when verifying the server's certificate.

  • :verify_depth (Integer, nil)

    The verification depth limit.

  • :verify (:none, :peer, :fail_if_no_peer_cert, true, false, Integer, nil)

    The verification mode.

  • :verify_hostname (Boolean, nil)

    Indicates whether to verify the server's hostname.

Options Hash (**kwargs):

  • :query (String, nil)

    The query-string to append to the request path.

  • :query_params (Hash, nil)

    The query-params to append to the request path.

  • :user (String, nil)

    The user to authenticate as.

  • :password (String, nil)

    The password to authenticate with.

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

    Additional HTTP header names and values to add to the request.

  • :content_type (String, :text, :xml, :html, :json, nil)

    The Content-Type header value for the request. If a Symbol is given it will be resolved to a common MIME type:

    • :text - text/plain
    • :xml - text/xml
    • :html - text/html
    • :json - application/json
  • :accept (String, :text, :xml, :html, :json, nil)

    The Accept header value for the request. If a Symbol is given it will be resolved to a common MIME type:

    • :text - text/plain
    • :xml - text/xml
    • :html - text/html
    • :json - application/json
  • :cookie (String, Hash{String => String}, Cookie, nil)

    Additional Cookie header. If a Hash is given, it will be converted to a String using Cookie. If the cookie value is empty, the Cookie header will not be set.

  • :body (String, nil)

    The body of the request.

  • :form_data (Hash, String, nil)

    The form data that may be sent in the body of the request.

  • :json (#to_json, nil)

    The JSON data that will be sent in the body of the request. Will also default the Content-Type header to application/json, unless already set.

Returns:

  • (String)

    The response body.

See Also:

Since:

  • 1.0.0



1805
1806
1807
1808
1809
1810
1811
1812
1813
1814
1815
1816
1817
1818
1819
1820
1821
1822
1823
1824
1825
1826
1827
1828
1829
1830
1831
1832
# File 'lib/ronin/support/network/http.rb', line 1805

def self.response_body(method=:get,url, proxy:      self.proxy,
                                        ssl:        nil,
                                        headers:    {},
                                        user_agent: nil,
                                        cookie:     nil,
                                        user:       nil,
                                        password:   nil,
                                        **kwargs)
  uri = case url
        when Addressable::URI, URI::HTTP
          url
        when String
          Addressable::URI.parse(url)
        else
          raise(ArgumentError,"URL argument must be either a Addressable::URI, URI::HTTP, or a String: #{url.inspect}")
        end

  path = uri.request_uri
  http = connect_uri(url, proxy:      proxy,
                          ssl:        ssl,
                          headers:    headers,
                          user_agent: user_agent,
                          cookie:     cookie,
                          user:       user,
                          password:   password)

  http.response_body(method,path,**kwargs)
end

.response_headers(method = :head, url, proxy: self.proxy, ssl: nil, headers: {}, user_agent: nil, cookie: nil, user: nil, password: nil, **kwargs) ⇒ Hash{String => String}

Sends an arbitrary HTTP request and returns the response headers.

The HTTP method to use for the request.

Parameters:

  • method (:copy, :delete, :get, :head, :lock, :mkcol, :move, :options, :patch, :post, :propfind, :proppatch, :put, :trace, :unlock) (defaults to: :head)
  • url (URI::HTTP, Addressable::URI, String)

    Optional URL to create the HTTP request for.

  • kwargs (Hash{Symbol => Object})

    Aditional keyword arguments and headers for #request.

  • proxy (String, URI::HTTP, Addressable::URI, nil) (defaults to: self.proxy)

    Optional proxy to use for the request.

  • headers (Hash{Symbol,String => String,Array}, nil) (defaults to: {})

    Additional headers to add to each request.

  • user_agent (String, :random, :chrome, :chrome_linux, :chrome_macos, :chrome_windows, :chrome_iphone, :chrome_ipad, :chrome_android, :firefox, :firefox_linux, :firefox_macos, :firefox_windows, :firefox_iphone, :firefox_ipad, :firefox_android, :safari, :safari_macos, :safari_iphone, :safari_ipad, :edge, :linux, :macos, :windows, :iphone, :ipad, :android, nil) (defaults to: nil)

    The default User-Agent value to add to each request.

  • cookie (Cookie, Hash, String, nil) (defaults to: nil)

    The default cookie params to add to each request.

  • user (String, nil) (defaults to: nil)

    The HTTP Basic-Auth user to add to each request.

  • password (String, nil) (defaults to: nil)

    The HTTP Basic-Auth password to add to each request.

  • ssl (Boolean, Hash{Symbol => Object}, nil) (defaults to: nil)

    Specifies whether to enable SSL and/or the SSL context configuration.

Options Hash (ssl:):

  • :ca_bundle (String, nil)

    The path to the CA bundle directory or file.

  • :cert (Crypto::Cert, OpenSSL::X509::Certificate, nil)

    The certificate to use for the SSL/TLS connection.

  • :cert_store (OpenSSL::X509::Store, nil)

    The certificate store to use for the SSL/TLS connection.

  • :ciphers (Array<(name, version, bits, alg_bits)>, nil)

    The accepted ciphers to use for the SSL/TLS connection.

  • :extra_chain_cert (Crypto::Cert, OpenSSL::X509::Certificate, nil)

    The extra certificate to add to the SSL/TLS certificate chain.

  • :key (Crypto::Key::RSA, Crypto::Key::DSA, OpenSSL::PKey::RSA, OpenSSL::PKey::DSA, nil)

    The RSA or DSA key to use for the SSL/TLS connection.

  • :timeout (Integer, nil)

    The connection timeout limit.

  • :version (1, 1.1, 1.2, Symbol, nil)

    The desired SSL/TLS version.

  • :min_version (1, 1.1, 1.2, Symbol, nil)

    The minimum SSL/TLS version.

  • :max_version (1, 1.1, 1.2, Symbol, nil)

    The maximum SSL/TLS version.

  • :verify_callback (Proc, nil)

    The callback to use when verifying the server's certificate.

  • :verify_depth (Integer, nil)

    The verification depth limit.

  • :verify (:none, :peer, :fail_if_no_peer_cert, true, false, Integer, nil)

    The verification mode.

  • :verify_hostname (Boolean, nil)

    Indicates whether to verify the server's hostname.

Options Hash (**kwargs):

  • :query (String, nil)

    The query-string to append to the request path.

  • :query_params (Hash, nil)

    The query-params to append to the request path.

  • :user (String, nil)

    The user to authenticate as.

  • :password (String, nil)

    The password to authenticate with.

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

    Additional HTTP header names and values to add to the request.

  • :content_type (String, :text, :xml, :html, :json, nil)

    The Content-Type header value for the request. If a Symbol is given it will be resolved to a common MIME type:

    • :text - text/plain
    • :xml - text/xml
    • :html - text/html
    • :json - application/json
  • :accept (String, :text, :xml, :html, :json, nil)

    The Accept header value for the request. If a Symbol is given it will be resolved to a common MIME type:

    • :text - text/plain
    • :xml - text/xml
    • :html - text/html
    • :json - application/json
  • :cookie (String, Hash{String => String}, Cookie, nil)

    Additional Cookie header. If a Hash is given, it will be converted to a String using Cookie. If the cookie value is empty, the Cookie header will not be set.

  • :body (String, nil)

    The body of the request.

  • :form_data (Hash, String, nil)

    The form data that may be sent in the body of the request.

  • :json (#to_json, nil)

    The JSON data that will be sent in the body of the request. Will also default the Content-Type header to application/json, unless already set.

Returns:

See Also:

Since:

  • 1.0.0



1662
1663
1664
1665
1666
1667
1668
1669
1670
1671
1672
1673
1674
1675
1676
1677
1678
1679
1680
1681
1682
1683
1684
1685
1686
1687
1688
1689
# File 'lib/ronin/support/network/http.rb', line 1662

def self.response_headers(method=:head,url, proxy:      self.proxy,
                                            ssl:        nil,
                                            headers:    {},
                                            user_agent: nil,
                                            cookie:     nil,
                                            user:       nil,
                                            password:   nil,
                                            **kwargs)
  uri  = case url
         when Addressable::URI, URI::HTTP
           url
         when String
           Addressable::URI.parse(url)
         else
           raise(ArgumentError,"URL argument must be either a Addressable::URI, URI::HTTP, or a String: #{url.inspect}")
         end

  path = uri.request_uri
  http = connect_uri(url, proxy:      proxy,
                          ssl:        ssl,
                          headers:    headers,
                          user_agent: user_agent,
                          cookie:     cookie,
                          user:       user,
                          password:   password)

  http.response_headers(method,path,**kwargs)
end

.response_status(method = :head, url, proxy: self.proxy, ssl: nil, headers: {}, user_agent: nil, cookie: nil, user: nil, password: nil, **kwargs) ⇒ Integer

Sends an arbitrary HTTP request and returns the response status.

The HTTP method to use for the request.

Parameters:

  • method (:copy, :delete, :get, :head, :lock, :mkcol, :move, :options, :patch, :post, :propfind, :proppatch, :put, :trace, :unlock) (defaults to: :head)
  • url (URI::HTTP, Addressable::URI, String)

    Optional URL to create the HTTP request for.

  • kwargs (Hash{Symbol => Object})

    Aditional keyword arguments and headers for #request.

  • proxy (String, URI::HTTP, Addressable::URI, nil) (defaults to: self.proxy)

    Optional proxy to use for the request.

  • headers (Hash{Symbol,String => String,Array}, nil) (defaults to: {})

    Additional headers to add to each request.

  • user_agent (String, :random, :chrome, :chrome_linux, :chrome_macos, :chrome_windows, :chrome_iphone, :chrome_ipad, :chrome_android, :firefox, :firefox_linux, :firefox_macos, :firefox_windows, :firefox_iphone, :firefox_ipad, :firefox_android, :safari, :safari_macos, :safari_iphone, :safari_ipad, :edge, :linux, :macos, :windows, :iphone, :ipad, :android, nil) (defaults to: nil)

    The default User-Agent value to add to each request.

  • cookie (Cookie, Hash, String, nil) (defaults to: nil)

    The default cookie params to add to each request.

  • user (String, nil) (defaults to: nil)

    The HTTP Basic-Auth user to add to each request.

  • password (String, nil) (defaults to: nil)

    The HTTP Basic-Auth password to add to each request.

  • ssl (Boolean, Hash{Symbol => Object}, nil) (defaults to: nil)

    Specifies whether to enable SSL and/or the SSL context configuration.

Options Hash (ssl:):

  • :ca_bundle (String, nil)

    The path to the CA bundle directory or file.

  • :cert (Crypto::Cert, OpenSSL::X509::Certificate, nil)

    The certificate to use for the SSL/TLS connection.

  • :cert_store (OpenSSL::X509::Store, nil)

    The certificate store to use for the SSL/TLS connection.

  • :ciphers (Array<(name, version, bits, alg_bits)>, nil)

    The accepted ciphers to use for the SSL/TLS connection.

  • :extra_chain_cert (Crypto::Cert, OpenSSL::X509::Certificate, nil)

    The extra certificate to add to the SSL/TLS certificate chain.

  • :key (Crypto::Key::RSA, Crypto::Key::DSA, OpenSSL::PKey::RSA, OpenSSL::PKey::DSA, nil)

    The RSA or DSA key to use for the SSL/TLS connection.

  • :timeout (Integer, nil)

    The connection timeout limit.

  • :version (1, 1.1, 1.2, Symbol, nil)

    The desired SSL/TLS version.

  • :min_version (1, 1.1, 1.2, Symbol, nil)

    The minimum SSL/TLS version.

  • :max_version (1, 1.1, 1.2, Symbol, nil)

    The maximum SSL/TLS version.

  • :verify_callback (Proc, nil)

    The callback to use when verifying the server's certificate.

  • :verify_depth (Integer, nil)

    The verification depth limit.

  • :verify (:none, :peer, :fail_if_no_peer_cert, true, false, Integer, nil)

    The verification mode.

  • :verify_hostname (Boolean, nil)

    Indicates whether to verify the server's hostname.

Options Hash (**kwargs):

  • :query (String, nil)

    The query-string to append to the request path.

  • :query_params (Hash, nil)

    The query-params to append to the request path.

  • :user (String, nil)

    The user to authenticate as.

  • :password (String, nil)

    The password to authenticate with.

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

    Additional HTTP header names and values to add to the request.

  • :content_type (String, :text, :xml, :html, :json, nil)

    The Content-Type header value for the request. If a Symbol is given it will be resolved to a common MIME type:

    • :text - text/plain
    • :xml - text/xml
    • :html - text/html
    • :json - application/json
  • :accept (String, :text, :xml, :html, :json, nil)

    The Accept header value for the request. If a Symbol is given it will be resolved to a common MIME type:

    • :text - text/plain
    • :xml - text/xml
    • :html - text/html
    • :json - application/json
  • :cookie (String, Hash{String => String}, Cookie, nil)

    Additional Cookie header. If a Hash is given, it will be converted to a String using Cookie. If the cookie value is empty, the Cookie header will not be set.

  • :body (String, nil)

    The body of the request.

  • :form_data (Hash, String, nil)

    The form data that may be sent in the body of the request.

  • :json (#to_json, nil)

    The JSON data that will be sent in the body of the request. Will also default the Content-Type header to application/json, unless already set.

Returns:

  • (Integer)

    The status code of the response.

See Also:

Since:

  • 1.0.0



1560
1561
1562
1563
1564
1565
1566
1567
1568
1569
1570
1571
1572
1573
1574
1575
1576
1577
1578
1579
1580
1581
1582
1583
1584
1585
1586
1587
# File 'lib/ronin/support/network/http.rb', line 1560

def self.response_status(method=:head,url, proxy:      self.proxy,
                                           ssl:        nil,
                                           headers:    {},
                                           user_agent: nil,
                                           cookie:     nil,
                                           user:       nil,
                                           password:   nil,
                                           **kwargs)
  uri  = case url
         when Addressable::URI, URI::HTTP
           url
         when String
           Addressable::URI.parse(url)
         else
           raise(ArgumentError,"URL argument must be either a Addressable::URI, URI::HTTP, or a String: #{url.inspect}")
         end

  path = uri.request_uri
  http = connect_uri(url, proxy:      proxy,
                          ssl:        ssl,
                          headers:    headers,
                          user_agent: user_agent,
                          cookie:     cookie,
                          user:       user,
                          password:   password)

  http.response_status(method,path,**kwargs)
end

.server_header(url, proxy: self.proxy, ssl: nil, headers: {}, user_agent: nil, cookie: nil, user: nil, password: nil, **kwargs) ⇒ String?

Sends an HTTP request and returns the Server header.

Parameters:

  • url (URI::HTTP, Addressable::URI, String)

    Optional URL to create the HTTP request for.

  • kwargs (Hash{Symbol => Object})

    Aditional keyword arguments and headers for #request.

  • proxy (String, URI::HTTP, Addressable::URI, nil) (defaults to: self.proxy)

    Optional proxy to use for the request.

  • headers (Hash{Symbol,String => String,Array}, nil) (defaults to: {})

    Additional headers to add to each request.

  • user_agent (String, :random, :chrome, :chrome_linux, :chrome_macos, :chrome_windows, :chrome_iphone, :chrome_ipad, :chrome_android, :firefox, :firefox_linux, :firefox_macos, :firefox_windows, :firefox_iphone, :firefox_ipad, :firefox_android, :safari, :safari_macos, :safari_iphone, :safari_ipad, :edge, :linux, :macos, :windows, :iphone, :ipad, :android, nil) (defaults to: nil)

    The default User-Agent value to add to each request.

  • cookie (Cookie, Hash, String, nil) (defaults to: nil)

    The default cookie params to add to each request.

  • user (String, nil) (defaults to: nil)

    The HTTP Basic-Auth user to add to each request.

  • password (String, nil) (defaults to: nil)

    The HTTP Basic-Auth password to add to each request.

  • ssl (Boolean, Hash{Symbol => Object}, nil) (defaults to: nil)

    Specifies whether to enable SSL and/or the SSL context configuration.

Options Hash (ssl:):

  • :ca_bundle (String, nil)

    The path to the CA bundle directory or file.

  • :cert (Crypto::Cert, OpenSSL::X509::Certificate, nil)

    The certificate to use for the SSL/TLS connection.

  • :cert_store (OpenSSL::X509::Store, nil)

    The certificate store to use for the SSL/TLS connection.

  • :ciphers (Array<(name, version, bits, alg_bits)>, nil)

    The accepted ciphers to use for the SSL/TLS connection.

  • :extra_chain_cert (Crypto::Cert, OpenSSL::X509::Certificate, nil)

    The extra certificate to add to the SSL/TLS certificate chain.

  • :key (Crypto::Key::RSA, Crypto::Key::DSA, OpenSSL::PKey::RSA, OpenSSL::PKey::DSA, nil)

    The RSA or DSA key to use for the SSL/TLS connection.

  • :timeout (Integer, nil)

    The connection timeout limit.

  • :version (1, 1.1, 1.2, Symbol, nil)

    The desired SSL/TLS version.

  • :min_version (1, 1.1, 1.2, Symbol, nil)

    The minimum SSL/TLS version.

  • :max_version (1, 1.1, 1.2, Symbol, nil)

    The maximum SSL/TLS version.

  • :verify_callback (Proc, nil)

    The callback to use when verifying the server's certificate.

  • :verify_depth (Integer, nil)

    The verification depth limit.

  • :verify (:none, :peer, :fail_if_no_peer_cert, true, false, Integer, nil)

    The verification mode.

  • :verify_hostname (Boolean, nil)

    Indicates whether to verify the server's hostname.

Options Hash (**kwargs):

  • :query (String, nil)

    The query-string to append to the request path.

  • :query_params (Hash, nil)

    The query-params to append to the request path.

  • :user (String, nil)

    The user to authenticate as.

  • :password (String, nil)

    The password to authenticate with.

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

    Additional HTTP header names and values to add to the request.

  • :content_type (String, :text, :xml, :html, :json, nil)

    The Content-Type header value for the request. If a Symbol is given it will be resolved to a common MIME type:

    • :text - text/plain
    • :xml - text/xml
    • :html - text/html
    • :json - application/json
  • :accept (String, :text, :xml, :html, :json, nil)

    The Accept header value for the request. If a Symbol is given it will be resolved to a common MIME type:

    • :text - text/plain
    • :xml - text/xml
    • :html - text/html
    • :json - application/json
  • :cookie (String, Hash{String => String}, Cookie, nil)

    Additional Cookie header. If a Hash is given, it will be converted to a String using Cookie. If the cookie value is empty, the Cookie header will not be set.

  • :body (String, nil)

    The body of the request.

  • :form_data (Hash, String, nil)

    The form data that may be sent in the body of the request.

  • :json (#to_json, nil)

    The JSON data that will be sent in the body of the request. Will also default the Content-Type header to application/json, unless already set.

Returns:

  • (String, nil)

    The Server header.

See Also:

Since:

  • 1.0.0



1708
1709
1710
1711
1712
1713
1714
1715
1716
1717
1718
1719
1720
1721
1722
1723
1724
1725
1726
1727
1728
1729
1730
1731
1732
1733
1734
1735
# File 'lib/ronin/support/network/http.rb', line 1708

def self.server_header(url, proxy:      self.proxy,
                            ssl:        nil,
                            headers:    {},
                            user_agent: nil,
                            cookie:     nil,
                            user:       nil,
                            password:   nil,
                            **kwargs)
  uri  = case url
         when Addressable::URI, URI::HTTP
           url
         when String
           Addressable::URI.parse(url)
         else
           raise(ArgumentError,"URL argument must be either a Addressable::URI, URI::HTTP, or a String: #{url.inspect}")
         end

  path = uri.request_uri
  http = connect_uri(url, proxy:      proxy,
                          ssl:        ssl,
                          headers:    headers,
                          user_agent: user_agent,
                          cookie:     cookie,
                          user:       user,
                          password:   password)

  http.server_header(path: path, **kwargs)
end

.trace(url, proxy: self.proxy, ssl: nil, headers: {}, user_agent: nil, cookie: nil, user: nil, password: nil, **kwargs) {|response| ... } ⇒ Net::HTTPResponse

Performs a TRACE request for the given URI.

Parameters:

  • url (URI::HTTP, Addressable::URI, String)

    Optional URL to create the HTTP request for.

  • kwargs (Hash{Symbol => Object})

    Aditional keyword arguments and headers for #request.

  • proxy (String, URI::HTTP, Addressable::URI, nil) (defaults to: self.proxy)

    Optional proxy to use for the request.

  • headers (Hash{Symbol,String => String,Array}, nil) (defaults to: {})

    Additional headers to add to each request.

  • user_agent (String, :random, :chrome, :chrome_linux, :chrome_macos, :chrome_windows, :chrome_iphone, :chrome_ipad, :chrome_android, :firefox, :firefox_linux, :firefox_macos, :firefox_windows, :firefox_iphone, :firefox_ipad, :firefox_android, :safari, :safari_macos, :safari_iphone, :safari_ipad, :edge, :linux, :macos, :windows, :iphone, :ipad, :android, nil) (defaults to: nil)

    The default User-Agent value to add to each request.

  • cookie (Cookie, Hash, String, nil) (defaults to: nil)

    The default cookie params to add to each request.

  • user (String, nil) (defaults to: nil)

    The HTTP Basic-Auth user to add to each request.

  • password (String, nil) (defaults to: nil)

    The HTTP Basic-Auth password to add to each request.

  • ssl (Boolean, Hash{Symbol => Object}, nil) (defaults to: nil)

    Specifies whether to enable SSL and/or the SSL context configuration.

Options Hash (ssl:):

  • :ca_bundle (String, nil)

    The path to the CA bundle directory or file.

  • :cert (Crypto::Cert, OpenSSL::X509::Certificate, nil)

    The certificate to use for the SSL/TLS connection.

  • :cert_store (OpenSSL::X509::Store, nil)

    The certificate store to use for the SSL/TLS connection.

  • :ciphers (Array<(name, version, bits, alg_bits)>, nil)

    The accepted ciphers to use for the SSL/TLS connection.

  • :extra_chain_cert (Crypto::Cert, OpenSSL::X509::Certificate, nil)

    The extra certificate to add to the SSL/TLS certificate chain.

  • :key (Crypto::Key::RSA, Crypto::Key::DSA, OpenSSL::PKey::RSA, OpenSSL::PKey::DSA, nil)

    The RSA or DSA key to use for the SSL/TLS connection.

  • :timeout (Integer, nil)

    The connection timeout limit.

  • :version (1, 1.1, 1.2, Symbol, nil)

    The desired SSL/TLS version.

  • :min_version (1, 1.1, 1.2, Symbol, nil)

    The minimum SSL/TLS version.

  • :max_version (1, 1.1, 1.2, Symbol, nil)

    The maximum SSL/TLS version.

  • :verify_callback (Proc, nil)

    The callback to use when verifying the server's certificate.

  • :verify_depth (Integer, nil)

    The verification depth limit.

  • :verify (:none, :peer, :fail_if_no_peer_cert, true, false, Integer, nil)

    The verification mode.

  • :verify_hostname (Boolean, nil)

    Indicates whether to verify the server's hostname.

Options Hash (**kwargs):

  • :query (String, nil)

    The query-string to append to the request path.

  • :query_params (Hash, nil)

    The query-params to append to the request path.

  • :user (String, nil)

    The user to authenticate as.

  • :password (String, nil)

    The password to authenticate with.

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

    Additional HTTP header names and values to add to the request.

  • :content_type (String, :text, :xml, :html, :json, nil)

    The Content-Type header value for the request. If a Symbol is given it will be resolved to a common MIME type:

    • :text - text/plain
    • :xml - text/xml
    • :html - text/html
    • :json - application/json
  • :accept (String, :text, :xml, :html, :json, nil)

    The Accept header value for the request. If a Symbol is given it will be resolved to a common MIME type:

    • :text - text/plain
    • :xml - text/xml
    • :html - text/html
    • :json - application/json
  • :cookie (String, Hash{String => String}, Cookie, nil)

    Additional Cookie header. If a Hash is given, it will be converted to a String using Cookie. If the cookie value is empty, the Cookie header will not be set.

  • :body (String, nil)

    The body of the request.

  • :form_data (Hash, String, nil)

    The form data that may be sent in the body of the request.

  • :json (#to_json, nil)

    The JSON data that will be sent in the body of the request. Will also default the Content-Type header to application/json, unless already set.

Yields:

  • (response)

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

Yield Parameters:

  • response (Net::HTTPRresponse)

    The received HTTP response object.

Returns:

  • (Net::HTTPResponse)

    The new HTTP Request object.

See Also:

Since:

  • 1.0.0



2827
2828
2829
2830
2831
2832
2833
2834
2835
2836
2837
2838
2839
2840
2841
2842
2843
2844
2845
2846
2847
2848
2849
2850
2851
2852
2853
2854
2855
# File 'lib/ronin/support/network/http.rb', line 2827

def self.trace(url, proxy:      self.proxy,
                    ssl:        nil,
                    headers:    {},
                    user_agent: nil,
                    cookie:     nil,
                    user:       nil,
                    password:   nil,
                    **kwargs,
                    &block)
  uri = case url
        when Addressable::URI, URI::HTTP
          url
        when String
          Addressable::URI.parse(url)
        else
          raise(ArgumentError,"URL argument must be either a Addressable::URI, URI::HTTP, or a String: #{url.inspect}")
        end

  path = uri.request_uri
  http = connect_uri(url, proxy:      proxy,
                          ssl:        ssl,
                          headers:    headers,
                          user_agent: user_agent,
                          cookie:     cookie,
                          user:       user,
                          password:   password)

  http.trace(path,**kwargs,&block)
end

.unlock(url, proxy: self.proxy, ssl: nil, headers: {}, user_agent: nil, cookie: nil, user: nil, password: nil, **kwargs) {|response| ... } ⇒ Net::HTTPResponse

Performs a UNLOCK request for the given URI.

Parameters:

  • url (URI::HTTP, Addressable::URI, String)

    Optional URL to create the HTTP request for.

  • kwargs (Hash{Symbol => Object})

    Aditional keyword arguments and headers for #request.

  • proxy (String, URI::HTTP, Addressable::URI, nil) (defaults to: self.proxy)

    Optional proxy to use for the request.

  • headers (Hash{Symbol,String => String,Array}, nil) (defaults to: {})

    Additional headers to add to each request.

  • user_agent (String, :random, :chrome, :chrome_linux, :chrome_macos, :chrome_windows, :chrome_iphone, :chrome_ipad, :chrome_android, :firefox, :firefox_linux, :firefox_macos, :firefox_windows, :firefox_iphone, :firefox_ipad, :firefox_android, :safari, :safari_macos, :safari_iphone, :safari_ipad, :edge, :linux, :macos, :windows, :iphone, :ipad, :android, nil) (defaults to: nil)

    The default User-Agent value to add to each request.

  • cookie (Cookie, Hash, String, nil) (defaults to: nil)

    The default cookie params to add to each request.

  • user (String, nil) (defaults to: nil)

    The HTTP Basic-Auth user to add to each request.

  • password (String, nil) (defaults to: nil)

    The HTTP Basic-Auth password to add to each request.

  • ssl (Boolean, Hash{Symbol => Object}, nil) (defaults to: nil)

    Specifies whether to enable SSL and/or the SSL context configuration.

Options Hash (ssl:):

  • :ca_bundle (String, nil)

    The path to the CA bundle directory or file.

  • :cert (Crypto::Cert, OpenSSL::X509::Certificate, nil)

    The certificate to use for the SSL/TLS connection.

  • :cert_store (OpenSSL::X509::Store, nil)

    The certificate store to use for the SSL/TLS connection.

  • :ciphers (Array<(name, version, bits, alg_bits)>, nil)

    The accepted ciphers to use for the SSL/TLS connection.

  • :extra_chain_cert (Crypto::Cert, OpenSSL::X509::Certificate, nil)

    The extra certificate to add to the SSL/TLS certificate chain.

  • :key (Crypto::Key::RSA, Crypto::Key::DSA, OpenSSL::PKey::RSA, OpenSSL::PKey::DSA, nil)

    The RSA or DSA key to use for the SSL/TLS connection.

  • :timeout (Integer, nil)

    The connection timeout limit.

  • :version (1, 1.1, 1.2, Symbol, nil)

    The desired SSL/TLS version.

  • :min_version (1, 1.1, 1.2, Symbol, nil)

    The minimum SSL/TLS version.

  • :max_version (1, 1.1, 1.2, Symbol, nil)

    The maximum SSL/TLS version.

  • :verify_callback (Proc, nil)

    The callback to use when verifying the server's certificate.

  • :verify_depth (Integer, nil)

    The verification depth limit.

  • :verify (:none, :peer, :fail_if_no_peer_cert, true, false, Integer, nil)

    The verification mode.

  • :verify_hostname (Boolean, nil)

    Indicates whether to verify the server's hostname.

Options Hash (**kwargs):

  • :query (String, nil)

    The query-string to append to the request path.

  • :query_params (Hash, nil)

    The query-params to append to the request path.

  • :user (String, nil)

    The user to authenticate as.

  • :password (String, nil)

    The password to authenticate with.

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

    Additional HTTP header names and values to add to the request.

  • :content_type (String, :text, :xml, :html, :json, nil)

    The Content-Type header value for the request. If a Symbol is given it will be resolved to a common MIME type:

    • :text - text/plain
    • :xml - text/xml
    • :html - text/html
    • :json - application/json
  • :accept (String, :text, :xml, :html, :json, nil)

    The Accept header value for the request. If a Symbol is given it will be resolved to a common MIME type:

    • :text - text/plain
    • :xml - text/xml
    • :html - text/html
    • :json - application/json
  • :cookie (String, Hash{String => String}, Cookie, nil)

    Additional Cookie header. If a Hash is given, it will be converted to a String using Cookie. If the cookie value is empty, the Cookie header will not be set.

  • :body (String, nil)

    The body of the request.

  • :form_data (Hash, String, nil)

    The form data that may be sent in the body of the request.

  • :json (#to_json, nil)

    The JSON data that will be sent in the body of the request. Will also default the Content-Type header to application/json, unless already set.

Yields:

  • (response)

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

Yield Parameters:

  • response (Net::HTTPRresponse)

    The received HTTP response object.

Returns:

  • (Net::HTTPResponse)

    The new HTTP Request object.

See Also:

Since:

  • 1.0.0



2880
2881
2882
2883
2884
2885
2886
2887
2888
2889
2890
2891
2892
2893
2894
2895
2896
2897
2898
2899
2900
2901
2902
2903
2904
2905
2906
2907
2908
# File 'lib/ronin/support/network/http.rb', line 2880

def self.unlock(url, proxy:      self.proxy,
                     ssl:        nil,
                     headers:    {},
                     user_agent: nil,
                     cookie:     nil,
                     user:       nil,
                     password:   nil,
                     **kwargs,
                     &block)
  uri = case url
        when Addressable::URI, URI::HTTP
          url
        when String
          Addressable::URI.parse(url)
        else
          raise(ArgumentError,"URL argument must be either a Addressable::URI, URI::HTTP, or a String: #{url.inspect}")
        end

  path = uri.request_uri
  http = connect_uri(url, proxy:      proxy,
                          ssl:        ssl,
                          headers:    headers,
                          user_agent: user_agent,
                          cookie:     cookie,
                          user:       user,
                          password:   password)

  http.unlock(path,**kwargs,&block)
end

.user_agentString?

The default Ronin HTTP User-Agent string.

Returns:

  • (String, nil)

    The default Ronin HTTP User-Agent.



103
104
105
# File 'lib/ronin/support/network/http.rb', line 103

def self.user_agent
  @user_agent
end

.user_agent=(new_user_agent) ⇒ String?

Sets the default Ronin HTTP User-Agent string.

The new User-Agent default value.

  • If a Symbol or a String is given, then the user_agent value will be set.
  • If nil is given, then the user_agent value will be cleared.

Parameters:

  • new_user_agent (String, :random, :chrome, :chrome_linux, :chrome_macos, :chrome_windows, :chrome_iphone, :chrome_ipad, :chrome_android, :firefox, :firefox_linux, :firefox_macos, :firefox_windows, :firefox_iphone, :firefox_ipad, :firefox_android, :safari, :safari_macos, :safari_iphone, :safari_ipad, :edge, :linux, :macos, :windows, :iphone, :ipad, :android, nil)

Returns:

  • (String, nil)

    The new User-Agent string.



127
128
129
130
131
132
# File 'lib/ronin/support/network/http.rb', line 127

def self.user_agent=(new_user_agent)
  @user_agent = case new_user_agent
                when Symbol then UserAgents[new_user_agent]
                else             new_user_agent
                end
end

Instance Method Details

#allowed_methods(path = '*', **kwargs) ⇒ Array<Symbol>

Sends a OPTIONS HTTP request and parses the Allow response header.

Parameters:

  • path (String) (defaults to: '*')

    The path to to make the request for.

  • kwargs (Hash{Symbol => Object})

    Aditional keyword arguments and headers for #request.

Options Hash (**kwargs):

  • :query (String, nil)

    The query-string to append to the request path.

  • :query_params (Hash, nil)

    The query-params to append to the request path.

  • :user (String, nil)

    The user to authenticate as.

  • :password (String, nil)

    The password to authenticate with.

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

    Additional HTTP header names and values to add to the request.

  • :content_type (String, :text, :xml, :html, :json, nil)

    The Content-Type header value for the request. If a Symbol is given it will be resolved to a common MIME type:

    • :text - text/plain
    • :xml - text/xml
    • :html - text/html
    • :json - application/json
  • :accept (String, :text, :xml, :html, :json, nil)

    The Accept header value for the request. If a Symbol is given it will be resolved to a common MIME type:

    • :text - text/plain
    • :xml - text/xml
    • :html - text/html
    • :json - application/json
  • :cookie (String, Hash{String => String}, Cookie, nil)

    Additional Cookie header. If a Hash is given, it will be converted to a String using Cookie. If the cookie value is empty, the Cookie header will not be set.

  • :body (String, nil)

    The body of the request.

  • :form_data (Hash, String, nil)

    The form data that may be sent in the body of the request.

  • :json (#to_json, nil)

    The JSON data that will be sent in the body of the request. Will also default the Content-Type header to application/json, unless already set.

Returns:

  • (Array<Symbol>)

    The allowed HTTP request methods for the given path.

Since:

  • 1.0.0



1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
# File 'lib/ronin/support/network/http.rb', line 1257

def allowed_methods(path='*',**kwargs)
  response = options(path,**kwargs)
  allow    = response['Allow']
  methods  = allow.split(', ')

  methods.map! do |method|
    method.downcase!
    method.to_sym
  end

  return methods
end

#closeObject

Closes the HTTP connection.

Since:

  • 1.0.0



1474
1475
1476
# File 'lib/ronin/support/network/http.rb', line 1474

def close
  @http.finish if @http.started?
end

#copy(path, **kwargs) {|response| ... } ⇒ Net::HTTPResponse

Sends a COPY HTTP request.

Parameters:

  • path (String)

    The path to to make the request for.

  • kwargs (Hash{Symbol => Object})

    Aditional keyword arguments and headers for #request.

Options Hash (**kwargs):

  • :query (String, nil)

    The query-string to append to the request path.

  • :query_params (Hash, nil)

    The query-params to append to the request path.

  • :user (String, nil)

    The user to authenticate as.

  • :password (String, nil)

    The password to authenticate with.

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

    Additional HTTP header names and values to add to the request.

  • :content_type (String, :text, :xml, :html, :json, nil)

    The Content-Type header value for the request. If a Symbol is given it will be resolved to a common MIME type:

    • :text - text/plain
    • :xml - text/xml
    • :html - text/html
    • :json - application/json
  • :accept (String, :text, :xml, :html, :json, nil)

    The Accept header value for the request. If a Symbol is given it will be resolved to a common MIME type:

    • :text - text/plain
    • :xml - text/xml
    • :html - text/html
    • :json - application/json
  • :cookie (String, Hash{String => String}, Cookie, nil)

    Additional Cookie header. If a Hash is given, it will be converted to a String using Cookie. If the cookie value is empty, the Cookie header will not be set.

  • :body (String, nil)

    The body of the request.

  • :form_data (Hash, String, nil)

    The form data that may be sent in the body of the request.

  • :json (#to_json, nil)

    The JSON data that will be sent in the body of the request. Will also default the Content-Type header to application/json, unless already set.

Yields:

  • (response)

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

Yield Parameters:

  • response (Net::HTTPResponse)

    The received HTTP response object.

Returns:

  • (Net::HTTPResponse)

    The new HTTP Request object.

Since:

  • 1.0.0



996
997
998
# File 'lib/ronin/support/network/http.rb', line 996

def copy(path,**kwargs,&block)
  request(:copy,path,**kwargs,&block)
end

#delete(path, **kwargs) {|response| ... } ⇒ Net::HTTPResponse

Sends a DELETE HTTP request.

Parameters:

  • path (String)

    The path to to make the request for.

  • kwargs (Hash{Symbol => Object})

    Aditional keyword arguments and headers for #request.

Options Hash (**kwargs):

  • :query (String, nil)

    The query-string to append to the request path.

  • :query_params (Hash, nil)

    The query-params to append to the request path.

  • :user (String, nil)

    The user to authenticate as.

  • :password (String, nil)

    The password to authenticate with.

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

    Additional HTTP header names and values to add to the request.

  • :content_type (String, :text, :xml, :html, :json, nil)

    The Content-Type header value for the request. If a Symbol is given it will be resolved to a common MIME type:

    • :text - text/plain
    • :xml - text/xml
    • :html - text/html
    • :json - application/json
  • :accept (String, :text, :xml, :html, :json, nil)

    The Accept header value for the request. If a Symbol is given it will be resolved to a common MIME type:

    • :text - text/plain
    • :xml - text/xml
    • :html - text/html
    • :json - application/json
  • :cookie (String, Hash{String => String}, Cookie, nil)

    Additional Cookie header. If a Hash is given, it will be converted to a String using Cookie. If the cookie value is empty, the Cookie header will not be set.

  • :body (String, nil)

    The body of the request.

  • :form_data (Hash, String, nil)

    The form data that may be sent in the body of the request.

  • :json (#to_json, nil)

    The JSON data that will be sent in the body of the request. Will also default the Content-Type header to application/json, unless already set.

Yields:

  • (response)

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

Yield Parameters:

  • response (Net::HTTPResponse)

    The received HTTP response object.

Returns:

  • (Net::HTTPResponse)

    The new HTTP Request object.

Since:

  • 1.0.0



1019
1020
1021
# File 'lib/ronin/support/network/http.rb', line 1019

def delete(path,**kwargs,&block)
  request(:delete,path,**kwargs,&block)
end

#get(path, **kwargs) {|response| ... } ⇒ Net::HTTPResponse

Sends a GET HTTP request.

Parameters:

  • path (String)

    The path to to make the request for.

  • kwargs (Hash{Symbol => Object})

    Aditional keyword arguments and headers for #request.

Options Hash (**kwargs):

  • :query (String, nil)

    The query-string to append to the request path.

  • :query_params (Hash, nil)

    The query-params to append to the request path.

  • :user (String, nil)

    The user to authenticate as.

  • :password (String, nil)

    The password to authenticate with.

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

    Additional HTTP header names and values to add to the request.

  • :content_type (String, :text, :xml, :html, :json, nil)

    The Content-Type header value for the request. If a Symbol is given it will be resolved to a common MIME type:

    • :text - text/plain
    • :xml - text/xml
    • :html - text/html
    • :json - application/json
  • :accept (String, :text, :xml, :html, :json, nil)

    The Accept header value for the request. If a Symbol is given it will be resolved to a common MIME type:

    • :text - text/plain
    • :xml - text/xml
    • :html - text/html
    • :json - application/json
  • :cookie (String, Hash{String => String}, Cookie, nil)

    Additional Cookie header. If a Hash is given, it will be converted to a String using Cookie. If the cookie value is empty, the Cookie header will not be set.

  • :body (String, nil)

    The body of the request.

  • :form_data (Hash, String, nil)

    The form data that may be sent in the body of the request.

  • :json (#to_json, nil)

    The JSON data that will be sent in the body of the request. Will also default the Content-Type header to application/json, unless already set.

Yields:

  • (response)

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

Yield Parameters:

  • response (Net::HTTPResponse)

    The received HTTP response object.

Returns:

  • (Net::HTTPResponse)

    The new HTTP Request object.

Since:

  • 1.0.0



1042
1043
1044
# File 'lib/ronin/support/network/http.rb', line 1042

def get(path,**kwargs,&block)
  request(:get,path,**kwargs,&block)
end

#get_body(path, **kwargs) ⇒ String

Sends a GET HTTP request and returns the response body.

Parameters:

  • path (String)

    The path to to make the request for.

  • kwargs (Hash{Symbol => Object})

    Aditional keyword arguments and headers for #request.

Options Hash (**kwargs):

  • :query (String, nil)

    The query-string to append to the request path.

  • :query_params (Hash, nil)

    The query-params to append to the request path.

  • :user (String, nil)

    The user to authenticate as.

  • :password (String, nil)

    The password to authenticate with.

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

    Additional HTTP header names and values to add to the request.

  • :content_type (String, :text, :xml, :html, :json, nil)

    The Content-Type header value for the request. If a Symbol is given it will be resolved to a common MIME type:

    • :text - text/plain
    • :xml - text/xml
    • :html - text/html
    • :json - application/json
  • :accept (String, :text, :xml, :html, :json, nil)

    The Accept header value for the request. If a Symbol is given it will be resolved to a common MIME type:

    • :text - text/plain
    • :xml - text/xml
    • :html - text/html
    • :json - application/json
  • :cookie (String, Hash{String => String}, Cookie, nil)

    Additional Cookie header. If a Hash is given, it will be converted to a String using Cookie. If the cookie value is empty, the Cookie header will not be set.

  • :body (String, nil)

    The body of the request.

  • :form_data (Hash, String, nil)

    The form data that may be sent in the body of the request.

  • :json (#to_json, nil)

    The JSON data that will be sent in the body of the request. Will also default the Content-Type header to application/json, unless already set.

Returns:

  • (String)

    The response body.

Since:

  • 1.0.0



1124
1125
1126
# File 'lib/ronin/support/network/http.rb', line 1124

def get_body(path,**kwargs)
  response_body(:get,path,**kwargs)
end

#get_cookies(path, **kwargs) ⇒ Array<SetCookie>

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

Parameters:

  • path (String)

    The path to to make the request for.

  • kwargs (Hash{Symbol => Object})

    Aditional keyword arguments and headers for #request.

Options Hash (**kwargs):

  • :query (String, nil)

    The query-string to append to the request path.

  • :query_params (Hash, nil)

    The query-params to append to the request path.

  • :user (String, nil)

    The user to authenticate as.

  • :password (String, nil)

    The password to authenticate with.

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

    Additional HTTP header names and values to add to the request.

  • :content_type (String, :text, :xml, :html, :json, nil)

    The Content-Type header value for the request. If a Symbol is given it will be resolved to a common MIME type:

    • :text - text/plain
    • :xml - text/xml
    • :html - text/html
    • :json - application/json
  • :accept (String, :text, :xml, :html, :json, nil)

    The Accept header value for the request. If a Symbol is given it will be resolved to a common MIME type:

    • :text - text/plain
    • :xml - text/xml
    • :html - text/html
    • :json - application/json
  • :cookie (String, Hash{String => String}, Cookie, nil)

    Additional Cookie header. If a Hash is given, it will be converted to a String using Cookie. If the cookie value is empty, the Cookie header will not be set.

  • :body (String, nil)

    The body of the request.

  • :form_data (Hash, String, nil)

    The form data that may be sent in the body of the request.

  • :json (#to_json, nil)

    The JSON data that will be sent in the body of the request. Will also default the Content-Type header to application/json, unless already set.

Returns:

Since:

  • 1.0.0



1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
# File 'lib/ronin/support/network/http.rb', line 1076

def get_cookies(path, **kwargs)
  response = request(:get,path,**kwargs)

  if (set_cookies = response.get_fields('Set-Cookie'))
    set_cookies.map do |cookie|
      SetCookie.parse(cookie)
    end
  else
    []
  end
end

#get_headers(path, **kwargs) ⇒ Hash{String => String}

Sends a GET HTTP request and returns the response headers.

Parameters:

  • path (String)

    The path to to make the request for.

  • kwargs (Hash{Symbol => Object})

    Aditional keyword arguments and headers for #request.

Options Hash (**kwargs):

  • :query (String, nil)

    The query-string to append to the request path.

  • :query_params (Hash, nil)

    The query-params to append to the request path.

  • :user (String, nil)

    The user to authenticate as.

  • :password (String, nil)

    The password to authenticate with.

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

    Additional HTTP header names and values to add to the request.

  • :content_type (String, :text, :xml, :html, :json, nil)

    The Content-Type header value for the request. If a Symbol is given it will be resolved to a common MIME type:

    • :text - text/plain
    • :xml - text/xml
    • :html - text/html
    • :json - application/json
  • :accept (String, :text, :xml, :html, :json, nil)

    The Accept header value for the request. If a Symbol is given it will be resolved to a common MIME type:

    • :text - text/plain
    • :xml - text/xml
    • :html - text/html
    • :json - application/json
  • :cookie (String, Hash{String => String}, Cookie, nil)

    Additional Cookie header. If a Hash is given, it will be converted to a String using Cookie. If the cookie value is empty, the Cookie header will not be set.

  • :body (String, nil)

    The body of the request.

  • :form_data (Hash, String, nil)

    The form data that may be sent in the body of the request.

  • :json (#to_json, nil)

    The JSON data that will be sent in the body of the request. Will also default the Content-Type header to application/json, unless already set.

Returns:

Since:

  • 1.0.0



1059
1060
1061
# File 'lib/ronin/support/network/http.rb', line 1059

def get_headers(path,**kwargs)
  response_headers(:get,path,**kwargs)
end

#head(path, **kwargs) {|response| ... } ⇒ Net::HTTPResponse

Sends a HEAD HTTP request.

Parameters:

  • path (String)

    The path to to make the request for.

  • kwargs (Hash{Symbol => Object})

    Aditional keyword arguments and headers for #request.

Options Hash (**kwargs):

  • :query (String, nil)

    The query-string to append to the request path.

  • :query_params (Hash, nil)

    The query-params to append to the request path.

  • :user (String, nil)

    The user to authenticate as.

  • :password (String, nil)

    The password to authenticate with.

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

    Additional HTTP header names and values to add to the request.

  • :content_type (String, :text, :xml, :html, :json, nil)

    The Content-Type header value for the request. If a Symbol is given it will be resolved to a common MIME type:

    • :text - text/plain
    • :xml - text/xml
    • :html - text/html
    • :json - application/json
  • :accept (String, :text, :xml, :html, :json, nil)

    The Accept header value for the request. If a Symbol is given it will be resolved to a common MIME type:

    • :text - text/plain
    • :xml - text/xml
    • :html - text/html
    • :json - application/json
  • :cookie (String, Hash{String => String}, Cookie, nil)

    Additional Cookie header. If a Hash is given, it will be converted to a String using Cookie. If the cookie value is empty, the Cookie header will not be set.

  • :body (String, nil)

    The body of the request.

  • :form_data (Hash, String, nil)

    The form data that may be sent in the body of the request.

  • :json (#to_json, nil)

    The JSON data that will be sent in the body of the request. Will also default the Content-Type header to application/json, unless already set.

Yields:

  • (response)

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

Yield Parameters:

  • response (Net::HTTPResponse)

    The received HTTP response object.

Returns:

  • (Net::HTTPResponse)

    The new HTTP Request object.

Since:

  • 1.0.0



1147
1148
1149
# File 'lib/ronin/support/network/http.rb', line 1147

def head(path,**kwargs,&block)
  request(:head,path,**kwargs,&block)
end

#lock(path, **kwargs) {|response| ... } ⇒ Net::HTTPResponse

Sends a LOCK HTTP request.

Parameters:

  • path (String)

    The path to to make the request for.

  • kwargs (Hash{Symbol => Object})

    Aditional keyword arguments and headers for #request.

Options Hash (**kwargs):

  • :query (String, nil)

    The query-string to append to the request path.

  • :query_params (Hash, nil)

    The query-params to append to the request path.

  • :user (String, nil)

    The user to authenticate as.

  • :password (String, nil)

    The password to authenticate with.

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

    Additional HTTP header names and values to add to the request.

  • :content_type (String, :text, :xml, :html, :json, nil)

    The Content-Type header value for the request. If a Symbol is given it will be resolved to a common MIME type:

    • :text - text/plain
    • :xml - text/xml
    • :html - text/html
    • :json - application/json
  • :accept (String, :text, :xml, :html, :json, nil)

    The Accept header value for the request. If a Symbol is given it will be resolved to a common MIME type:

    • :text - text/plain
    • :xml - text/xml
    • :html - text/html
    • :json - application/json
  • :cookie (String, Hash{String => String}, Cookie, nil)

    Additional Cookie header. If a Hash is given, it will be converted to a String using Cookie. If the cookie value is empty, the Cookie header will not be set.

  • :body (String, nil)

    The body of the request.

  • :form_data (Hash, String, nil)

    The form data that may be sent in the body of the request.

  • :json (#to_json, nil)

    The JSON data that will be sent in the body of the request. Will also default the Content-Type header to application/json, unless already set.

Yields:

  • (response)

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

Yield Parameters:

  • response (Net::HTTPResponse)

    The received HTTP response object.

Returns:

  • (Net::HTTPResponse)

    The new HTTP Request object.

Since:

  • 1.0.0



1170
1171
1172
# File 'lib/ronin/support/network/http.rb', line 1170

def lock(path,**kwargs,&block)
  request(:lock,path,**kwargs,&block)
end

#mkcol(path, **kwargs) {|response| ... } ⇒ Net::HTTPResponse

Sends a MKCOL HTTP request.

Parameters:

  • path (String)

    The path to to make the request for.

  • kwargs (Hash{Symbol => Object})

    Aditional keyword arguments and headers for #request.

Options Hash (**kwargs):

  • :query (String, nil)

    The query-string to append to the request path.

  • :query_params (Hash, nil)

    The query-params to append to the request path.

  • :user (String, nil)

    The user to authenticate as.

  • :password (String, nil)

    The password to authenticate with.

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

    Additional HTTP header names and values to add to the request.

  • :content_type (String, :text, :xml, :html, :json, nil)

    The Content-Type header value for the request. If a Symbol is given it will be resolved to a common MIME type:

    • :text - text/plain
    • :xml - text/xml
    • :html - text/html
    • :json - application/json
  • :accept (String, :text, :xml, :html, :json, nil)

    The Accept header value for the request. If a Symbol is given it will be resolved to a common MIME type:

    • :text - text/plain
    • :xml - text/xml
    • :html - text/html
    • :json - application/json
  • :cookie (String, Hash{String => String}, Cookie, nil)

    Additional Cookie header. If a Hash is given, it will be converted to a String using Cookie. If the cookie value is empty, the Cookie header will not be set.

  • :body (String, nil)

    The body of the request.

  • :form_data (Hash, String, nil)

    The form data that may be sent in the body of the request.

  • :json (#to_json, nil)

    The JSON data that will be sent in the body of the request. Will also default the Content-Type header to application/json, unless already set.

Yields:

  • (response)

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

Yield Parameters:

  • response (Net::HTTPResponse)

    The received HTTP response object.

Returns:

  • (Net::HTTPResponse)

    The new HTTP Request object.

Since:

  • 1.0.0



1193
1194
1195
# File 'lib/ronin/support/network/http.rb', line 1193

def mkcol(path,**kwargs,&block)
  request(:mkcol,path,**kwargs,&block)
end

#move(path, **kwargs) {|response| ... } ⇒ Net::HTTPResponse

Sends a MOVE HTTP request.

Parameters:

  • path (String)

    The path to to make the request for.

  • kwargs (Hash{Symbol => Object})

    Aditional keyword arguments and headers for #request.

Options Hash (**kwargs):

  • :query (String, nil)

    The query-string to append to the request path.

  • :query_params (Hash, nil)

    The query-params to append to the request path.

  • :user (String, nil)

    The user to authenticate as.

  • :password (String, nil)

    The password to authenticate with.

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

    Additional HTTP header names and values to add to the request.

  • :content_type (String, :text, :xml, :html, :json, nil)

    The Content-Type header value for the request. If a Symbol is given it will be resolved to a common MIME type:

    • :text - text/plain
    • :xml - text/xml
    • :html - text/html
    • :json - application/json
  • :accept (String, :text, :xml, :html, :json, nil)

    The Accept header value for the request. If a Symbol is given it will be resolved to a common MIME type:

    • :text - text/plain
    • :xml - text/xml
    • :html - text/html
    • :json - application/json
  • :cookie (String, Hash{String => String}, Cookie, nil)

    Additional Cookie header. If a Hash is given, it will be converted to a String using Cookie. If the cookie value is empty, the Cookie header will not be set.

  • :body (String, nil)

    The body of the request.

  • :form_data (Hash, String, nil)

    The form data that may be sent in the body of the request.

  • :json (#to_json, nil)

    The JSON data that will be sent in the body of the request. Will also default the Content-Type header to application/json, unless already set.

Yields:

  • (response)

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

Yield Parameters:

  • response (Net::HTTPResponse)

    The received HTTP response object.

Returns:

  • (Net::HTTPResponse)

    The new HTTP Request object.

Since:

  • 1.0.0



1216
1217
1218
# File 'lib/ronin/support/network/http.rb', line 1216

def move(path,**kwargs,&block)
  request(:move,path,**kwargs,&block)
end

#ok?(method = :head, path, **kwargs) ⇒ Boolean

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

The HTTP method to use for the request.

Parameters:

  • method (:copy, :delete, :get, :head, :lock, :mkcol, :move, :options, :patch, :post, :propfind, :proppatch, :put, :trace, :unlock) (defaults to: :head)
  • path (String)

    The path to to make the request for.

  • kwargs (Hash{Symbol => Object})

    Aditional keyword arguments and headers for #request.

Options Hash (**kwargs):

  • :query (String, nil)

    The query-string to append to the request path.

  • :query_params (Hash, nil)

    The query-params to append to the request path.

  • :user (String, nil)

    The user to authenticate as.

  • :password (String, nil)

    The password to authenticate with.

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

    Additional HTTP header names and values to add to the request.

  • :content_type (String, :text, :xml, :html, :json, nil)

    The Content-Type header value for the request. If a Symbol is given it will be resolved to a common MIME type:

    • :text - text/plain
    • :xml - text/xml
    • :html - text/html
    • :json - application/json
  • :accept (String, :text, :xml, :html, :json, nil)

    The Accept header value for the request. If a Symbol is given it will be resolved to a common MIME type:

    • :text - text/plain
    • :xml - text/xml
    • :html - text/html
    • :json - application/json
  • :cookie (String, Hash{String => String}, Cookie, nil)

    Additional Cookie header. If a Hash is given, it will be converted to a String using Cookie. If the cookie value is empty, the Cookie header will not be set.

  • :body (String, nil)

    The body of the request.

  • :form_data (Hash, String, nil)

    The form data that may be sent in the body of the request.

  • :json (#to_json, nil)

    The JSON data that will be sent in the body of the request. Will also default the Content-Type header to application/json, unless already set.

Returns:

  • (Boolean)

    Indicates that the response status was 200.

Since:

  • 1.0.0



877
878
879
# File 'lib/ronin/support/network/http.rb', line 877

def ok?(method=:head,path,**kwargs)
  response_status(method,path,**kwargs) == 200
end

#options(path, **kwargs) {|response| ... } ⇒ Net::HTTPResponse

Sends a OPTIONS HTTP request.

Parameters:

  • path (String)

    The path to to make the request for.

  • kwargs (Hash{Symbol => Object})

    Aditional keyword arguments and headers for #request.

Options Hash (**kwargs):

  • :query (String, nil)

    The query-string to append to the request path.

  • :query_params (Hash, nil)

    The query-params to append to the request path.

  • :user (String, nil)

    The user to authenticate as.

  • :password (String, nil)

    The password to authenticate with.

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

    Additional HTTP header names and values to add to the request.

  • :content_type (String, :text, :xml, :html, :json, nil)

    The Content-Type header value for the request. If a Symbol is given it will be resolved to a common MIME type:

    • :text - text/plain
    • :xml - text/xml
    • :html - text/html
    • :json - application/json
  • :accept (String, :text, :xml, :html, :json, nil)

    The Accept header value for the request. If a Symbol is given it will be resolved to a common MIME type:

    • :text - text/plain
    • :xml - text/xml
    • :html - text/html
    • :json - application/json
  • :cookie (String, Hash{String => String}, Cookie, nil)

    Additional Cookie header. If a Hash is given, it will be converted to a String using Cookie. If the cookie value is empty, the Cookie header will not be set.

  • :body (String, nil)

    The body of the request.

  • :form_data (Hash, String, nil)

    The form data that may be sent in the body of the request.

  • :json (#to_json, nil)

    The JSON data that will be sent in the body of the request. Will also default the Content-Type header to application/json, unless already set.

Yields:

  • (response)

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

Yield Parameters:

  • response (Net::HTTPResponse)

    The received HTTP response object.

Returns:

  • (Net::HTTPResponse)

    The new HTTP Request object.

Since:

  • 1.0.0



1239
1240
1241
# File 'lib/ronin/support/network/http.rb', line 1239

def options(path,**kwargs,&block)
  request(:options,path,**kwargs,&block)
end

#patch(path, **kwargs) {|response| ... } ⇒ Net::HTTPResponse

Sends a PATCH HTTP request.

Parameters:

  • path (String)

    The path to to make the request for.

  • kwargs (Hash{Symbol => Object})

    Aditional keyword arguments and headers for #request.

Options Hash (**kwargs):

  • :query (String, nil)

    The query-string to append to the request path.

  • :query_params (Hash, nil)

    The query-params to append to the request path.

  • :user (String, nil)

    The user to authenticate as.

  • :password (String, nil)

    The password to authenticate with.

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

    Additional HTTP header names and values to add to the request.

  • :content_type (String, :text, :xml, :html, :json, nil)

    The Content-Type header value for the request. If a Symbol is given it will be resolved to a common MIME type:

    • :text - text/plain
    • :xml - text/xml
    • :html - text/html
    • :json - application/json
  • :accept (String, :text, :xml, :html, :json, nil)

    The Accept header value for the request. If a Symbol is given it will be resolved to a common MIME type:

    • :text - text/plain
    • :xml - text/xml
    • :html - text/html
    • :json - application/json
  • :cookie (String, Hash{String => String}, Cookie, nil)

    Additional Cookie header. If a Hash is given, it will be converted to a String using Cookie. If the cookie value is empty, the Cookie header will not be set.

  • :body (String, nil)

    The body of the request.

  • :form_data (Hash, String, nil)

    The form data that may be sent in the body of the request.

  • :json (#to_json, nil)

    The JSON data that will be sent in the body of the request. Will also default the Content-Type header to application/json, unless already set.

Yields:

  • (response)

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

Yield Parameters:

  • response (Net::HTTPResponse)

    The received HTTP response object.

Returns:

  • (Net::HTTPResponse)

    The new HTTP Request object.

Since:

  • 1.0.0



1289
1290
1291
# File 'lib/ronin/support/network/http.rb', line 1289

def patch(path,**kwargs,&block)
  request(:patch,path,**kwargs,&block)
end

#post(path, **kwargs) {|response| ... } ⇒ Net::HTTPResponse

Sends a POST HTTP request.

Parameters:

  • path (String)

    The path to to make the request for.

  • kwargs (Hash{Symbol => Object})

    Aditional keyword arguments and headers for #request.

Options Hash (**kwargs):

  • :query (String, nil)

    The query-string to append to the request path.

  • :query_params (Hash, nil)

    The query-params to append to the request path.

  • :user (String, nil)

    The user to authenticate as.

  • :password (String, nil)

    The password to authenticate with.

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

    Additional HTTP header names and values to add to the request.

  • :content_type (String, :text, :xml, :html, :json, nil)

    The Content-Type header value for the request. If a Symbol is given it will be resolved to a common MIME type:

    • :text - text/plain
    • :xml - text/xml
    • :html - text/html
    • :json - application/json
  • :accept (String, :text, :xml, :html, :json, nil)

    The Accept header value for the request. If a Symbol is given it will be resolved to a common MIME type:

    • :text - text/plain
    • :xml - text/xml
    • :html - text/html
    • :json - application/json
  • :cookie (String, Hash{String => String}, Cookie, nil)

    Additional Cookie header. If a Hash is given, it will be converted to a String using Cookie. If the cookie value is empty, the Cookie header will not be set.

  • :body (String, nil)

    The body of the request.

  • :form_data (Hash, String, nil)

    The form data that may be sent in the body of the request.

  • :json (#to_json, nil)

    The JSON data that will be sent in the body of the request. Will also default the Content-Type header to application/json, unless already set.

Yields:

  • (response)

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

Yield Parameters:

  • response (Net::HTTPResponse)

    The received HTTP response object.

Returns:

  • (Net::HTTPResponse)

    The new HTTP Request object.

Since:

  • 1.0.0



1312
1313
1314
# File 'lib/ronin/support/network/http.rb', line 1312

def post(path,**kwargs,&block)
  request(:post,path,**kwargs,&block)
end

#post_body(path, **kwargs) ⇒ String

Sends a POST HTTP request and returns the response body.

Parameters:

  • path (String)

    The path to to make the request for.

  • kwargs (Hash{Symbol => Object})

    Aditional keyword arguments and headers for #request.

Options Hash (**kwargs):

  • :query (String, nil)

    The query-string to append to the request path.

  • :query_params (Hash, nil)

    The query-params to append to the request path.

  • :user (String, nil)

    The user to authenticate as.

  • :password (String, nil)

    The password to authenticate with.

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

    Additional HTTP header names and values to add to the request.

  • :content_type (String, :text, :xml, :html, :json, nil)

    The Content-Type header value for the request. If a Symbol is given it will be resolved to a common MIME type:

    • :text - text/plain
    • :xml - text/xml
    • :html - text/html
    • :json - application/json
  • :accept (String, :text, :xml, :html, :json, nil)

    The Accept header value for the request. If a Symbol is given it will be resolved to a common MIME type:

    • :text - text/plain
    • :xml - text/xml
    • :html - text/html
    • :json - application/json
  • :cookie (String, Hash{String => String}, Cookie, nil)

    Additional Cookie header. If a Hash is given, it will be converted to a String using Cookie. If the cookie value is empty, the Cookie header will not be set.

  • :body (String, nil)

    The body of the request.

  • :form_data (Hash, String, nil)

    The form data that may be sent in the body of the request.

  • :json (#to_json, nil)

    The JSON data that will be sent in the body of the request. Will also default the Content-Type header to application/json, unless already set.

Returns:

  • (String)

    The response body.

Since:

  • 1.0.0



1346
1347
1348
# File 'lib/ronin/support/network/http.rb', line 1346

def post_body(path,**kwargs)
  response_body(:post,path,**kwargs)
end

#post_cookies(path, **kwargs) ⇒ Array<SetCookie>?

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

Parameters:

  • path (String)

    The path to to make the request for.

  • kwargs (Hash{Symbol => Object})

    Aditional keyword arguments and headers for #request.

Options Hash (**kwargs):

  • :query (String, nil)

    The query-string to append to the request path.

  • :query_params (Hash, nil)

    The query-params to append to the request path.

  • :user (String, nil)

    The user to authenticate as.

  • :password (String, nil)

    The password to authenticate with.

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

    Additional HTTP header names and values to add to the request.

  • :content_type (String, :text, :xml, :html, :json, nil)

    The Content-Type header value for the request. If a Symbol is given it will be resolved to a common MIME type:

    • :text - text/plain
    • :xml - text/xml
    • :html - text/html
    • :json - application/json
  • :accept (String, :text, :xml, :html, :json, nil)

    The Accept header value for the request. If a Symbol is given it will be resolved to a common MIME type:

    • :text - text/plain
    • :xml - text/xml
    • :html - text/html
    • :json - application/json
  • :cookie (String, Hash{String => String}, Cookie, nil)

    Additional Cookie header. If a Hash is given, it will be converted to a String using Cookie. If the cookie value is empty, the Cookie header will not be set.

  • :body (String, nil)

    The body of the request.

  • :form_data (Hash, String, nil)

    The form data that may be sent in the body of the request.

  • :json (#to_json, nil)

    The JSON data that will be sent in the body of the request. Will also default the Content-Type header to application/json, unless already set.

Returns:

Since:

  • 1.1.0



1101
1102
1103
1104
1105
1106
1107
1108
1109
# File 'lib/ronin/support/network/http.rb', line 1101

def post_cookies(path, **kwargs)
  response = request(:post,path,**kwargs)

  if (set_cookies = response.get_fields('Set-Cookie'))
    set_cookies.map do |cookie|
      SetCookie.parse(cookie)
    end
  end
end

#post_headers(path, **kwargs) ⇒ Hash{String => String}

Sends a POST HTTP request and returns the response headers.

Parameters:

  • path (String)

    The path to to make the request for.

  • kwargs (Hash{Symbol => Object})

    Aditional keyword arguments and headers for #request.

Options Hash (**kwargs):

  • :query (String, nil)

    The query-string to append to the request path.

  • :query_params (Hash, nil)

    The query-params to append to the request path.

  • :user (String, nil)

    The user to authenticate as.

  • :password (String, nil)

    The password to authenticate with.

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

    Additional HTTP header names and values to add to the request.

  • :content_type (String, :text, :xml, :html, :json, nil)

    The Content-Type header value for the request. If a Symbol is given it will be resolved to a common MIME type:

    • :text - text/plain
    • :xml - text/xml
    • :html - text/html
    • :json - application/json
  • :accept (String, :text, :xml, :html, :json, nil)

    The Accept header value for the request. If a Symbol is given it will be resolved to a common MIME type:

    • :text - text/plain
    • :xml - text/xml
    • :html - text/html
    • :json - application/json
  • :cookie (String, Hash{String => String}, Cookie, nil)

    Additional Cookie header. If a Hash is given, it will be converted to a String using Cookie. If the cookie value is empty, the Cookie header will not be set.

  • :body (String, nil)

    The body of the request.

  • :form_data (Hash, String, nil)

    The form data that may be sent in the body of the request.

  • :json (#to_json, nil)

    The JSON data that will be sent in the body of the request. Will also default the Content-Type header to application/json, unless already set.

Returns:

Since:

  • 1.0.0



1329
1330
1331
# File 'lib/ronin/support/network/http.rb', line 1329

def post_headers(path,**kwargs)
  response_headers(:post,path,**kwargs)
end

#powered_by_header(method: :head, path: '/', **kwargs) ⇒ String?

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

The HTTP method to use for the request.

Parameters:

  • method (:copy, :delete, :get, :head, :lock, :mkcol, :move, :options, :patch, :post, :propfind, :proppatch, :put, :trace, :unlock) (defaults to: :head)
  • path (String) (defaults to: '/')

    The path to to make the request for.

  • kwargs (Hash{Symbol => Object})

    Aditional keyword arguments and headers for #request.

Options Hash (**kwargs):

  • :query (String, nil)

    The query-string to append to the request path.

  • :query_params (Hash, nil)

    The query-params to append to the request path.

  • :user (String, nil)

    The user to authenticate as.

  • :password (String, nil)

    The password to authenticate with.

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

    Additional HTTP header names and values to add to the request.

  • :content_type (String, :text, :xml, :html, :json, nil)

    The Content-Type header value for the request. If a Symbol is given it will be resolved to a common MIME type:

    • :text - text/plain
    • :xml - text/xml
    • :html - text/html
    • :json - application/json
  • :accept (String, :text, :xml, :html, :json, nil)

    The Accept header value for the request. If a Symbol is given it will be resolved to a common MIME type:

    • :text - text/plain
    • :xml - text/xml
    • :html - text/html
    • :json - application/json
  • :cookie (String, Hash{String => String}, Cookie, nil)

    Additional Cookie header. If a Hash is given, it will be converted to a String using Cookie. If the cookie value is empty, the Cookie header will not be set.

  • :body (String, nil)

    The body of the request.

  • :form_data (Hash, String, nil)

    The form data that may be sent in the body of the request.

  • :json (#to_json, nil)

    The JSON data that will be sent in the body of the request. Will also default the Content-Type header to application/json, unless already set.

Returns:

  • (String, nil)

    The X-Powered-By header.

Since:

  • 1.0.0



950
951
952
953
# File 'lib/ronin/support/network/http.rb', line 950

def powered_by_header(method: :head, path: '/',**kwargs)
  response = request(method,path,**kwargs)
  response['X-Powered-By']
end

#prop_find {|response| ... } ⇒ Net::HTTPResponse

Sends a PROPFIND HTTP request.

Parameters:

  • path (String)

    The path to to make the request for.

  • kwargs (Hash{Symbol => Object})

    Aditional keyword arguments and headers for #request.

Yields:

  • (response)

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

Yield Parameters:

  • response (Net::HTTPResponse)

    The received HTTP response object.

Returns:

  • (Net::HTTPResponse)

    The new HTTP Request object.

Since:

  • 1.0.0



1373
1374
1375
# File 'lib/ronin/support/network/http.rb', line 1373

def propfind(path,**kwargs,&block)
  request(:propfind,path,**kwargs,&block)
end

#prop_patch {|response| ... } ⇒ Net::HTTPResponse

Sends a PROPPATCH HTTP request.

Parameters:

  • path (String)

    The path to to make the request for.

  • kwargs (Hash{Symbol => Object})

    Aditional keyword arguments and headers for #request.

Yields:

  • (response)

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

Yield Parameters:

  • response (Net::HTTPResponse)

    The received HTTP response object.

Returns:

  • (Net::HTTPResponse)

    The new HTTP Request object.

Since:

  • 1.0.0



1398
1399
1400
# File 'lib/ronin/support/network/http.rb', line 1398

def proppatch(path,**kwargs,&block)
  request(:proppatch,path,**kwargs,&block)
end

#propfind(path, **kwargs) {|response| ... } ⇒ Net::HTTPResponse

Sends a PROPFIND HTTP request.

Parameters:

  • path (String)

    The path to to make the request for.

  • kwargs (Hash{Symbol => Object})

    Aditional keyword arguments and headers for #request.

Options Hash (**kwargs):

  • :query (String, nil)

    The query-string to append to the request path.

  • :query_params (Hash, nil)

    The query-params to append to the request path.

  • :user (String, nil)

    The user to authenticate as.

  • :password (String, nil)

    The password to authenticate with.

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

    Additional HTTP header names and values to add to the request.

  • :content_type (String, :text, :xml, :html, :json, nil)

    The Content-Type header value for the request. If a Symbol is given it will be resolved to a common MIME type:

    • :text - text/plain
    • :xml - text/xml
    • :html - text/html
    • :json - application/json
  • :accept (String, :text, :xml, :html, :json, nil)

    The Accept header value for the request. If a Symbol is given it will be resolved to a common MIME type:

    • :text - text/plain
    • :xml - text/xml
    • :html - text/html
    • :json - application/json
  • :cookie (String, Hash{String => String}, Cookie, nil)

    Additional Cookie header. If a Hash is given, it will be converted to a String using Cookie. If the cookie value is empty, the Cookie header will not be set.

  • :body (String, nil)

    The body of the request.

  • :form_data (Hash, String, nil)

    The form data that may be sent in the body of the request.

  • :json (#to_json, nil)

    The JSON data that will be sent in the body of the request. Will also default the Content-Type header to application/json, unless already set.

Yields:

  • (response)

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

Yield Parameters:

  • response (Net::HTTPResponse)

    The received HTTP response object.

Returns:

  • (Net::HTTPResponse)

    The new HTTP Request object.

Since:

  • 1.0.0



1369
1370
1371
# File 'lib/ronin/support/network/http.rb', line 1369

def propfind(path,**kwargs,&block)
  request(:propfind,path,**kwargs,&block)
end

#proppatch(path, **kwargs) {|response| ... } ⇒ Net::HTTPResponse

Sends a PROPPATCH HTTP request.

Parameters:

  • path (String)

    The path to to make the request for.

  • kwargs (Hash{Symbol => Object})

    Aditional keyword arguments and headers for #request.

Options Hash (**kwargs):

  • :query (String, nil)

    The query-string to append to the request path.

  • :query_params (Hash, nil)

    The query-params to append to the request path.

  • :user (String, nil)

    The user to authenticate as.

  • :password (String, nil)

    The password to authenticate with.

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

    Additional HTTP header names and values to add to the request.

  • :content_type (String, :text, :xml, :html, :json, nil)

    The Content-Type header value for the request. If a Symbol is given it will be resolved to a common MIME type:

    • :text - text/plain
    • :xml - text/xml
    • :html - text/html
    • :json - application/json
  • :accept (String, :text, :xml, :html, :json, nil)

    The Accept header value for the request. If a Symbol is given it will be resolved to a common MIME type:

    • :text - text/plain
    • :xml - text/xml
    • :html - text/html
    • :json - application/json
  • :cookie (String, Hash{String => String}, Cookie, nil)

    Additional Cookie header. If a Hash is given, it will be converted to a String using Cookie. If the cookie value is empty, the Cookie header will not be set.

  • :body (String, nil)

    The body of the request.

  • :form_data (Hash, String, nil)

    The form data that may be sent in the body of the request.

  • :json (#to_json, nil)

    The JSON data that will be sent in the body of the request. Will also default the Content-Type header to application/json, unless already set.

Yields:

  • (response)

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

Yield Parameters:

  • response (Net::HTTPResponse)

    The received HTTP response object.

Returns:

  • (Net::HTTPResponse)

    The new HTTP Request object.

Since:

  • 1.0.0



1394
1395
1396
# File 'lib/ronin/support/network/http.rb', line 1394

def proppatch(path,**kwargs,&block)
  request(:proppatch,path,**kwargs,&block)
end

#put(path, **kwargs) {|response| ... } ⇒ Net::HTTPResponse

Sends a PUT HTTP request.

Parameters:

  • path (String)

    The path to to make the request for.

  • kwargs (Hash{Symbol => Object})

    Aditional keyword arguments and headers for #request.

Options Hash (**kwargs):

  • :query (String, nil)

    The query-string to append to the request path.

  • :query_params (Hash, nil)

    The query-params to append to the request path.

  • :user (String, nil)

    The user to authenticate as.

  • :password (String, nil)

    The password to authenticate with.

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

    Additional HTTP header names and values to add to the request.

  • :content_type (String, :text, :xml, :html, :json, nil)

    The Content-Type header value for the request. If a Symbol is given it will be resolved to a common MIME type:

    • :text - text/plain
    • :xml - text/xml
    • :html - text/html
    • :json - application/json
  • :accept (String, :text, :xml, :html, :json, nil)

    The Accept header value for the request. If a Symbol is given it will be resolved to a common MIME type:

    • :text - text/plain
    • :xml - text/xml
    • :html - text/html
    • :json - application/json
  • :cookie (String, Hash{String => String}, Cookie, nil)

    Additional Cookie header. If a Hash is given, it will be converted to a String using Cookie. If the cookie value is empty, the Cookie header will not be set.

  • :body (String, nil)

    The body of the request.

  • :form_data (Hash, String, nil)

    The form data that may be sent in the body of the request.

  • :json (#to_json, nil)

    The JSON data that will be sent in the body of the request. Will also default the Content-Type header to application/json, unless already set.

Yields:

  • (response)

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

Yield Parameters:

  • response (Net::HTTPResponse)

    The received HTTP response object.

Returns:

  • (Net::HTTPResponse)

    The new HTTP Request object.

Since:

  • 1.0.0



1419
1420
1421
# File 'lib/ronin/support/network/http.rb', line 1419

def put(path,**kwargs,&block)
  request(:put,path,**kwargs,&block)
end

#request(method, path, query: nil, query_params: nil, headers: nil, content_type: nil, accept: nil, user_agent: @user_agent, cookie: @cookie, user: @user, password: @password, body: nil, form_data: nil, json: nil, **additional_headers) {|response| ... } ⇒ Net::HTTPResponse

Sends an arbitrary HTTP request.

The HTTP method to use for the request.

Examples:

http.request(:get, '/')

Streaming response body:

http.request(:get, '/big_file.txt') do |response|
  respnse.read_body do |chunk|
    # ...
  end
end

Basic-Auth

http.request(:get, '/', user: 'admin', password: 'secret')

Query string:

http.request(:get, '/search', query: 'foo%20bar')

Query params:

http.request(:get, '/search', query_params: {q: 'foo bar'})

Request body:

http.request(:post, '/form', body: 'foo=1&bar=2')

Form data:

http.request(:post, '/form', form_data: {'foo' => 1, 'bar' => 2})

Streaming request body:

http.request(:put, '/file', body: File.new('/path/to/file'))

Parameters:

  • method (:copy, :delete, :get, :head, :lock, :mkcol, :move, :options, :patch, :post, :propfind, :proppatch, :put, :trace, :unlock)
  • path (String)

    The path to to make the request for.

  • query (String, nil) (defaults to: nil)

    The query-string to append to the request path.

  • query_params (Hash, nil) (defaults to: nil)

    The query-params to append to the request path.

  • user (String, nil) (defaults to: @user)

    The user to authenticate as.

  • password (String, nil) (defaults to: @password)

    The password to authenticate with.

  • headers (Hash{Symbol,String => String}, nil) (defaults to: nil)

    Additional HTTP header names and values to add to the request.

  • content_type (String, :text, :xml, :html, :json, nil) (defaults to: nil)

    The Content-Type header value for the request. If a Symbol is given it will be resolved to a common MIME type:

    • :text - text/plain
    • :xml - text/xml
    • :html - text/html
    • :json - application/json
  • accept (String, :text, :xml, :html, :json, nil) (defaults to: nil)

    The Accept header value for the request. If a Symbol is given it will be resolved to a common MIME type:

    • :text - text/plain
    • :xml - text/xml
    • :html - text/html
    • :json - application/json
  • cookie (String, Hash{String => String}, nil) (defaults to: @cookie)

    Additional Cookie header. If a Hash is given, it will be converted to a String using Cookie.

  • body (String, nil) (defaults to: nil)

    The body of the request.

  • form_data (Hash, String, nil) (defaults to: nil)

    The form data that may be sent in the body of the request.

  • json (#to_json, nil) (defaults to: nil)

    The JSON data that will be sent in the body of the request. Will also default the Content-Type header to application/json, unless already set.

  • additional_headers (Hash{Symbol => String})

    Additional headers to add to the request.

Yields:

  • (response)

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

Yield Parameters:

  • response (Net::HTTPResponse)

    The received HTTP response object.

Returns:

  • (Net::HTTPResponse)

    The new HTTP Request object.

Raises:

  • (ArgumentError)

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

Since:

  • 1.0.0



735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
# File 'lib/ronin/support/network/http.rb', line 735

def request(method,path, # query string keyword arguments
                         query:        nil,
                         query_params: nil,
                         # header keyword arguments
                         headers:      nil,
                         content_type: nil,
                         accept:       nil,
                         user_agent:   @user_agent,
                         cookie:       @cookie,
                         # Basic-Auth keyword arguments
                         user:     @user,
                         password: @password,
                         # request body keyword arguments
                         body:      nil,
                         form_data: nil,
                         json:      nil,
                         **additional_headers,
                         &block)
  request = Request.build(method,path, headers:      @headers,
                                       content_type: content_type,
                                       accept:       accept,
                                       user_agent:   user_agent,
                                       cookie:       cookie,
                                       user:         user,
                                       password:     password,
                                       query:        query,
                                       query_params: query_params,
                                       body:         body,
                                       form_data:    form_data,
                                       json:         json)

  if headers
    # populate any arbitrary headers
    headers.each do |name,value|
      request[name] = value
    end
  end

  unless additional_headers.empty?
    # set additional keyword argument headers (ex: `referer: '...'`
    additional_headers.each do |name,value|
      request[name] = value
    end
  end

  return @http.request(request,&block)
end

#response_body(method = :get, path, **kwargs) ⇒ String

Sends an arbitrary HTTP request and returns the response body.

The HTTP method to use for the request.

Parameters:

  • method (:copy, :delete, :get, :head, :lock, :mkcol, :move, :options, :patch, :post, :propfind, :proppatch, :put, :trace, :unlock) (defaults to: :get)
  • path (String)

    The path to to make the request for.

  • kwargs (Hash{Symbol => Object})

    Aditional keyword arguments and headers for #request.

Options Hash (**kwargs):

  • :query (String, nil)

    The query-string to append to the request path.

  • :query_params (Hash, nil)

    The query-params to append to the request path.

  • :user (String, nil)

    The user to authenticate as.

  • :password (String, nil)

    The password to authenticate with.

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

    Additional HTTP header names and values to add to the request.

  • :content_type (String, :text, :xml, :html, :json, nil)

    The Content-Type header value for the request. If a Symbol is given it will be resolved to a common MIME type:

    • :text - text/plain
    • :xml - text/xml
    • :html - text/html
    • :json - application/json
  • :accept (String, :text, :xml, :html, :json, nil)

    The Accept header value for the request. If a Symbol is given it will be resolved to a common MIME type:

    • :text - text/plain
    • :xml - text/xml
    • :html - text/html
    • :json - application/json
  • :cookie (String, Hash{String => String}, Cookie, nil)

    Additional Cookie header. If a Hash is given, it will be converted to a String using Cookie. If the cookie value is empty, the Cookie header will not be set.

  • :body (String, nil)

    The body of the request.

  • :form_data (Hash, String, nil)

    The form data that may be sent in the body of the request.

  • :json (#to_json, nil)

    The JSON data that will be sent in the body of the request. Will also default the Content-Type header to application/json, unless already set.

Returns:

  • (String)

    The response body.

Since:

  • 1.0.0



973
974
975
# File 'lib/ronin/support/network/http.rb', line 973

def response_body(method=:get,path,**kwargs)
  request(method,path,**kwargs).body
end

#response_headers(method = :head, path, **kwargs) ⇒ Hash{String => String}

Sends an arbitrary HTTP request and returns the response headers.

The HTTP method to use for the request.

Parameters:

  • method (:copy, :delete, :get, :head, :lock, :mkcol, :move, :options, :patch, :post, :propfind, :proppatch, :put, :trace, :unlock) (defaults to: :head)
  • path (String)

    The path to to make the request for.

  • kwargs (Hash{Symbol => Object})

    Aditional keyword arguments and headers for #request.

Options Hash (**kwargs):

  • :query (String, nil)

    The query-string to append to the request path.

  • :query_params (Hash, nil)

    The query-params to append to the request path.

  • :user (String, nil)

    The user to authenticate as.

  • :password (String, nil)

    The password to authenticate with.

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

    Additional HTTP header names and values to add to the request.

  • :content_type (String, :text, :xml, :html, :json, nil)

    The Content-Type header value for the request. If a Symbol is given it will be resolved to a common MIME type:

    • :text - text/plain
    • :xml - text/xml
    • :html - text/html
    • :json - application/json
  • :accept (String, :text, :xml, :html, :json, nil)

    The Accept header value for the request. If a Symbol is given it will be resolved to a common MIME type:

    • :text - text/plain
    • :xml - text/xml
    • :html - text/html
    • :json - application/json
  • :cookie (String, Hash{String => String}, Cookie, nil)

    Additional Cookie header. If a Hash is given, it will be converted to a String using Cookie. If the cookie value is empty, the Cookie header will not be set.

  • :body (String, nil)

    The body of the request.

  • :form_data (Hash, String, nil)

    The form data that may be sent in the body of the request.

  • :json (#to_json, nil)

    The JSON data that will be sent in the body of the request. Will also default the Content-Type header to application/json, unless already set.

Returns:

Since:

  • 1.0.0



899
900
901
902
903
904
905
906
907
# File 'lib/ronin/support/network/http.rb', line 899

def response_headers(method=:head,path,**kwargs)
  headers = {}

  request(method,path,**kwargs).each_capitalized do |name,value|
    headers[name] = value
  end

  return headers
end

#response_status(method = :head, path, **kwargs) ⇒ Integer

Sends an arbitrary HTTP request and returns the response status.

The HTTP method to use for the request.

Parameters:

  • method (:copy, :delete, :get, :head, :lock, :mkcol, :move, :options, :patch, :post, :propfind, :proppatch, :put, :trace, :unlock) (defaults to: :head)
  • path (String)

    The path to to make the request for.

  • kwargs (Hash{Symbol => Object})

    Aditional keyword arguments and headers for #request.

Options Hash (**kwargs):

  • :query (String, nil)

    The query-string to append to the request path.

  • :query_params (Hash, nil)

    The query-params to append to the request path.

  • :user (String, nil)

    The user to authenticate as.

  • :password (String, nil)

    The password to authenticate with.

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

    Additional HTTP header names and values to add to the request.

  • :content_type (String, :text, :xml, :html, :json, nil)

    The Content-Type header value for the request. If a Symbol is given it will be resolved to a common MIME type:

    • :text - text/plain
    • :xml - text/xml
    • :html - text/html
    • :json - application/json
  • :accept (String, :text, :xml, :html, :json, nil)

    The Accept header value for the request. If a Symbol is given it will be resolved to a common MIME type:

    • :text - text/plain
    • :xml - text/xml
    • :html - text/html
    • :json - application/json
  • :cookie (String, Hash{String => String}, Cookie, nil)

    Additional Cookie header. If a Hash is given, it will be converted to a String using Cookie. If the cookie value is empty, the Cookie header will not be set.

  • :body (String, nil)

    The body of the request.

  • :form_data (Hash, String, nil)

    The form data that may be sent in the body of the request.

  • :json (#to_json, nil)

    The JSON data that will be sent in the body of the request. Will also default the Content-Type header to application/json, unless already set.

Returns:

  • (Integer)

    The response status code.

Since:

  • 1.0.0



854
855
856
857
# File 'lib/ronin/support/network/http.rb', line 854

def response_status(method=:head,path,**kwargs)
  response = request(method,path,**kwargs)
  response.code.to_i
end

#server_header(method: :head, path: '/', **kwargs) ⇒ String?

Sends an HTTP request and returns the Server header.

The HTTP method to use for the request.

Parameters:

  • method (:copy, :delete, :get, :head, :lock, :mkcol, :move, :options, :patch, :post, :propfind, :proppatch, :put, :trace, :unlock) (defaults to: :head)
  • path (String) (defaults to: '/')

    The path to to make the request for.

  • kwargs (Hash{Symbol => Object})

    Aditional keyword arguments and headers for #request.

Options Hash (**kwargs):

  • :query (String, nil)

    The query-string to append to the request path.

  • :query_params (Hash, nil)

    The query-params to append to the request path.

  • :user (String, nil)

    The user to authenticate as.

  • :password (String, nil)

    The password to authenticate with.

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

    Additional HTTP header names and values to add to the request.

  • :content_type (String, :text, :xml, :html, :json, nil)

    The Content-Type header value for the request. If a Symbol is given it will be resolved to a common MIME type:

    • :text - text/plain
    • :xml - text/xml
    • :html - text/html
    • :json - application/json
  • :accept (String, :text, :xml, :html, :json, nil)

    The Accept header value for the request. If a Symbol is given it will be resolved to a common MIME type:

    • :text - text/plain
    • :xml - text/xml
    • :html - text/html
    • :json - application/json
  • :cookie (String, Hash{String => String}, Cookie, nil)

    Additional Cookie header. If a Hash is given, it will be converted to a String using Cookie. If the cookie value is empty, the Cookie header will not be set.

  • :body (String, nil)

    The body of the request.

  • :form_data (Hash, String, nil)

    The form data that may be sent in the body of the request.

  • :json (#to_json, nil)

    The JSON data that will be sent in the body of the request. Will also default the Content-Type header to application/json, unless already set.

Returns:

  • (String, nil)

    The Server header.

Since:

  • 1.0.0



927
928
929
930
# File 'lib/ronin/support/network/http.rb', line 927

def server_header(method: :head, path: '/',**kwargs)
  response = request(method,path,**kwargs)
  response['Server']
end

#ssl?Boolean

Determines if the HTTP connect is using SSL/TLS.

Returns:

  • (Boolean)

Since:

  • 1.0.0



567
568
569
# File 'lib/ronin/support/network/http.rb', line 567

def ssl?
  @http.use_ssl?
end

#trace(path, **kwargs) {|response| ... } ⇒ Net::HTTPResponse

Sends a TRACE HTTP request.

Parameters:

  • path (String)

    The path to to make the request for.

  • kwargs (Hash{Symbol => Object})

    Aditional keyword arguments and headers for #request.

Options Hash (**kwargs):

  • :query (String, nil)

    The query-string to append to the request path.

  • :query_params (Hash, nil)

    The query-params to append to the request path.

  • :user (String, nil)

    The user to authenticate as.

  • :password (String, nil)

    The password to authenticate with.

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

    Additional HTTP header names and values to add to the request.

  • :content_type (String, :text, :xml, :html, :json, nil)

    The Content-Type header value for the request. If a Symbol is given it will be resolved to a common MIME type:

    • :text - text/plain
    • :xml - text/xml
    • :html - text/html
    • :json - application/json
  • :accept (String, :text, :xml, :html, :json, nil)

    The Accept header value for the request. If a Symbol is given it will be resolved to a common MIME type:

    • :text - text/plain
    • :xml - text/xml
    • :html - text/html
    • :json - application/json
  • :cookie (String, Hash{String => String}, Cookie, nil)

    Additional Cookie header. If a Hash is given, it will be converted to a String using Cookie. If the cookie value is empty, the Cookie header will not be set.

  • :body (String, nil)

    The body of the request.

  • :form_data (Hash, String, nil)

    The form data that may be sent in the body of the request.

  • :json (#to_json, nil)

    The JSON data that will be sent in the body of the request. Will also default the Content-Type header to application/json, unless already set.

Yields:

  • (response)

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

Yield Parameters:

  • response (Net::HTTPResponse)

    The received HTTP response object.

Returns:

  • (Net::HTTPResponse)

    The new HTTP Request object.

Since:

  • 1.0.0



1442
1443
1444
# File 'lib/ronin/support/network/http.rb', line 1442

def trace(path,**kwargs,&block)
  request(:trace,path,**kwargs,&block)
end

#unlock(path, **kwargs) {|response| ... } ⇒ Net::HTTPResponse

Sends a UNLOCK HTTP request.

Parameters:

  • path (String)

    The path to to make the request for.

  • kwargs (Hash{Symbol => Object})

    Aditional keyword arguments and headers for #request.

Options Hash (**kwargs):

  • :query (String, nil)

    The query-string to append to the request path.

  • :query_params (Hash, nil)

    The query-params to append to the request path.

  • :user (String, nil)

    The user to authenticate as.

  • :password (String, nil)

    The password to authenticate with.

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

    Additional HTTP header names and values to add to the request.

  • :content_type (String, :text, :xml, :html, :json, nil)

    The Content-Type header value for the request. If a Symbol is given it will be resolved to a common MIME type:

    • :text - text/plain
    • :xml - text/xml
    • :html - text/html
    • :json - application/json
  • :accept (String, :text, :xml, :html, :json, nil)

    The Accept header value for the request. If a Symbol is given it will be resolved to a common MIME type:

    • :text - text/plain
    • :xml - text/xml
    • :html - text/html
    • :json - application/json
  • :cookie (String, Hash{String => String}, Cookie, nil)

    Additional Cookie header. If a Hash is given, it will be converted to a String using Cookie. If the cookie value is empty, the Cookie header will not be set.

  • :body (String, nil)

    The body of the request.

  • :form_data (Hash, String, nil)

    The form data that may be sent in the body of the request.

  • :json (#to_json, nil)

    The JSON data that will be sent in the body of the request. Will also default the Content-Type header to application/json, unless already set.

Yields:

  • (response)

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

Yield Parameters:

  • response (Net::HTTPResponse)

    The received HTTP response object.

Returns:

  • (Net::HTTPResponse)

    The new HTTP Request object.

Since:

  • 1.0.0



1465
1466
1467
# File 'lib/ronin/support/network/http.rb', line 1465

def unlock(path,**kwargs,&block)
  request(:unlock,path,**kwargs,&block)
end