Class: Ronin::Support::Web::Agent

Inherits:
Object
  • Object
show all
Defined in:
lib/ronin/support/web/agent.rb,
lib/ronin/support/web/agent/mixin.rb

Overview

Web Agent represents a stripped-down web browser, which can request URLs, follow redirects, and parse responses.

Features

  • Automatically follows redirects.
  • Provides low-level HTTP methods.
  • Provides high-level methods for requesting and parsing HTML, XML, or JSON.
  • Maintains a persistent connection pool.

Anti-Features

  • Does not cache files or write to the disk.
  • Does not evaluate JavaScript.

Defined Under Namespace

Modules: Mixin Classes: ContentTypeError, Error, TooManyRedirects

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(follow_redirects: true, max_redirects: 20, proxy: Support::Network::HTTP.proxy, ssl: nil, user_agent: Support::Network::HTTP.user_agent) ⇒ Agent

Initializes the Web agent.

Parameters:

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

    The optional proxy to send requests through.

  • 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: Support::Network::HTTP.user_agent)

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

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

    Additional SSL/TLS configuration.

Options Hash (ssl:):

  • :ca_bundle (String, nil)

    The path to the CA bundle directory or file.

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

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



128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
# File 'lib/ronin/support/web/agent.rb', line 128

def initialize(follow_redirects: true,
               max_redirects:    20,
               # HTTP options
               proxy:      Support::Network::HTTP.proxy,
               ssl:        nil,
               user_agent: Support::Network::HTTP.user_agent)
  @follow_redirects = follow_redirects
  @max_redirects    = max_redirects

  # HTTP options
  @proxy      = proxy
  @ssl        = ssl
  @user_agent = user_agent

  @sessions = {}
end

Instance Attribute Details

#max_redirectsInteger (readonly)

Maximum number of redirects to follow.

Returns:

  • (Integer)


81
82
83
# File 'lib/ronin/support/web/agent.rb', line 81

def max_redirects
  @max_redirects
end

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

The proxy to send requests through.

Returns:

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


71
72
73
# File 'lib/ronin/support/web/agent.rb', line 71

def proxy
  @proxy
end

#user_agentString? (readonly)

The User-Agent header value.

Returns:

  • (String, nil)


76
77
78
# File 'lib/ronin/support/web/agent.rb', line 76

def user_agent
  @user_agent
end

Instance Method Details

#follow_redirects?Boolean

Indicates whether redirects will automatically be followed.

Returns:

  • (Boolean)


150
151
152
# File 'lib/ronin/support/web/agent.rb', line 150

def follow_redirects?
  @follow_redirects
end

#get(url, follow_redirects: @follow_redirects, max_redirects: @max_redirects, **kwargs) {|response| ... } ⇒ Net::HTTPResponse

Note:

This method will follow redirects by default.

Gets a URL and returns the response.

Examples:

response = agent.get('https://example.com/')
# => #<Net::HTTPResponse:...>

Parameters:

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

    The URL to create the HTTP GET request for.

  • kwargs (Hash)

    a customizable set of options

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 headers to use for 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}, Ronin::Support::Network::HTTP::Cookie, nil)

    Additional Cookie header.

  • :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 HTTP response object.

Raises:



1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
# File 'lib/ronin/support/web/agent.rb', line 1059

def get(url, follow_redirects: @follow_redirects,
             max_redirects:    @max_redirects,
             **kwargs)
  response = http_get(url,**kwargs)

  if follow_redirects && response.kind_of?(Net::HTTPRedirection)
    redirect_count = 0

    while response.kind_of?(Net::HTTPRedirection)
      if redirect_count >= max_redirects
        raise(TooManyRedirects,"maximum number of redirects reached: #{url.inspect}")
      end

      location = response['Location']
      response = http_get(location)

      redirect_count += 1
    end
  end

  yield response if block_given?
  return response
end

#get_html(url, **kwargs) ⇒ Nokogiri::HTML::Document

Note:

This method will follow redirects by default.

Gets the URL and returns the parsed HTML.

