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:

  • follow_redirects (Boolean) (defaults to: true)

    Specifies whether HTTP redirects will automatically be followed.

  • max_redirects (Integer) (defaults to: 20)

    The maximum number of redirects to follow. Defaults to 20.

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



134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
# File 'lib/ronin/support/web/agent.rb', line 134

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)


156
157
158
# File 'lib/ronin/support/web/agent.rb', line 156

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.

  • follow_redirects (Boolean) (defaults to: @follow_redirects)

    Overrides whether HTTP redirects will automatically be followed.

  • max_redirects (Integer) (defaults to: @max_redirects)

    Overrides the maximum number of redirects to follow.

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



1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
# File 'lib/ronin/support/web/agent.rb', line 1071

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

  • :follow_redirects (Boolean)

    Overrides whether HTTP redirects will automatically be followed.

  • :max_redirects (Integer)

    Overrides the maximum number of redirects to follow.

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



1124
1125
1126
1127
1128
1129
1130
1131
1132
# File 'lib/ronin/support/web/agent.rb', line 1124

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

  • :follow_redirects (Boolean)

    Overrides whether HTTP redirects will automatically be followed.

  • :max_redirects (Integer)

    Overrides the maximum number of redirects to follow.

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



1203
1204
1205
1206
1207
1208
1209
1210
1211
# File 'lib/ronin/support/web/agent.rb', line 1203

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

  • :follow_redirects (Boolean)

    Overrides whether HTTP redirects will automatically be followed.

  • :max_redirects (Integer)

    Overrides the maximum number of redirects to follow.

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



1163
1164
1165
1166
1167
1168
1169
1170
1171
# File 'lib/ronin/support/web/agent.rb', line 1163

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:



756
757
758
759
760
761
762
763
764
# File 'lib/ronin/support/web/agent.rb', line 756

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:



435
436
437
438
439
440
441
442
443
# File 'lib/ronin/support/web/agent.rb', line 435

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:



466
467
468
469
470
471
472
473
474
# File 'lib/ronin/support/web/agent.rb', line 466

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:



497
498
499
500
501
502
503
504
505
# File 'lib/ronin/support/web/agent.rb', line 497

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:



575
576
577
578
579
580
581
582
583
# File 'lib/ronin/support/web/agent.rb', line 575

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:



549
550
551
552
553
554
555
556
557
# File 'lib/ronin/support/web/agent.rb', line 549

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:



523
524
525
526
527
528
529
530
531
# File 'lib/ronin/support/web/agent.rb', line 523

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:



606
607
608
609
610
611
612
613
614
# File 'lib/ronin/support/web/agent.rb', line 606

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:



637
638
639
640
641
642
643
644
645
# File 'lib/ronin/support/web/agent.rb', line 637

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:



668
669
670
671
672
673
674
675
676
# File 'lib/ronin/support/web/agent.rb', line 668

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:



699
700
701
702
703
704
705
706
707
# File 'lib/ronin/support/web/agent.rb', line 699

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:



296
297
298
299
300
301
302
303
304
# File 'lib/ronin/support/web/agent.rb', line 296

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:



730
731
732
733
734
735
736
737
738
# File 'lib/ronin/support/web/agent.rb', line 730

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:



787
788
789
790
791
792
793
794
795
# File 'lib/ronin/support/web/agent.rb', line 787

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:



818
819
820
821
822
823
824
825
826
# File 'lib/ronin/support/web/agent.rb', line 818

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:



870
871
872
873
874
875
876
877
878
# File 'lib/ronin/support/web/agent.rb', line 870

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:



844
845
846
847
848
849
850
851
852
# File 'lib/ronin/support/web/agent.rb', line 844

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:



375
376
377
378
379
380
381
382
383
384
# File 'lib/ronin/support/web/agent.rb', line 375

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:



901
902
903
904
905
906
907
908
909
# File 'lib/ronin/support/web/agent.rb', line 901

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:



934
935
936
937
938
939
940
941
942
# File 'lib/ronin/support/web/agent.rb', line 934

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:



967
968
969
970
971
972
973
974
975
# File 'lib/ronin/support/web/agent.rb', line 967

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:



240
241
242
243
244
245
246
247
248
# File 'lib/ronin/support/web/agent.rb', line 240

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:



404
405
406
407
408
409
410
411
412
# File 'lib/ronin/support/web/agent.rb', line 404

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:



324
325
326
327
328
329
330
331
332
# File 'lib/ronin/support/web/agent.rb', line 324

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:



268
269
270
271
272
273
274
275
276
# File 'lib/ronin/support/web/agent.rb', line 268

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:



349
350
351
352
353
354
355
356
357
358
# File 'lib/ronin/support/web/agent.rb', line 349

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:



998
999
1000
1001
1002
1003
1004
1005
1006
# File 'lib/ronin/support/web/agent.rb', line 998

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:



1029
1030
1031
1032
1033
1034
1035
1036
1037
# File 'lib/ronin/support/web/agent.rb', line 1029

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.

  • follow_redirects (Boolean) (defaults to: @follow_redirects)

    Overrides whether HTTP redirects will automatically be followed.

  • max_redirects (Integer) (defaults to: @max_redirects)

    Overrides the maximum number of redirects to follow.

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



1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
# File 'lib/ronin/support/web/agent.rb', line 1247

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

  • :follow_redirects (Boolean)

    Overrides whether HTTP redirects will automatically be followed.

  • :max_redirects (Integer)

    Overrides the maximum number of redirects to follow.

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



1299
1300
1301
1302
1303
1304
1305
1306
1307
# File 'lib/ronin/support/web/agent.rb', line 1299

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

  • :follow_redirects (Boolean)

    Overrides whether HTTP redirects will automatically be followed.

  • :max_redirects (Integer)

    Overrides the maximum number of redirects to follow.

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



1387
1388
1389
1390
1391
1392
1393
1394
1395
# File 'lib/ronin/support/web/agent.rb', line 1387

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

  • :follow_redirects (Boolean)

    Overrides whether HTTP redirects will automatically be followed.

  • :max_redirects (Integer)

    Overrides the maximum number of redirects to follow.

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



1341
1342
1343
1344
1345
1346
1347
1348
1349
# File 'lib/ronin/support/web/agent.rb', line 1341

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