Examples:

doc = agent.get_html('https://example.com/page.html')
# => #<Nokogiri::HTML::Document:...>

Parameters:

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

    The URL to create the HTTP GET request for.

  • kwargs (Hash)

    a customizable set of options

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 headers to use for 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}, Ronin::Support::Network::HTTP::Cookie, nil)

    Additional Cookie header.

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

  • (Nokogiri::HTML::Document)

    The parsed HTML response.

Raises:



1106
1107
1108
1109
1110
1111
1112
1113
1114
# File 'lib/ronin/support/web/agent.rb', line 1106

def get_html(url,**kwargs)
  response = get(url,**kwargs)

  unless response.content_type.include?('text/html')
    raise(ContentTypeError,"response 'Content-Type' was not 'text/html': #{response.content_type.inspect}")
  end

  return Nokogiri::HTML(response.body)
end

#get_json(url, **kwargs) ⇒ Hash{String => Object}, Array

Note:

This method will follow redirects by default.

Gets the URL and returns the parsed JSON.

Examples:

json = agent.get_json('https://example.com/data.json')
# => {...}

Parameters:

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

    The URL to create the HTTP GET request for.

  • kwargs (Hash)

    a customizable set of options

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 headers to use for 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}, Ronin::Support::Network::HTTP::Cookie, nil)

    Additional Cookie header.

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

  • (Hash{String => Object}, Array)

    The parsed JSON.

Raises:



1173
1174
1175
1176
1177
1178
1179
1180
1181
# File 'lib/ronin/support/web/agent.rb', line 1173

def get_json(url,**kwargs)
  response = get(url,**kwargs)

  unless response.content_type.include?('application/json')
    raise(ContentTypeError,"response 'Content-Type' was not 'application/json': #{response.content_type.inspect}")
  end

  return ::JSON.parse(response.body)
end

#get_xml(url, **kwargs) ⇒ Nokogiri::XML::Document

Note:

This method will follow redirects by default.

Gets the URL and returns the parsed XML.

Examples:

doc = agent.get_xml('https://example.com/data.xml')
# => #<Nokogiri::XML::Document:...>

Parameters:

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

    The URL to create the HTTP GET request for.

  • kwargs (Hash)

    a customizable set of options

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 headers to use for 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}, Ronin::Support::Network::HTTP::Cookie, nil)

    Additional Cookie header.

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

  • (Nokogiri::XML::Document)

    The parsed XML response.

Raises:



1139
1140
1141
1142
1143
1144
1145
1146
1147
# File 'lib/ronin/support/web/agent.rb', line 1139

def get_xml(url,**kwargs)
  response = get(url,**kwargs)

  unless response.content_type.include?('text/xml')
    raise(ContentTypeError,"response 'Content-Type' was not 'text/xml': #{response.content_type.inspect}")
  end

  return Nokogiri::XML(response.body)
end

#http_allowed_methods(url, **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)

    The URL to create the HTTP request for.

  • kwargs (Hash)

    a customizable set of options

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 headers to use for 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}, Ronin::Support::Network::HTTP::Cookie, nil)

    Additional Cookie header.

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



750
751
752
753
754
755
756
757
758
# File 'lib/ronin/support/web/agent.rb', line 750

def http_allowed_methods(url,**kwargs)
  uri = normalize_url(url)

  session_for(uri).allowed_methods(
    uri.request_uri, user:     uri.user,
                     password: uri.password,
                     **kwargs
  )
end

#http_copy(url, **kwargs) {|response| ... } ⇒ Net::HTTPResponse

Performs a COPY request for the given URI.

Parameters:

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

    The URL to create the HTTP request for.

  • kwargs (Hash)

    a customizable set of options

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 headers to use for 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}, Ronin::Support::Network::HTTP::Cookie, nil)

    Additional Cookie header.

  • :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 HTTP response object.

See Also:



429
430
431
432
433
434
435
436
437
# File 'lib/ronin/support/web/agent.rb', line 429

def http_copy(url,**kwargs,&block)
  uri = normalize_url(url)

  session_for(uri).copy(
    uri.request_uri, user:     uri.user,
                     password: uri.password,
                     **kwargs, &block
  )
end

#http_delete(url, **kwargs) {|response| ... } ⇒ Net::HTTPResponse

Performs a DELETE request for the given URI.

Parameters:

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

    The URL to create the HTTP request for.

  • kwargs (Hash)

    a customizable set of options

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 headers to use for 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}, Ronin::Support::Network::HTTP::Cookie, nil)

    Additional Cookie header.

  • :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 HTTP response object.

See Also:



460
461
462
463
464
465
466
467
468
# File 'lib/ronin/support/web/agent.rb', line 460

def http_delete(url,**kwargs,&block)
  uri = normalize_url(url)

  session_for(uri).delete(
    uri.request_uri, user:     uri.user,
                     password: uri.password,
                     **kwargs, &block
  )
end

#http_get(url, **kwargs) {|response| ... } ⇒ Net::HTTPResponse

Performs a GET request for the given URI.

Parameters:

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

    The URL to create the HTTP request for.

  • kwargs (Hash)

    a customizable set of options

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 headers to use for 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}, Ronin::Support::Network::HTTP::Cookie, nil)

    Additional Cookie header.

  • :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 HTTP response object.

See Also:



491
492
493
494
495
496
497
498
499
# File 'lib/ronin/support/web/agent.rb', line 491

def http_get(url,**kwargs,&block)
  uri = normalize_url(url)

  session_for(uri).get(
    uri.request_uri, user:     uri.user,
                     password: uri.password,
                     **kwargs, &block
  )
end

#http_get_body(url, **kwargs) ⇒ String

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

Parameters:

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

    The URL to create the HTTP request for.

  • kwargs (Hash)

    a customizable set of options

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 headers to use for 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}, Ronin::Support::Network::HTTP::Cookie, nil)

    Additional Cookie header.

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



569
570
571
572
573
574
575
576
577
# File 'lib/ronin/support/web/agent.rb', line 569

def http_get_body(url,**kwargs)
  uri = normalize_url(url)

  session_for(uri).get_body(
    uri.request_uri, user:     uri.user,
                     password: uri.password,
                     **kwargs
  )
end

#http_get_cookies(url, **kwargs) ⇒ Array<SetCookie>?

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

Parameters:

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

    The URL to create the HTTP request for.

  • kwargs (Hash)

    a customizable set of options

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 headers to use for 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}, Ronin::Support::Network::HTTP::Cookie, nil)

    Additional Cookie header.

  • :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<SetCookie>, nil)

    The parsed SetCookie header(s).

See Also:



543
544
545
546
547
548
549
550
551
# File 'lib/ronin/support/web/agent.rb', line 543

def http_get_cookies(url,**kwargs)
  uri = normalize_url(url)

  session_for(uri).get_cookies(
    uri.request_uri, user:     uri.user,
                     password: uri.password,
                     **kwargs
  )
end

#http_get_headers(url, **kwargs) ⇒ Hash{String => String}

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

Parameters:

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

    The URL to create the HTTP request for.

  • kwargs (Hash)

    a customizable set of options

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 headers to use for 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}, Ronin::Support::Network::HTTP::Cookie, nil)

    Additional Cookie header.

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

  • (Hash{String => String})

    The response headers.

See Also:



517
518
519
520
521
522
523
524
525
# File 'lib/ronin/support/web/agent.rb', line 517

def http_get_headers(url,**kwargs)
  uri = normalize_url(url)

  session_for(uri).get_headers(
    uri.request_uri, user:     uri.user,
                     password: uri.password,
                     **kwargs
  )
end

#http_head(url, **kwargs) {|response| ... } ⇒ Net::HTTPResponse

Performs a HEAD request for the given URI.

Parameters:

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

    The URL to create the HTTP request for.

  • kwargs (Hash)

    a customizable set of options

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 headers to use for 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}, Ronin::Support::Network::HTTP::Cookie, nil)

    Additional Cookie header.

  • :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 HTTP response object.

See Also:



600
601
602
603
604
605
606
607
608
# File 'lib/ronin/support/web/agent.rb', line 600

def http_head(url,**kwargs,&block)
  uri = normalize_url(url)

  session_for(uri).head(
    uri.request_uri, user:     uri.user,
                     password: uri.password,
                     **kwargs, &block
  )
end

#http_lock(url, **kwargs) {|response| ... } ⇒ Net::HTTPResponse

Performs a LOCK request for the given URI.

Parameters:

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

    The URL to create the HTTP request for.

  • kwargs (Hash)

    a customizable set of options

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 headers to use for 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}, Ronin::Support::Network::HTTP::Cookie, nil)

    Additional Cookie header.

  • :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 HTTP response object.

See Also:



631
632
633
634
635
636
637
638
639
# File 'lib/ronin/support/web/agent.rb', line 631

def http_lock(url,**kwargs,&block)
  uri = normalize_url(url)

  session_for(uri).lock(
    uri.request_uri, user:     uri.user,
                     password: uri.password,
                     **kwargs, &block
  )
end

#http_mkcol(url, **kwargs) {|response| ... } ⇒ Net::HTTPResponse

Performs a MKCOL request for the given URI.

Parameters:

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

    The URL to create the HTTP request for.

  • kwargs (Hash)

    a customizable set of options

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 headers to use for 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}, Ronin::Support::Network::HTTP::Cookie, nil)

    Additional Cookie header.

  • :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 HTTP response object.

See Also:



662
663
664
665
666
667
668
669
670
# File 'lib/ronin/support/web/agent.rb', line 662

def http_mkcol(url,**kwargs,&block)
  uri = normalize_url(url)

  session_for(uri).mkcol(
    uri.request_uri, user:     uri.user,
                     password: uri.password,
                     **kwargs, &block
  )
end

#http_move(url, **kwargs) {|response| ... } ⇒ Net::HTTPResponse

Performs a MOVE request for the given URI.

Parameters:

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

    The URL to create the HTTP request for.

  • kwargs (Hash)

    a customizable set of options

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 headers to use for 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}, Ronin::Support::Network::HTTP::Cookie, nil)

    Additional Cookie header.

  • :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 HTTP response object.

See Also:



693
694
695
696
697
698
699
700
701
# File 'lib/ronin/support/web/agent.rb', line 693

def http_move(url,**kwargs,&block)
  uri = normalize_url(url)

  session_for(uri).move(
    uri.request_uri, user:     uri.user,
                     password: uri.password,
                     **kwargs, &block
  )
end

#http_ok?(method = :head, url, **kwargs) ⇒ Boolean

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

Parameters:

  • method (Symbol, String) (defaults to: :head)

    The HTTP method to use for the request.

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

    The URL to create the HTTP request for.

  • kwargs (Hash)

    a customizable set of options

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 headers to use for 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}, Ronin::Support::Network::HTTP::Cookie, nil)

    Additional Cookie header.

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



290
291
292
293
294
295
296
297
298
# File 'lib/ronin/support/web/agent.rb', line 290

def http_ok?(method=:head,url,**kwargs)
  uri = normalize_url(url)

  session_for(uri).ok?(
    method, uri.request_uri, user:     uri.user,
                             password: uri.password,
                             **kwargs
  )
end

#http_options(url, **kwargs) {|response| ... } ⇒ Net::HTTPResponse

Performs a OPTIONS request for the given URI.

Parameters:

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

    The URL to create the HTTP request for.

  • kwargs (Hash)

    a customizable set of options

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 headers to use for 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}, Ronin::Support::Network::HTTP::Cookie, nil)

    Additional Cookie header.

  • :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 HTTP response object.

See Also:



724
725
726
727
728
729
730
731
732
# File 'lib/ronin/support/web/agent.rb', line 724

def http_options(url,**kwargs,&block)
  uri = normalize_url(url)

  session_for(uri).options(
    uri.request_uri, user:     uri.user,
                     password: uri.password,
                     **kwargs, &block
  )
end

#http_patch(url, **kwargs) {|response| ... } ⇒ Net::HTTPResponse

Performs a PATCH request for the given URI.

Parameters:

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

    The URL to create the HTTP request for.

  • kwargs (Hash)

    a customizable set of options

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 headers to use for 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}, Ronin::Support::Network::HTTP::Cookie, nil)

    Additional Cookie header.

  • :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 HTTP response object.

See Also:



781
782
783
784
785
786
787
788
789
# File 'lib/ronin/support/web/agent.rb', line 781

def http_patch(url,**kwargs,&block)
  uri = normalize_url(url)

  session_for(uri).patch(
    uri.request_uri, user:     uri.user,
                     password: uri.password,
                     **kwargs, &block
  )
end

#http_post(url, **kwargs) {|response| ... } ⇒ Net::HTTPResponse

Performs a POST request for the given URI.

Parameters:

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

    The URL to create the HTTP request for.

  • kwargs (Hash)

    a customizable set of options

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 headers to use for 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}, Ronin::Support::Network::HTTP::Cookie, nil)

    Additional Cookie header.

  • :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 HTTP response object.

See Also:



812
813
814
815
816
817
818
819
820
# File 'lib/ronin/support/web/agent.rb', line 812

def http_post(url,**kwargs,&block)
  uri = normalize_url(url)

  session_for(uri).post(
    uri.request_uri, user:     uri.user,
                     password: uri.password,
                     **kwargs, &block
  )
end

#http_post_body(url, **kwargs) ⇒ String

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

Parameters:

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

    The URL to create the HTTP request for.

  • kwargs (Hash)

    a customizable set of options

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 headers to use for 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}, Ronin::Support::Network::HTTP::Cookie, nil)

    Additional Cookie header.

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



864
865
866
867
868
869
870
871
872
# File 'lib/ronin/support/web/agent.rb', line 864

def http_post_body(url,**kwargs)
  uri = normalize_url(url)

  session_for(uri).post_body(
    uri.request_uri, user:     uri.user,
                     password: uri.password,
                     **kwargs
  )
end

#http_post_headers(url, **kwargs) ⇒ Hash{String => String}

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

Parameters:

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

    The URL to create the HTTP request for.

  • kwargs (Hash)

    a customizable set of options

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 headers to use for 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}, Ronin::Support::Network::HTTP::Cookie, nil)

    Additional Cookie header.

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

  • (Hash{String => String})

    The response headers.

See Also:



838
839
840
841
842
843
844
845
846
# File 'lib/ronin/support/web/agent.rb', line 838

def http_post_headers(url,**kwargs)
  uri = normalize_url(url)

  session_for(uri).post_headers(
    uri.request_uri, user:     uri.user,
                     password: uri.password,
                     **kwargs
  )
end

#http_powered_by_header(url, **kwargs) ⇒ String?

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

Parameters:

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

    The URL to create the HTTP request for.

  • kwargs (Hash)

    a customizable set of options

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 headers to use for 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}, Ronin::Support::Network::HTTP::Cookie, nil)

    Additional Cookie header.

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



369
370
371
372
373
374
375
376
377
378
# File 'lib/ronin/support/web/agent.rb', line 369

def http_powered_by_header(url,**kwargs)
  uri = normalize_url(url)

  session_for(uri).powered_by_header(
    user:     uri.user,
    password: uri.password,
    path:     uri.request_uri,
    **kwargs
  )
end

#http_propfind(url, **kwargs) {|response| ... } ⇒ Net::HTTPResponse Also known as: http_prop_find

Performs a PROPFIND request for the given URI.

Parameters:

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

    The URL to create the HTTP request for.

  • kwargs (Hash)

    a customizable set of options

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 headers to use for 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}, Ronin::Support::Network::HTTP::Cookie, nil)

    Additional Cookie header.

  • :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 HTTP response object.

See Also:



895
896
897
898
899
900
901
902
903
# File 'lib/ronin/support/web/agent.rb', line 895

def http_propfind(url,**kwargs,&block)
  uri = normalize_url(url)

  session_for(uri).propfind(
    uri.request_uri, user:     uri.user,
                     password: uri.password,
                     **kwargs, &block
  )
end

#http_proppatch(url, **kwargs) {|response| ... } ⇒ Net::HTTPResponse Also known as: http_prop_patch

Performs a PROPPATCH request for the given URI.

Parameters:

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

    The URL to create the HTTP request for.

  • kwargs (Hash)

    a customizable set of options

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 headers to use for 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}, Ronin::Support::Network::HTTP::Cookie, nil)

    Additional Cookie header.

  • :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 HTTP response object.

See Also:



928
929
930
931
932
933
934
935
936
# File 'lib/ronin/support/web/agent.rb', line 928

def http_proppatch(url,**kwargs,&block)
  uri = normalize_url(url)

  session_for(uri).proppatch(
    uri.request_uri, user:     uri.user,
                     password: uri.password,
                     **kwargs, &block
  )
end

#http_put(url, **kwargs) {|response| ... } ⇒ Net::HTTPResponse

Performs a PUT request for the given URI.

Parameters:

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

    The URL to create the HTTP request for.

  • kwargs (Hash)

    a customizable set of options

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 headers to use for 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}, Ronin::Support::Network::HTTP::Cookie, nil)

    Additional Cookie header.

  • :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 HTTP response object.

See Also:



961
962
963
964
965
966
967
968
969
# File 'lib/ronin/support/web/agent.rb', line 961

def http_put(url,**kwargs,&block)
  uri = normalize_url(url)

  session_for(uri).put(
    uri.request_uri, user:     uri.user,
                     password: uri.password,
                     **kwargs, &block
  )
end

#http_request(method, url, **kwargs) {|response| ... } ⇒ Net::HTTPResponse

Performs and arbitrary HTTP request.

Parameters:

  • method (Symbol, String)

    The HTTP method to use for the request.

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

    The URL to create the HTTP request for.

  • kwargs (Hash)

    a customizable set of options

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 headers to use for 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}, Ronin::Support::Network::HTTP::Cookie, nil)

    Additional Cookie header.

  • :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 HTTP response object.

Raises:

  • (ArgumentError)

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

See Also:



234
235
236
237
238
239
240
241
242
# File 'lib/ronin/support/web/agent.rb', line 234

def http_request(method,url,**kwargs,&block)
  uri = normalize_url(url)

  session_for(uri).request(
    method, uri.request_uri, user:     uri.user,
                             password: uri.password,
                             **kwargs, &block
  )
end

#http_response_body(method = :get, url, **kwargs) ⇒ String

Sends an arbitrary HTTP request and returns the response body.

Parameters:

  • method (Symbol, String) (defaults to: :get)

    The HTTP method to use for the request.

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

    The URL to create the HTTP request for.

  • kwargs (Hash)

    a customizable set of options

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 headers to use for 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}, Ronin::Support::Network::HTTP::Cookie, nil)

    Additional Cookie header.

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



398
399
400
401
402
403
404
405
406
# File 'lib/ronin/support/web/agent.rb', line 398

def http_response_body(method=:get,url,**kwargs)
  uri = normalize_url(url)

  session_for(uri).response_body(
    method, uri.request_uri, user:     uri.user,
                             password: uri.password,
                             **kwargs
  )
end

#http_response_headers(method = :head, url, **kwargs) ⇒ Hash{String => String}

Sends an arbitrary HTTP request and returns the response headers.

Parameters:

  • method (Symbol, String) (defaults to: :head)

    The HTTP method to use for the request.

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

    The URL to create the HTTP request for.

  • kwargs (Hash)

    a customizable set of options

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 headers to use for 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}, Ronin::Support::Network::HTTP::Cookie, nil)

    Additional Cookie header.

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

  • (Hash{String => String})

    The response headers.

See Also:



318
319
320
321
322
323
324
325
326
# File 'lib/ronin/support/web/agent.rb', line 318

def http_response_headers(method=:head,url,**kwargs)
  uri = normalize_url(url)

  session_for(uri).response_headers(
    method, uri.request_uri, user:     uri.user,
                             password: uri.password,
                             **kwargs
  )
end

#http_response_status(method = :head, url, **kwargs) ⇒ Integer

Sends an arbitrary HTTP request and returns the response status.

Parameters:

  • method (Symbol, String) (defaults to: :head)

    The HTTP method to use for the request.

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

    The URL to create the HTTP request for.

  • kwargs (Hash)

    a customizable set of options

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 headers to use for 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}, Ronin::Support::Network::HTTP::Cookie, nil)

    Additional Cookie header.

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



262
263
264
265
266
267
268
269
270
# File 'lib/ronin/support/web/agent.rb', line 262

def http_response_status(method=:head,url,**kwargs)
  uri = normalize_url(url)

  session_for(uri).response_status(
    method, uri.request_uri, user:     uri.user,
                             password: uri.password,
                             **kwargs
  )
end

#http_server_header(url, **kwargs) ⇒ String?

Sends an HTTP request and returns the Server header.

Parameters:

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

    The URL to create the HTTP request for.

  • kwargs (Hash)

    a customizable set of options

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 headers to use for 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}, Ronin::Support::Network::HTTP::Cookie, nil)

    Additional Cookie header.

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



343
344
345
346
347
348
349
350
351
352
# File 'lib/ronin/support/web/agent.rb', line 343

def http_server_header(url,**kwargs)
  uri = normalize_url(url)

  session_for(uri).server_header(
    user:     uri.user,
    password: uri.password,
    path:     uri.request_uri,
    **kwargs
  )
end

#http_trace(url, **kwargs) {|response| ... } ⇒ Net::HTTPResponse

Performs a TRACE request for the given URI.

Parameters:

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

    The URL to create the HTTP request for.

  • kwargs (Hash)

    a customizable set of options

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 headers to use for 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}, Ronin::Support::Network::HTTP::Cookie, nil)

    Additional Cookie header.

  • :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 HTTP response object.

See Also:



992
993
994
995
996
997
998
999
1000
# File 'lib/ronin/support/web/agent.rb', line 992

def http_trace(url,**kwargs,&block)
  uri = normalize_url(url)

  session_for(uri).trace(
    uri.request_uri, user:     uri.user,
                     password: uri.password,
                     **kwargs, &block
  )
end

#http_unlock(url, **kwargs) {|response| ... } ⇒ Net::HTTPResponse

Performs a UNLOCK request for the given URI.

Parameters:

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

    The URL to create the HTTP request for.

  • kwargs (Hash)

    a customizable set of options

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 headers to use for 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}, Ronin::Support::Network::HTTP::Cookie, nil)

    Additional Cookie header.

  • :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 HTTP response object.

See Also:



1023
1024
1025
1026
1027
1028
1029
1030
1031
# File 'lib/ronin/support/web/agent.rb', line 1023

def http_unlock(url,**kwargs,&block)
  uri = normalize_url(url)

  session_for(uri).unlock(
    uri.request_uri, user:     uri.user,
                     password: uri.password,
                     **kwargs, &block
  )
end

#post(url, follow_redirects: @follow_redirects, max_redirects: @max_redirects, **kwargs) {|response| ... } ⇒ Net::HTTPResponse

Note:

If the response is an HTTP redirect, then #get will be called to follow any redirects.

Performs an HTTP POST to the URL.

Examples:

response = agent.post('https://example.com/form', form_data: {'foo' => 'bar'})
# => #<Net::HTTPResponse:...>

Parameters:

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

    The URL to create the HTTP GET request for.

  • kwargs (Hash)

    a customizable set of options

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 headers to use for 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}, Ronin::Support::Network::HTTP::Cookie, nil)

    Additional Cookie header.

  • :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 HTTP response object.

Raises:



1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
# File 'lib/ronin/support/web/agent.rb', line 1211

def post(url, follow_redirects: @follow_redirects,
              max_redirects:    @max_redirects,
              **kwargs)
  response = http_post(url,**kwargs)

  if follow_redirects && response.kind_of?(Net::HTTPRedirection)
    location = response['Location']

    response = begin
                 get(location, follow_redirects: follow_redirects,
                               max_redirects:    max_redirects - 1)
               rescue TooManyRedirects
                 raise(TooManyRedirects,"maximum number of redirects reached: #{url.inspect}")
               end
  end

  yield response if block_given?
  return response
end

#post_html(url, **kwargs) ⇒ Nokogiri::HTML::Document

Note:

If the response is an HTTP redirect, then #get will be called to follow any redirects.

Performs an HTTP POST to the URL and parses the HTML response.

Examples:

Send a POST request and parses the HTML response:

doc = agent.post_html 'https://example.com/form', form_data: {foo: 'bar'})
# => #<Nokogiri::HTML::Document:...>

Parameters:

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

    The URL to create the HTTP POST request for.

  • kwargs (Hash)

    a customizable set of options

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 headers to use for 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}, Ronin::Support::Network::HTTP::Cookie, nil)

    Additional Cookie header.

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

  • (Nokogiri::HTML::Document)

    The parsed HTML response.

Raises:



1257
1258
1259
1260
1261
1262
1263
1264
1265
# File 'lib/ronin/support/web/agent.rb', line 1257

def post_html(url,**kwargs)
  response = post(url,**kwargs)

  unless response.content_type.include?('text/html')
    raise(ContentTypeError,"response 'Content-Type' was not 'text/html': #{response.content_type.inspect}")
  end

  return Nokogiri::HTML(response.body)
end

#post_json(url, **kwargs) ⇒ Hash{String => Object}, Array

Note:

If the response is an HTTP redirect, then #get will be called to follow any redirects.

Performs an HTTP POST to the URL and parses the JSON response.

Examples:

Send a POST request to the form and parse the JSON response:

json = agent.post_json 'https://example.com/form', form_data: {foo: 'bar'}
# => {...}

Send a POST request containing JSON and parse the JSON response:

json = agent.post_json 'https://example.com/api/end-point', json: {foo: 'bar'}
# => {...}

Parameters:

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

    The URL to create the HTTP POST request for.

  • kwargs (Hash)

    a customizable set of options

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 headers to use for 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}, Ronin::Support::Network::HTTP::Cookie, nil)

    Additional Cookie header.

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

  • (Hash{String => Object}, Array)

    The parses JSON response.

Raises:



1333
1334
1335
1336
1337
1338
1339
1340
1341
# File 'lib/ronin/support/web/agent.rb', line 1333

def post_json(url,**kwargs)
  response = post(url,**kwargs)

  unless response.content_type.include?('application/json')
    raise(ContentTypeError,"response 'Content-Type' was not 'application/json': #{response.content_type.inspect}")
  end

  return ::JSON.parse(response.body)
end

#post_xml(url, **kwargs) ⇒ Nokogiri::XML::Document

Note:

If the response is an HTTP redirect, then #get will be called to follow any redirects.

Performs an HTTP POST to the URL and parses the XML response.

Examples:

Send a POST request to the form and parses the XML response:

doc = agent.post_xml 'https://example.com/form', form_data: {foo: 'bar'}
# => #<Nokogiri::XML::Document:...>

Parameters:

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

    The URL to create the HTTP POST request for.

  • kwargs (Hash)

    a customizable set of options

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 headers to use for 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}, Ronin::Support::Network::HTTP::Cookie, nil)

    Additional Cookie header.

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

  • (Nokogiri::XML::Document)

    The parsed XML response.

Raises:



1293
1294
1295
1296
1297
1298
1299
1300
1301
# File 'lib/ronin/support/web/agent.rb', line 1293

def post_xml(url,**kwargs)
  response = post(url,**kwargs)

  unless response.content_type.include?('text/xml')
    raise(ContentTypeError,"response 'Content-Type' was not 'application/json': #{response.content_type.inspect}")
  end

  return Nokogiri::XML(response.body)
end