Class: Ronin::Support::Network::HTTP
- Inherits:
-
Object
- Object
- Ronin::Support::Network::HTTP
- Defined in:
- lib/ronin/support/network/http.rb,
lib/ronin/support/network/http/mixin.rb,
lib/ronin/support/network/http/cookie.rb,
lib/ronin/support/network/http/request.rb,
lib/ronin/support/network/http/set_cookie.rb,
lib/ronin/support/network/http/user_agents.rb
Overview
Provides helper methods for communicating with HTTP Servers.
Core-Ext Methods
Defined Under Namespace
Modules: Mixin, Request, UserAgents Classes: Cookie, SetCookie
Instance Attribute Summary collapse
-
#cookie ⇒ Cookie?
The default cookie params to add to every request.
-
#headers ⇒ Hash{String => String,Array}
readonly
Additional headers to add to every request.
-
#host ⇒ String
readonly
The host to connect to.
-
#password ⇒ String?
readonly
The HTTP Baic-Auth password to add to every request.
-
#port ⇒ Integer
readonly
The port to connect to.
-
#proxy ⇒ URI::HTTP, ...
readonly
The proxy to send requests through.
-
#user ⇒ String?
readonly
The HTTP Baic-Auth user to add to every request.
-
#user_agent ⇒ String?
The
User-Agent
header value.
Class Method Summary collapse
-
.allowed_methods(url, proxy: self.proxy, ssl: nil, headers: {}, user_agent: nil, cookie: nil, user: nil, password: nil, **kwargs) ⇒ Array<Symbol>
Performs a
OPTIONS
HTTP request for the given URI and parses theAllow
response header. -
.connect(host, port, ssl: port == 443, **kwargs) {|http| ... } ⇒ HTTP?
Creates a HTTP connection to the host nad port.
-
.connect_uri(url, ssl: nil, user: nil, password: nil, **kwargs) {|http| ... } ⇒ HTTP?
Creates a HTTP connection using the URI.
-
.copy(url, proxy: self.proxy, ssl: nil, headers: {}, user_agent: nil, cookie: nil, user: nil, password: nil, **kwargs) {|response| ... } ⇒ Net::HTTPResponse
Performs a
COPY
request for the given URI. -
.delete(url, proxy: self.proxy, ssl: nil, headers: {}, user_agent: nil, cookie: nil, user: nil, password: nil, **kwargs) {|response| ... } ⇒ Net::HTTPResponse
Performs a
DELETE
request for the given URI. -
.get(url, proxy: self.proxy, ssl: nil, headers: {}, user_agent: nil, cookie: nil, user: nil, password: nil, **kwargs) {|response| ... } ⇒ Net::HTTPResponse
Performs a
GET
request for the given URI. -
.get_body(url, proxy: self.proxy, ssl: nil, headers: {}, user_agent: nil, cookie: nil, user: nil, password: nil, **kwargs) ⇒ String
Performs a
GET
request for the given URI and returns the response body. -
.get_cookies(url, proxy: self.proxy, ssl: nil, headers: {}, user_agent: nil, cookie: nil, user: nil, password: nil, **kwargs) ⇒ Array<SetCookie>?
Sends an HTTP request and returns the parsed
Set-Cookie
header(s). -
.get_headers(url, proxy: self.proxy, ssl: nil, headers: {}, user_agent: nil, cookie: nil, user: nil, password: nil, **kwargs) ⇒ Hash{String => String}
Performs a
GET
request for the given URI and returns the response headers. -
.head(url, proxy: self.proxy, ssl: nil, headers: {}, user_agent: nil, cookie: nil, user: nil, password: nil, **kwargs) {|response| ... } ⇒ Net::HTTPResponse
Performs a
HEAD
request for the given URI. -
.lock(url, proxy: self.proxy, ssl: nil, headers: {}, user_agent: nil, cookie: nil, user: nil, password: nil, **kwargs) {|response| ... } ⇒ Net::HTTPResponse
Performs a
LOCK
request for the given URI. -
.mkcol(url, proxy: self.proxy, ssl: nil, headers: {}, user_agent: nil, cookie: nil, user: nil, password: nil, **kwargs) {|response| ... } ⇒ Net::HTTPResponse
Performs a
MKCOL
request for the given URI. -
.move(url, proxy: self.proxy, ssl: nil, headers: {}, user_agent: nil, cookie: nil, user: nil, password: nil, **kwargs) {|response| ... } ⇒ Net::HTTPResponse
Performs a
MOVE
request for the given URI. -
.ok?(method = :head, url, proxy: self.proxy, ssl: nil, headers: {}, user_agent: nil, cookie: nil, user: nil, password: nil, **kwargs) ⇒ Boolean
Sends a HTTP request and determines if the response status was 200.
-
.options(url, proxy: self.proxy, ssl: nil, headers: {}, user_agent: nil, cookie: nil, user: nil, password: nil, **kwargs) {|response| ... } ⇒ Net::HTTPResponse
Performs a
OPTIONS
request for the given URI. -
.patch(url, proxy: self.proxy, ssl: nil, headers: {}, user_agent: nil, cookie: nil, user: nil, password: nil, **kwargs) {|response| ... } ⇒ Net::HTTPResponse
Performs a
PATCH
request for the given URI. -
.post(url, proxy: self.proxy, ssl: nil, headers: {}, user_agent: nil, cookie: nil, user: nil, password: nil, **kwargs) {|response| ... } ⇒ Net::HTTPResponse
Performs a
POST
request for the given URI. -
.post_body(url, proxy: self.proxy, ssl: nil, headers: {}, user_agent: nil, cookie: nil, user: nil, password: nil, **kwargs) ⇒ String
Performs a
POST
request for the given URI and returns the response body. -
.post_cookies(url, proxy: self.proxy, ssl: nil, headers: {}, user_agent: nil, cookie: nil, user: nil, password: nil, **kwargs, &block) ⇒ Array<SetCookie>?
Sends an HTTP request and returns the parsed
Set-Cookie
header(s). -
.post_headers(url, proxy: self.proxy, ssl: nil, headers: {}, user_agent: nil, cookie: nil, user: nil, password: nil, **kwargs) ⇒ Hash{String => String}
Performs a
POST
request on the given URI and returns the response headers. -
.powered_by_header(url, proxy: self.proxy, ssl: nil, headers: {}, user_agent: nil, cookie: nil, user: nil, password: nil, **kwargs) ⇒ String?
Sends an HTTP request and returns the
X-Powered-By
header. -
.propfind(url, proxy: self.proxy, ssl: nil, headers: {}, user_agent: nil, cookie: nil, user: nil, password: nil, **kwargs) {|response| ... } ⇒ Net::HTTPResponse
Performs a
PROPFIND
request for the given URI. -
.proppatch(url, proxy: self.proxy, ssl: nil, headers: {}, user_agent: nil, cookie: nil, user: nil, password: nil, **kwargs) {|response| ... } ⇒ Net::HTTPResponse
Performs a
PROPPATCH
request for the given URI. -
.proxy ⇒ URI::HTTP, ...
The Ronin HTTP proxy to use.
-
.proxy=(new_proxy) ⇒ URI::HTTP, ...
Sets the Ronin HTTP proxy to use.
-
.put(url, proxy: self.proxy, ssl: nil, headers: {}, user_agent: nil, cookie: nil, user: nil, password: nil, **kwargs) {|response| ... } ⇒ Net::HTTPResponse
Performs a
PUT
request for the given URI. -
.request(method, url, proxy: self.proxy, ssl: nil, headers: {}, user_agent: nil, cookie: nil, user: nil, password: nil, **kwargs) {|response| ... } ⇒ Net::HTTPResponse
Performs and arbitrary HTTP request.
-
.response_body(method = :get, url, proxy: self.proxy, ssl: nil, headers: {}, user_agent: nil, cookie: nil, user: nil, password: nil, **kwargs) ⇒ String
Sends an arbitrary HTTP request and returns the response body.
-
.response_headers(method = :head, url, proxy: self.proxy, ssl: nil, headers: {}, user_agent: nil, cookie: nil, user: nil, password: nil, **kwargs) ⇒ Hash{String => String}
Sends an arbitrary HTTP request and returns the response headers.
-
.response_status(method = :head, url, proxy: self.proxy, ssl: nil, headers: {}, user_agent: nil, cookie: nil, user: nil, password: nil, **kwargs) ⇒ Integer
Sends an arbitrary HTTP request and returns the response status.
-
.server_header(url, proxy: self.proxy, ssl: nil, headers: {}, user_agent: nil, cookie: nil, user: nil, password: nil, **kwargs) ⇒ String?
Sends an HTTP request and returns the
Server
header. -
.trace(url, proxy: self.proxy, ssl: nil, headers: {}, user_agent: nil, cookie: nil, user: nil, password: nil, **kwargs) {|response| ... } ⇒ Net::HTTPResponse
Performs a
TRACE
request for the given URI. -
.unlock(url, proxy: self.proxy, ssl: nil, headers: {}, user_agent: nil, cookie: nil, user: nil, password: nil, **kwargs) {|response| ... } ⇒ Net::HTTPResponse
Performs a
UNLOCK
request for the given URI. -
.user_agent ⇒ String?
The default Ronin HTTP
User-Agent
string. -
.user_agent=(new_user_agent) ⇒ String?
Sets the default Ronin HTTP
User-Agent
string.
Instance Method Summary collapse
-
#allowed_methods(path = '*', **kwargs) ⇒ Array<Symbol>
Sends a
OPTIONS
HTTP request and parses theAllow
response header. -
#close ⇒ Object
Closes the HTTP connection.
-
#copy(path, **kwargs) {|response| ... } ⇒ Net::HTTPResponse
Sends a
COPY
HTTP request. -
#delete(path, **kwargs) {|response| ... } ⇒ Net::HTTPResponse
Sends a
DELETE
HTTP request. -
#get(path, **kwargs) {|response| ... } ⇒ Net::HTTPResponse
Sends a
GET
HTTP request. -
#get_body(path, **kwargs) ⇒ String
Sends a
GET
HTTP request and returns the response body. -
#get_cookies(path, **kwargs) ⇒ Array<SetCookie>
Sends an HTTP request and returns the parsed
Set-Cookie
header(s). -
#get_headers(path, **kwargs) ⇒ Hash{String => String}
Sends a
GET
HTTP request and returns the response headers. -
#head(path, **kwargs) {|response| ... } ⇒ Net::HTTPResponse
Sends a
HEAD
HTTP request. -
#initialize(host, port, proxy: nil, ssl: port == 443, headers: {}, user_agent: self.class.user_agent, cookie: nil, user: nil, password: nil) {|_self| ... } ⇒ HTTP
constructor
Initializes an HTTP connection.
-
#lock(path, **kwargs) {|response| ... } ⇒ Net::HTTPResponse
Sends a
LOCK
HTTP request. -
#mkcol(path, **kwargs) {|response| ... } ⇒ Net::HTTPResponse
Sends a
MKCOL
HTTP request. -
#move(path, **kwargs) {|response| ... } ⇒ Net::HTTPResponse
Sends a
MOVE
HTTP request. -
#ok?(method = :head, path, **kwargs) ⇒ Boolean
Sends a HTTP request and determines if the response status was 200.
-
#options(path, **kwargs) {|response| ... } ⇒ Net::HTTPResponse
Sends a
OPTIONS
HTTP request. -
#patch(path, **kwargs) {|response| ... } ⇒ Net::HTTPResponse
Sends a
PATCH
HTTP request. -
#post(path, **kwargs) {|response| ... } ⇒ Net::HTTPResponse
Sends a
POST
HTTP request. -
#post_body(path, **kwargs) ⇒ String
Sends a
POST
HTTP request and returns the response body. -
#post_cookies(path, **kwargs) ⇒ Array<SetCookie>?
Sends an HTTP request and returns the parsed
Set-Cookie
header(s). -
#post_headers(path, **kwargs) ⇒ Hash{String => String}
Sends a
POST
HTTP request and returns the response headers. -
#powered_by_header(method: :head, path: '/', **kwargs) ⇒ String?
Sends an HTTP request and returns the
X-Powered-By
header. -
#prop_find {|response| ... } ⇒ Net::HTTPResponse
Sends a
PROPFIND
HTTP request. -
#prop_patch {|response| ... } ⇒ Net::HTTPResponse
Sends a
PROPPATCH
HTTP request. -
#propfind(path, **kwargs) {|response| ... } ⇒ Net::HTTPResponse
Sends a
PROPFIND
HTTP request. -
#proppatch(path, **kwargs) {|response| ... } ⇒ Net::HTTPResponse
Sends a
PROPPATCH
HTTP request. -
#put(path, **kwargs) {|response| ... } ⇒ Net::HTTPResponse
Sends a
PUT
HTTP request. -
#request(method, path, query: nil, query_params: nil, headers: nil, content_type: nil, accept: nil, user_agent: @user_agent, cookie: @cookie, user: @user, password: @password, body: nil, form_data: nil, json: nil, **additional_headers) {|response| ... } ⇒ Net::HTTPResponse
Sends an arbitrary HTTP request.
-
#response_body(method = :get, path, **kwargs) ⇒ String
Sends an arbitrary HTTP request and returns the response body.
-
#response_headers(method = :head, path, **kwargs) ⇒ Hash{String => String}
Sends an arbitrary HTTP request and returns the response headers.
-
#response_status(method = :head, path, **kwargs) ⇒ Integer
Sends an arbitrary HTTP request and returns the response status.
-
#server_header(method: :head, path: '/', **kwargs) ⇒ String?
Sends an HTTP request and returns the
Server
header. -
#ssl? ⇒ Boolean
Determines if the HTTP connect is using SSL/TLS.
-
#trace(path, **kwargs) {|response| ... } ⇒ Net::HTTPResponse
Sends a
TRACE
HTTP request. -
#unlock(path, **kwargs) {|response| ... } ⇒ Net::HTTPResponse
Sends a
UNLOCK
HTTP request.
Constructor Details
#initialize(host, port, proxy: nil, ssl: port == 443, headers: {}, user_agent: self.class.user_agent, cookie: nil, user: nil, password: nil) {|_self| ... } ⇒ HTTP
Initializes an HTTP connection.
249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 |
# File 'lib/ronin/support/network/http.rb', line 249 def initialize(host,port, proxy: nil, ssl: port == 443, # header options headers: {}, user_agent: self.class.user_agent, cookie: nil, # Basic-Auth options user: nil, password: nil) @host = DNS::IDN.to_ascii(host) @port = port.to_i @headers = headers self.user_agent = user_agent if user_agent self. = if @user = user @password = password if proxy @proxy = URI(proxy) @http = Net::HTTP.new( @host, @port, @proxy.host, @proxy.port, @proxy.user, @proxy.password ) else @http = Net::HTTP.new(@host,@port) end case ssl when true then initialize_ssl when Hash then initialize_ssl(**ssl) end yield self if block_given? end |
Instance Attribute Details
#cookie ⇒ Cookie?
The default cookie params to add to every request.
167 168 169 |
# File 'lib/ronin/support/network/http.rb', line 167 def @cookie end |
#headers ⇒ Hash{String => String,Array} (readonly)
Additional headers to add to every request.
152 153 154 |
# File 'lib/ronin/support/network/http.rb', line 152 def headers @headers end |
#host ⇒ String (readonly)
The host to connect to.
142 143 144 |
# File 'lib/ronin/support/network/http.rb', line 142 def host @host end |
#password ⇒ String? (readonly)
The HTTP Baic-Auth password to add to every request.
162 163 164 |
# File 'lib/ronin/support/network/http.rb', line 162 def password @password end |
#port ⇒ Integer (readonly)
The port to connect to.
147 148 149 |
# File 'lib/ronin/support/network/http.rb', line 147 def port @port end |
#proxy ⇒ URI::HTTP, ... (readonly)
The proxy to send requests through.
137 138 139 |
# File 'lib/ronin/support/network/http.rb', line 137 def proxy @proxy end |
#user ⇒ String? (readonly)
The HTTP Baic-Auth user to add to every request.
157 158 159 |
# File 'lib/ronin/support/network/http.rb', line 157 def user @user end |
#user_agent ⇒ String?
The User-Agent
header value.
578 579 580 |
# File 'lib/ronin/support/network/http.rb', line 578 def user_agent @user_agent end |
Class Method Details
.allowed_methods(url, proxy: self.proxy, ssl: nil, headers: {}, user_agent: nil, cookie: nil, user: nil, password: nil, **kwargs) ⇒ Array<Symbol>
Performs a OPTIONS
HTTP request for the given URI and parses the
Allow
response header.
2416 2417 2418 2419 2420 2421 2422 2423 2424 2425 2426 2427 2428 2429 2430 2431 2432 2433 2434 2435 2436 2437 2438 2439 2440 2441 2442 2443 |
# File 'lib/ronin/support/network/http.rb', line 2416 def self.allowed_methods(url, proxy: self.proxy, ssl: nil, headers: {}, user_agent: nil, cookie: nil, user: nil, password: nil, **kwargs) uri = case url when Addressable::URI, URI::HTTP url when String Addressable::URI.parse(url) else raise(ArgumentError,"URL argument must be either a Addressable::URI, URI::HTTP, or a String: #{url.inspect}") end path = uri.request_uri http = connect_uri(url, proxy: proxy, ssl: ssl, headers: headers, user_agent: user_agent, cookie: , user: user, password: password) http.allowed_methods(path,**kwargs) end |
.connect(host, port, ssl: port == 443, **kwargs) {|http| ... } ⇒ HTTP?
Creates a HTTP connection to the host nad port.
486 487 488 489 490 491 492 493 494 495 496 497 498 |
# File 'lib/ronin/support/network/http.rb', line 486 def self.connect(host,port, ssl: port == 443, **kwargs) http = new(host,port, ssl: ssl, **kwargs) if block_given? begin yield http ensure http.close end else return http end end |
.connect_uri(url, ssl: nil, user: nil, password: nil, **kwargs) {|http| ... } ⇒ HTTP?
Creates a HTTP connection using the URI.
525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 |
# File 'lib/ronin/support/network/http.rb', line 525 def self.connect_uri(url, ssl: nil, user: nil, password: nil, **kwargs, &block) case url when URI::HTTP host = url.host port = url.port user ||= url.user password ||= url.password ssl ||= (url.scheme == 'https') when String uri = Addressable::URI.parse(url) host = uri.host port = uri.inferred_port user ||= uri.user password ||= uri.password ssl ||= (uri.scheme == 'https') when Addressable::URI host = url.host port = url.inferred_port user ||= url.user password ||= url.password ssl ||= (url.scheme == 'https') else raise(ArgumentError,"url must be a URI::HTTP, Addressable::URI, or a String: #{url.inspect}") end return connect(host,port, ssl: ssl, user: user, password: password, **kwargs, &block) end |
.copy(url, proxy: self.proxy, ssl: nil, headers: {}, user_agent: nil, cookie: nil, user: nil, password: nil, **kwargs) {|response| ... } ⇒ Net::HTTPResponse
Performs a COPY
request for the given URI.
1857 1858 1859 1860 1861 1862 1863 1864 1865 1866 1867 1868 1869 1870 1871 1872 1873 1874 1875 1876 1877 1878 1879 1880 1881 1882 1883 1884 1885 |
# File 'lib/ronin/support/network/http.rb', line 1857 def self.copy(url, proxy: self.proxy, ssl: nil, headers: {}, user_agent: nil, cookie: nil, user: nil, password: nil, **kwargs, &block) uri = case url when Addressable::URI, URI::HTTP url when String Addressable::URI.parse(url) else raise(ArgumentError,"URL argument must be either a Addressable::URI, URI::HTTP, or a String: #{url.inspect}") end path = uri.request_uri http = connect_uri(url, proxy: proxy, ssl: ssl, headers: headers, user_agent: user_agent, cookie: , user: user, password: password) http.copy(path,**kwargs,&block) end |
.delete(url, proxy: self.proxy, ssl: nil, headers: {}, user_agent: nil, cookie: nil, user: nil, password: nil, **kwargs) {|response| ... } ⇒ Net::HTTPResponse
Performs a DELETE
request for the given URI.
1910 1911 1912 1913 1914 1915 1916 1917 1918 1919 1920 1921 1922 1923 1924 1925 1926 1927 1928 1929 1930 1931 1932 1933 1934 1935 1936 1937 1938 |
# File 'lib/ronin/support/network/http.rb', line 1910 def self.delete(url, proxy: self.proxy, ssl: nil, headers: {}, user_agent: nil, cookie: nil, user: nil, password: nil, **kwargs, &block) uri = case url when Addressable::URI, URI::HTTP url when String Addressable::URI.parse(url) else raise(ArgumentError,"URL argument must be either a Addressable::URI, URI::HTTP, or a String: #{url.inspect}") end path = uri.request_uri http = connect_uri(url, proxy: proxy, ssl: ssl, headers: headers, user_agent: user_agent, cookie: , user: user, password: password) http.delete(path,**kwargs,&block) end |
.get(url, proxy: self.proxy, ssl: nil, headers: {}, user_agent: nil, cookie: nil, user: nil, password: nil, **kwargs) {|response| ... } ⇒ Net::HTTPResponse
Performs a GET
request for the given URI.
1963 1964 1965 1966 1967 1968 1969 1970 1971 1972 1973 1974 1975 1976 1977 1978 1979 1980 1981 1982 1983 1984 1985 1986 1987 1988 1989 1990 1991 |
# File 'lib/ronin/support/network/http.rb', line 1963 def self.get(url, proxy: self.proxy, ssl: nil, headers: {}, user_agent: nil, cookie: nil, user: nil, password: nil, **kwargs, &block) uri = case url when Addressable::URI, URI::HTTP url when String Addressable::URI.parse(url) else raise(ArgumentError,"URL argument must be either a Addressable::URI, URI::HTTP, or a String: #{url.inspect}") end path = uri.request_uri http = connect_uri(url, proxy: proxy, ssl: ssl, headers: headers, user_agent: user_agent, cookie: , user: user, password: password) http.get(path,**kwargs,&block) end |
.get_body(url, proxy: self.proxy, ssl: nil, headers: {}, user_agent: nil, cookie: nil, user: nil, password: nil, **kwargs) ⇒ String
Performs a GET
request for the given URI and returns the response
body.
2104 2105 2106 2107 2108 2109 2110 2111 2112 2113 2114 2115 2116 2117 2118 2119 2120 2121 2122 2123 2124 2125 2126 2127 2128 2129 2130 2131 |
# File 'lib/ronin/support/network/http.rb', line 2104 def self.get_body(url, proxy: self.proxy, ssl: nil, headers: {}, user_agent: nil, cookie: nil, user: nil, password: nil, **kwargs) uri = case url when Addressable::URI, URI::HTTP url when String Addressable::URI.parse(url) else raise(ArgumentError,"URL argument must be either a Addressable::URI, URI::HTTP, or a String: #{url.inspect}") end path = uri.request_uri http = connect_uri(url, proxy: proxy, ssl: ssl, headers: headers, user_agent: user_agent, cookie: , user: user, password: password) http.get_body(path,**kwargs) end |
.get_cookies(url, proxy: self.proxy, ssl: nil, headers: {}, user_agent: nil, cookie: nil, user: nil, password: nil, **kwargs) ⇒ Array<SetCookie>?
Sends an HTTP request and returns the parsed Set-Cookie
header(s).
2057 2058 2059 2060 2061 2062 2063 2064 2065 2066 2067 2068 2069 2070 2071 2072 2073 2074 2075 2076 2077 2078 2079 2080 2081 2082 2083 2084 |
# File 'lib/ronin/support/network/http.rb', line 2057 def self.(url, proxy: self.proxy, ssl: nil, headers: {}, user_agent: nil, cookie: nil, user: nil, password: nil, **kwargs) uri = case url when Addressable::URI, URI::HTTP url when String Addressable::URI.parse(url) else raise(ArgumentError,"URL argument must be either a Addressable::URI, URI::HTTP, or a String: #{url.inspect}") end path = uri.request_uri http = connect_uri(url, proxy: proxy, ssl: ssl, headers: headers, user_agent: user_agent, cookie: , user: user, password: password) http.(path, **kwargs) end |
.get_headers(url, proxy: self.proxy, ssl: nil, headers: {}, user_agent: nil, cookie: nil, user: nil, password: nil, **kwargs) ⇒ Hash{String => String}
Performs a GET
request for the given URI and returns the response
headers.
2011 2012 2013 2014 2015 2016 2017 2018 2019 2020 2021 2022 2023 2024 2025 2026 2027 2028 2029 2030 2031 2032 2033 2034 2035 2036 2037 2038 |
# File 'lib/ronin/support/network/http.rb', line 2011 def self.get_headers(url, proxy: self.proxy, ssl: nil, headers: {}, user_agent: nil, cookie: nil, user: nil, password: nil, **kwargs) uri = case url when Addressable::URI, URI::HTTP url when String Addressable::URI.parse(url) else raise(ArgumentError,"URL argument must be either a Addressable::URI, URI::HTTP, or a String: #{url.inspect}") end path = uri.request_uri http = connect_uri(url, proxy: proxy, ssl: ssl, headers: headers, user_agent: user_agent, cookie: , user: user, password: password) http.get_headers(path,**kwargs) end |
.head(url, proxy: self.proxy, ssl: nil, headers: {}, user_agent: nil, cookie: nil, user: nil, password: nil, **kwargs) {|response| ... } ⇒ Net::HTTPResponse
Performs a HEAD
request for the given URI.
2156 2157 2158 2159 2160 2161 2162 2163 2164 2165 2166 2167 2168 2169 2170 2171 2172 2173 2174 2175 2176 2177 2178 2179 2180 2181 2182 2183 2184 |
# File 'lib/ronin/support/network/http.rb', line 2156 def self.head(url, proxy: self.proxy, ssl: nil, headers: {}, user_agent: nil, cookie: nil, user: nil, password: nil, **kwargs, &block) uri = case url when Addressable::URI, URI::HTTP url when String Addressable::URI.parse(url) else raise(ArgumentError,"URL argument must be either a Addressable::URI, URI::HTTP, or a String: #{url.inspect}") end path = uri.request_uri http = connect_uri(url, proxy: proxy, ssl: ssl, headers: headers, user_agent: user_agent, cookie: , user: user, password: password) http.head(path,**kwargs,&block) end |
.lock(url, proxy: self.proxy, ssl: nil, headers: {}, user_agent: nil, cookie: nil, user: nil, password: nil, **kwargs) {|response| ... } ⇒ Net::HTTPResponse
Performs a LOCK
request for the given URI.
2209 2210 2211 2212 2213 2214 2215 2216 2217 2218 2219 2220 2221 2222 2223 2224 2225 2226 2227 2228 2229 2230 2231 2232 2233 2234 2235 2236 2237 |
# File 'lib/ronin/support/network/http.rb', line 2209 def self.lock(url, proxy: self.proxy, ssl: nil, headers: {}, user_agent: nil, cookie: nil, user: nil, password: nil, **kwargs, &block) uri = case url when Addressable::URI, URI::HTTP url when String Addressable::URI.parse(url) else raise(ArgumentError,"URL argument must be either a Addressable::URI, URI::HTTP, or a String: #{url.inspect}") end path = uri.request_uri http = connect_uri(url, proxy: proxy, ssl: ssl, headers: headers, user_agent: user_agent, cookie: , user: user, password: password) http.lock(path,**kwargs,&block) end |
.mkcol(url, proxy: self.proxy, ssl: nil, headers: {}, user_agent: nil, cookie: nil, user: nil, password: nil, **kwargs) {|response| ... } ⇒ Net::HTTPResponse
Performs a MKCOL
request for the given URI.
2262 2263 2264 2265 2266 2267 2268 2269 2270 2271 2272 2273 2274 2275 2276 2277 2278 2279 2280 2281 2282 2283 2284 2285 2286 2287 2288 2289 2290 |
# File 'lib/ronin/support/network/http.rb', line 2262 def self.mkcol(url, proxy: self.proxy, ssl: nil, headers: {}, user_agent: nil, cookie: nil, user: nil, password: nil, **kwargs, &block) uri = case url when Addressable::URI, URI::HTTP url when String Addressable::URI.parse(url) else raise(ArgumentError,"URL argument must be either a Addressable::URI, URI::HTTP, or a String: #{url.inspect}") end path = uri.request_uri http = connect_uri(url, proxy: proxy, ssl: ssl, headers: headers, user_agent: user_agent, cookie: , user: user, password: password) http.mkcol(path,**kwargs,&block) end |
.move(url, proxy: self.proxy, ssl: nil, headers: {}, user_agent: nil, cookie: nil, user: nil, password: nil, **kwargs) {|response| ... } ⇒ Net::HTTPResponse
Performs a MOVE
request for the given URI.
2315 2316 2317 2318 2319 2320 2321 2322 2323 2324 2325 2326 2327 2328 2329 2330 2331 2332 2333 2334 2335 2336 2337 2338 2339 2340 2341 2342 2343 |
# File 'lib/ronin/support/network/http.rb', line 2315 def self.move(url, proxy: self.proxy, ssl: nil, headers: {}, user_agent: nil, cookie: nil, user: nil, password: nil, **kwargs, &block) uri = case url when Addressable::URI, URI::HTTP url when String Addressable::URI.parse(url) else raise(ArgumentError,"URL argument must be either a Addressable::URI, URI::HTTP, or a String: #{url.inspect}") end path = uri.request_uri http = connect_uri(url, proxy: proxy, ssl: ssl, headers: headers, user_agent: user_agent, cookie: , user: user, password: password) http.move(path,**kwargs,&block) end |
.ok?(method = :head, url, proxy: self.proxy, ssl: nil, headers: {}, user_agent: nil, cookie: nil, user: nil, password: nil, **kwargs) ⇒ Boolean
Sends a HTTP request and determines if the response status was 200.
The HTTP method to use for the request.
1611 1612 1613 1614 1615 1616 1617 1618 1619 1620 1621 1622 1623 1624 1625 1626 1627 1628 1629 1630 1631 1632 1633 1634 1635 1636 1637 1638 |
# File 'lib/ronin/support/network/http.rb', line 1611 def self.ok?(method=:head,url, proxy: self.proxy, ssl: nil, headers: {}, user_agent: nil, cookie: nil, user: nil, password: nil, **kwargs) uri = case url when Addressable::URI, URI::HTTP url when String Addressable::URI.parse(url) else raise(ArgumentError,"URL argument must be either a Addressable::URI, URI::HTTP, or a String: #{url.inspect}") end path = uri.request_uri http = connect_uri(url, proxy: proxy, ssl: ssl, headers: headers, user_agent: user_agent, cookie: , user: user, password: password) http.ok?(method,path,**kwargs) end |
.options(url, proxy: self.proxy, ssl: nil, headers: {}, user_agent: nil, cookie: nil, user: nil, password: nil, **kwargs) {|response| ... } ⇒ Net::HTTPResponse
Performs a OPTIONS
request for the given URI.
2368 2369 2370 2371 2372 2373 2374 2375 2376 2377 2378 2379 2380 2381 2382 2383 2384 2385 2386 2387 2388 2389 2390 2391 2392 2393 2394 2395 2396 |
# File 'lib/ronin/support/network/http.rb', line 2368 def self.(url, proxy: self.proxy, ssl: nil, headers: {}, user_agent: nil, cookie: nil, user: nil, password: nil, **kwargs, &block) uri = case url when Addressable::URI, URI::HTTP url when String Addressable::URI.parse(url) else raise(ArgumentError,"URL argument must be either a Addressable::URI, URI::HTTP, or a String: #{url.inspect}") end path = uri.request_uri http = connect_uri(url, proxy: proxy, ssl: ssl, headers: headers, user_agent: user_agent, cookie: , user: user, password: password) http.(path,**kwargs,&block) end |
.patch(url, proxy: self.proxy, ssl: nil, headers: {}, user_agent: nil, cookie: nil, user: nil, password: nil, **kwargs) {|response| ... } ⇒ Net::HTTPResponse
Performs a PATCH
request for the given URI.
2468 2469 2470 2471 2472 2473 2474 2475 2476 2477 2478 2479 2480 2481 2482 2483 2484 2485 2486 2487 2488 2489 2490 2491 2492 2493 2494 2495 2496 |
# File 'lib/ronin/support/network/http.rb', line 2468 def self.patch(url, proxy: self.proxy, ssl: nil, headers: {}, user_agent: nil, cookie: nil, user: nil, password: nil, **kwargs, &block) uri = case url when Addressable::URI, URI::HTTP url when String Addressable::URI.parse(url) else raise(ArgumentError,"URL argument must be either a Addressable::URI, URI::HTTP, or a String: #{url.inspect}") end path = uri.request_uri http = connect_uri(url, proxy: proxy, ssl: ssl, headers: headers, user_agent: user_agent, cookie: , user: user, password: password) http.patch(path,**kwargs,&block) end |
.post(url, proxy: self.proxy, ssl: nil, headers: {}, user_agent: nil, cookie: nil, user: nil, password: nil, **kwargs) {|response| ... } ⇒ Net::HTTPResponse
Performs a POST
request for the given URI.
2521 2522 2523 2524 2525 2526 2527 2528 2529 2530 2531 2532 2533 2534 2535 2536 2537 2538 2539 2540 2541 2542 2543 2544 2545 2546 2547 2548 2549 |
# File 'lib/ronin/support/network/http.rb', line 2521 def self.post(url, proxy: self.proxy, ssl: nil, headers: {}, user_agent: nil, cookie: nil, user: nil, password: nil, **kwargs, &block) uri = case url when Addressable::URI, URI::HTTP url when String Addressable::URI.parse(url) else raise(ArgumentError,"URL argument must be either a Addressable::URI, URI::HTTP, or a String: #{url.inspect}") end path = uri.request_uri http = connect_uri(url, proxy: proxy, ssl: ssl, headers: headers, user_agent: user_agent, cookie: , user: user, password: password) http.post(path,**kwargs,&block) end |
.post_body(url, proxy: self.proxy, ssl: nil, headers: {}, user_agent: nil, cookie: nil, user: nil, password: nil, **kwargs) ⇒ String
Performs a POST
request for the given URI and returns the response
body.
2616 2617 2618 2619 2620 2621 2622 2623 2624 2625 2626 2627 2628 2629 2630 2631 2632 2633 2634 2635 2636 2637 2638 2639 2640 2641 2642 2643 |
# File 'lib/ronin/support/network/http.rb', line 2616 def self.post_body(url, proxy: self.proxy, ssl: nil, headers: {}, user_agent: nil, cookie: nil, user: nil, password: nil, **kwargs) uri = case url when Addressable::URI, URI::HTTP url when String Addressable::URI.parse(url) else raise(ArgumentError,"URL argument must be either a Addressable::URI, URI::HTTP, or a String: #{url.inspect}") end path = uri.request_uri http = connect_uri(url, proxy: proxy, ssl: ssl, headers: headers, user_agent: user_agent, cookie: , user: user, password: password) http.post_body(path,**kwargs) end |
.post_cookies(url, proxy: self.proxy, ssl: nil, headers: {}, user_agent: nil, cookie: nil, user: nil, password: nil, **kwargs, &block) ⇒ Array<SetCookie>?
Sends an HTTP request and returns the parsed Set-Cookie
header(s).
2927 2928 2929 2930 2931 2932 2933 2934 2935 2936 2937 2938 2939 2940 2941 2942 2943 2944 2945 2946 2947 2948 2949 2950 2951 2952 2953 2954 2955 |
# File 'lib/ronin/support/network/http.rb', line 2927 def self.(url, proxy: self.proxy, ssl: nil, headers: {}, user_agent: nil, cookie: nil, user: nil, password: nil, **kwargs, &block) uri = case url when Addressable::URI, URI::HTTP url when String Addressable::URI.parse(url) else raise(ArgumentError,"URL argument must be either a Addressable::URI, URI::HTTP, or a String: #{url.inspect}") end path = uri.request_uri http = connect_uri(url, proxy: proxy, ssl: ssl, headers: headers, user_agent: user_agent, cookie: , user: user, password: password) http.(path,**kwargs) end |
.post_headers(url, proxy: self.proxy, ssl: nil, headers: {}, user_agent: nil, cookie: nil, user: nil, password: nil, **kwargs) ⇒ Hash{String => String}
Performs a POST
request on the given URI and returns the response
headers.
2569 2570 2571 2572 2573 2574 2575 2576 2577 2578 2579 2580 2581 2582 2583 2584 2585 2586 2587 2588 2589 2590 2591 2592 2593 2594 2595 2596 |
# File 'lib/ronin/support/network/http.rb', line 2569 def self.post_headers(url, proxy: self.proxy, ssl: nil, headers: {}, user_agent: nil, cookie: nil, user: nil, password: nil, **kwargs) uri = case url when Addressable::URI, URI::HTTP url when String Addressable::URI.parse(url) else raise(ArgumentError,"URL argument must be either a Addressable::URI, URI::HTTP, or a String: #{url.inspect}") end path = uri.request_uri http = connect_uri(url, proxy: proxy, ssl: ssl, headers: headers, user_agent: user_agent, cookie: , user: user, password: password) http.post_headers(path,**kwargs) end |
.powered_by_header(url, proxy: self.proxy, ssl: nil, headers: {}, user_agent: nil, cookie: nil, user: nil, password: nil, **kwargs) ⇒ String?
Sends an HTTP request and returns the X-Powered-By
header.
1754 1755 1756 1757 1758 1759 1760 1761 1762 1763 1764 1765 1766 1767 1768 1769 1770 1771 1772 1773 1774 1775 1776 1777 1778 1779 1780 1781 |
# File 'lib/ronin/support/network/http.rb', line 1754 def self.powered_by_header(url, proxy: self.proxy, ssl: nil, headers: {}, user_agent: nil, cookie: nil, user: nil, password: nil, **kwargs) uri = case url when Addressable::URI, URI::HTTP url when String Addressable::URI.parse(url) else raise(ArgumentError,"URL argument must be either a Addressable::URI, URI::HTTP, or a String: #{url.inspect}") end path = uri.request_uri http = connect_uri(url, proxy: proxy, ssl: ssl, headers: headers, user_agent: user_agent, cookie: , user: user, password: password) http.powered_by_header(path: path, **kwargs) end |
.propfind(url, proxy: self.proxy, ssl: nil, headers: {}, user_agent: nil, cookie: nil, user: nil, password: nil, **kwargs) {|response| ... } ⇒ Net::HTTPResponse
Performs a PROPFIND
request for the given URI.
2668 2669 2670 2671 2672 2673 2674 2675 2676 2677 2678 2679 2680 2681 2682 2683 2684 2685 2686 2687 2688 2689 2690 2691 2692 2693 2694 2695 2696 |
# File 'lib/ronin/support/network/http.rb', line 2668 def self.propfind(url, proxy: self.proxy, ssl: nil, headers: {}, user_agent: nil, cookie: nil, user: nil, password: nil, **kwargs, &block) uri = case url when Addressable::URI, URI::HTTP url when String Addressable::URI.parse(url) else raise(ArgumentError,"URL argument must be either a Addressable::URI, URI::HTTP, or a String: #{url.inspect}") end path = uri.request_uri http = connect_uri(url, proxy: proxy, ssl: ssl, headers: headers, user_agent: user_agent, cookie: , user: user, password: password) http.propfind(path,**kwargs,&block) end |
.proppatch(url, proxy: self.proxy, ssl: nil, headers: {}, user_agent: nil, cookie: nil, user: nil, password: nil, **kwargs) {|response| ... } ⇒ Net::HTTPResponse
Performs a PROPPATCH
request for the given URI.
2721 2722 2723 2724 2725 2726 2727 2728 2729 2730 2731 2732 2733 2734 2735 2736 2737 2738 2739 2740 2741 2742 2743 2744 2745 2746 2747 2748 2749 |
# File 'lib/ronin/support/network/http.rb', line 2721 def self.proppatch(url, proxy: self.proxy, ssl: nil, headers: {}, user_agent: nil, cookie: nil, user: nil, password: nil, **kwargs, &block) uri = case url when Addressable::URI, URI::HTTP url when String Addressable::URI.parse(url) else raise(ArgumentError,"URL argument must be either a Addressable::URI, URI::HTTP, or a String: #{url.inspect}") end path = uri.request_uri http = connect_uri(url, proxy: proxy, ssl: ssl, headers: headers, user_agent: user_agent, cookie: , user: user, password: password) http.proppatch(path,**kwargs,&block) end |
.proxy ⇒ URI::HTTP, ...
If the RONIN_HTTP_PROXY
environment variable is specified, it
will be used as the default value.
If the HTTP_PROXY
environment variable is specified, it will
be used as the default value.
The Ronin HTTP proxy to use.
59 60 61 62 63 64 65 |
# File 'lib/ronin/support/network/http.rb', line 59 def self.proxy @proxy ||= if ENV['RONIN_HTTP_PROXY'] Addressable::URI.parse(ENV['RONIN_HTTP_PROXY']) elsif ENV['HTTP_PROXY'] Addressable::URI.parse(ENV['HTTP_PROXY']) end end |
.proxy=(new_proxy) ⇒ URI::HTTP, ...
Sets the Ronin HTTP proxy to use.
82 83 84 85 86 87 88 89 90 91 92 93 |
# File 'lib/ronin/support/network/http.rb', line 82 def self.proxy=(new_proxy) @proxy = case new_proxy when URI::HTTP, Addressable::URI new_proxy when String Addressable::URI.parse(new_proxy) when nil nil else raise(ArgumentError,"invalid proxy value (#{new_proxy.inspect}), must be either a URI::HTTP, Addressable::URI, String, or nil") end end |
.put(url, proxy: self.proxy, ssl: nil, headers: {}, user_agent: nil, cookie: nil, user: nil, password: nil, **kwargs) {|response| ... } ⇒ Net::HTTPResponse
Performs a PUT
request for the given URI.
2774 2775 2776 2777 2778 2779 2780 2781 2782 2783 2784 2785 2786 2787 2788 2789 2790 2791 2792 2793 2794 2795 2796 2797 2798 2799 2800 2801 2802 |
# File 'lib/ronin/support/network/http.rb', line 2774 def self.put(url, proxy: self.proxy, ssl: nil, headers: {}, user_agent: nil, cookie: nil, user: nil, password: nil, **kwargs, &block) uri = case url when Addressable::URI, URI::HTTP url when String Addressable::URI.parse(url) else raise(ArgumentError,"URL argument must be either a Addressable::URI, URI::HTTP, or a String: #{url.inspect}") end path = uri.request_uri http = connect_uri(url, proxy: proxy, ssl: ssl, headers: headers, user_agent: user_agent, cookie: , user: user, password: password) http.put(path,**kwargs,&block) end |
.request(method, url, proxy: self.proxy, ssl: nil, headers: {}, user_agent: nil, cookie: nil, user: nil, password: nil, **kwargs) {|response| ... } ⇒ Net::HTTPResponse
Performs and arbitrary HTTP request.
The HTTP method to use for the request.
1508 1509 1510 1511 1512 1513 1514 1515 1516 1517 1518 1519 1520 1521 1522 1523 1524 1525 1526 1527 1528 1529 1530 1531 1532 1533 1534 1535 1536 |
# File 'lib/ronin/support/network/http.rb', line 1508 def self.request(method,url, proxy: self.proxy, ssl: nil, headers: {}, user_agent: nil, cookie: nil, user: nil, password: nil, **kwargs, &block) uri = case url when Addressable::URI, URI::HTTP url when String Addressable::URI.parse(url) else raise(ArgumentError,"URL argument must be either a Addressable::URI, URI::HTTP, or a String: #{url.inspect}") end path = uri.request_uri http = connect_uri(uri, proxy: proxy, ssl: ssl, headers: headers, user_agent: user_agent, cookie: , user: user, password: password) http.request(method,path,**kwargs,&block) end |
.response_body(method = :get, url, proxy: self.proxy, ssl: nil, headers: {}, user_agent: nil, cookie: nil, user: nil, password: nil, **kwargs) ⇒ String
Sends an arbitrary HTTP request and returns the response body.
The HTTP method to use for the request.
1805 1806 1807 1808 1809 1810 1811 1812 1813 1814 1815 1816 1817 1818 1819 1820 1821 1822 1823 1824 1825 1826 1827 1828 1829 1830 1831 1832 |
# File 'lib/ronin/support/network/http.rb', line 1805 def self.response_body(method=:get,url, proxy: self.proxy, ssl: nil, headers: {}, user_agent: nil, cookie: nil, user: nil, password: nil, **kwargs) uri = case url when Addressable::URI, URI::HTTP url when String Addressable::URI.parse(url) else raise(ArgumentError,"URL argument must be either a Addressable::URI, URI::HTTP, or a String: #{url.inspect}") end path = uri.request_uri http = connect_uri(url, proxy: proxy, ssl: ssl, headers: headers, user_agent: user_agent, cookie: , user: user, password: password) http.response_body(method,path,**kwargs) end |
.response_headers(method = :head, url, proxy: self.proxy, ssl: nil, headers: {}, user_agent: nil, cookie: nil, user: nil, password: nil, **kwargs) ⇒ Hash{String => String}
Sends an arbitrary HTTP request and returns the response headers.
The HTTP method to use for the request.
1662 1663 1664 1665 1666 1667 1668 1669 1670 1671 1672 1673 1674 1675 1676 1677 1678 1679 1680 1681 1682 1683 1684 1685 1686 1687 1688 1689 |
# File 'lib/ronin/support/network/http.rb', line 1662 def self.response_headers(method=:head,url, proxy: self.proxy, ssl: nil, headers: {}, user_agent: nil, cookie: nil, user: nil, password: nil, **kwargs) uri = case url when Addressable::URI, URI::HTTP url when String Addressable::URI.parse(url) else raise(ArgumentError,"URL argument must be either a Addressable::URI, URI::HTTP, or a String: #{url.inspect}") end path = uri.request_uri http = connect_uri(url, proxy: proxy, ssl: ssl, headers: headers, user_agent: user_agent, cookie: , user: user, password: password) http.response_headers(method,path,**kwargs) end |
.response_status(method = :head, url, proxy: self.proxy, ssl: nil, headers: {}, user_agent: nil, cookie: nil, user: nil, password: nil, **kwargs) ⇒ Integer
Sends an arbitrary HTTP request and returns the response status.
The HTTP method to use for the request.
1560 1561 1562 1563 1564 1565 1566 1567 1568 1569 1570 1571 1572 1573 1574 1575 1576 1577 1578 1579 1580 1581 1582 1583 1584 1585 1586 1587 |
# File 'lib/ronin/support/network/http.rb', line 1560 def self.response_status(method=:head,url, proxy: self.proxy, ssl: nil, headers: {}, user_agent: nil, cookie: nil, user: nil, password: nil, **kwargs) uri = case url when Addressable::URI, URI::HTTP url when String Addressable::URI.parse(url) else raise(ArgumentError,"URL argument must be either a Addressable::URI, URI::HTTP, or a String: #{url.inspect}") end path = uri.request_uri http = connect_uri(url, proxy: proxy, ssl: ssl, headers: headers, user_agent: user_agent, cookie: , user: user, password: password) http.response_status(method,path,**kwargs) end |
.server_header(url, proxy: self.proxy, ssl: nil, headers: {}, user_agent: nil, cookie: nil, user: nil, password: nil, **kwargs) ⇒ String?
Sends an HTTP request and returns the Server
header.
1708 1709 1710 1711 1712 1713 1714 1715 1716 1717 1718 1719 1720 1721 1722 1723 1724 1725 1726 1727 1728 1729 1730 1731 1732 1733 1734 1735 |
# File 'lib/ronin/support/network/http.rb', line 1708 def self.server_header(url, proxy: self.proxy, ssl: nil, headers: {}, user_agent: nil, cookie: nil, user: nil, password: nil, **kwargs) uri = case url when Addressable::URI, URI::HTTP url when String Addressable::URI.parse(url) else raise(ArgumentError,"URL argument must be either a Addressable::URI, URI::HTTP, or a String: #{url.inspect}") end path = uri.request_uri http = connect_uri(url, proxy: proxy, ssl: ssl, headers: headers, user_agent: user_agent, cookie: , user: user, password: password) http.server_header(path: path, **kwargs) end |
.trace(url, proxy: self.proxy, ssl: nil, headers: {}, user_agent: nil, cookie: nil, user: nil, password: nil, **kwargs) {|response| ... } ⇒ Net::HTTPResponse
Performs a TRACE
request for the given URI.
2827 2828 2829 2830 2831 2832 2833 2834 2835 2836 2837 2838 2839 2840 2841 2842 2843 2844 2845 2846 2847 2848 2849 2850 2851 2852 2853 2854 2855 |
# File 'lib/ronin/support/network/http.rb', line 2827 def self.trace(url, proxy: self.proxy, ssl: nil, headers: {}, user_agent: nil, cookie: nil, user: nil, password: nil, **kwargs, &block) uri = case url when Addressable::URI, URI::HTTP url when String Addressable::URI.parse(url) else raise(ArgumentError,"URL argument must be either a Addressable::URI, URI::HTTP, or a String: #{url.inspect}") end path = uri.request_uri http = connect_uri(url, proxy: proxy, ssl: ssl, headers: headers, user_agent: user_agent, cookie: , user: user, password: password) http.trace(path,**kwargs,&block) end |
.unlock(url, proxy: self.proxy, ssl: nil, headers: {}, user_agent: nil, cookie: nil, user: nil, password: nil, **kwargs) {|response| ... } ⇒ Net::HTTPResponse
Performs a UNLOCK
request for the given URI.
2880 2881 2882 2883 2884 2885 2886 2887 2888 2889 2890 2891 2892 2893 2894 2895 2896 2897 2898 2899 2900 2901 2902 2903 2904 2905 2906 2907 2908 |
# File 'lib/ronin/support/network/http.rb', line 2880 def self.unlock(url, proxy: self.proxy, ssl: nil, headers: {}, user_agent: nil, cookie: nil, user: nil, password: nil, **kwargs, &block) uri = case url when Addressable::URI, URI::HTTP url when String Addressable::URI.parse(url) else raise(ArgumentError,"URL argument must be either a Addressable::URI, URI::HTTP, or a String: #{url.inspect}") end path = uri.request_uri http = connect_uri(url, proxy: proxy, ssl: ssl, headers: headers, user_agent: user_agent, cookie: , user: user, password: password) http.unlock(path,**kwargs,&block) end |
.user_agent ⇒ String?
The default Ronin HTTP User-Agent
string.
103 104 105 |
# File 'lib/ronin/support/network/http.rb', line 103 def self.user_agent @user_agent end |
.user_agent=(new_user_agent) ⇒ String?
Sets the default Ronin HTTP User-Agent
string.
The new User-Agent
default value.
- If a
Symbol
or aString
is given, then the user_agent value will be set. - If
nil
is given, then the user_agent value will be cleared.
127 128 129 130 131 132 |
# File 'lib/ronin/support/network/http.rb', line 127 def self.user_agent=(new_user_agent) @user_agent = case new_user_agent when Symbol then UserAgents[new_user_agent] else new_user_agent end end |
Instance Method Details
#allowed_methods(path = '*', **kwargs) ⇒ Array<Symbol>
Sends a OPTIONS
HTTP request and parses the Allow
response
header.
1257 1258 1259 1260 1261 1262 1263 1264 1265 1266 1267 1268 |
# File 'lib/ronin/support/network/http.rb', line 1257 def allowed_methods(path='*',**kwargs) response = (path,**kwargs) allow = response['Allow'] methods = allow.split(', ') methods.map! do |method| method.downcase! method.to_sym end return methods end |
#close ⇒ Object
Closes the HTTP connection.
1474 1475 1476 |
# File 'lib/ronin/support/network/http.rb', line 1474 def close @http.finish if @http.started? end |
#copy(path, **kwargs) {|response| ... } ⇒ Net::HTTPResponse
Sends a COPY
HTTP request.
996 997 998 |
# File 'lib/ronin/support/network/http.rb', line 996 def copy(path,**kwargs,&block) request(:copy,path,**kwargs,&block) end |
#delete(path, **kwargs) {|response| ... } ⇒ Net::HTTPResponse
Sends a DELETE
HTTP request.
1019 1020 1021 |
# File 'lib/ronin/support/network/http.rb', line 1019 def delete(path,**kwargs,&block) request(:delete,path,**kwargs,&block) end |
#get(path, **kwargs) {|response| ... } ⇒ Net::HTTPResponse
Sends a GET
HTTP request.
1042 1043 1044 |
# File 'lib/ronin/support/network/http.rb', line 1042 def get(path,**kwargs,&block) request(:get,path,**kwargs,&block) end |
#get_body(path, **kwargs) ⇒ String
Sends a GET
HTTP request and returns the response body.
1124 1125 1126 |
# File 'lib/ronin/support/network/http.rb', line 1124 def get_body(path,**kwargs) response_body(:get,path,**kwargs) end |
#get_cookies(path, **kwargs) ⇒ Array<SetCookie>
Sends an HTTP request and returns the parsed Set-Cookie
header(s).
1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 |
# File 'lib/ronin/support/network/http.rb', line 1076 def (path, **kwargs) response = request(:get,path,**kwargs) if ( = response.get_fields('Set-Cookie')) .map do || SetCookie.parse() end else [] end end |
#get_headers(path, **kwargs) ⇒ Hash{String => String}
Sends a GET
HTTP request and returns the response headers.
1059 1060 1061 |
# File 'lib/ronin/support/network/http.rb', line 1059 def get_headers(path,**kwargs) response_headers(:get,path,**kwargs) end |
#head(path, **kwargs) {|response| ... } ⇒ Net::HTTPResponse
Sends a HEAD
HTTP request.
1147 1148 1149 |
# File 'lib/ronin/support/network/http.rb', line 1147 def head(path,**kwargs,&block) request(:head,path,**kwargs,&block) end |
#lock(path, **kwargs) {|response| ... } ⇒ Net::HTTPResponse
Sends a LOCK
HTTP request.
1170 1171 1172 |
# File 'lib/ronin/support/network/http.rb', line 1170 def lock(path,**kwargs,&block) request(:lock,path,**kwargs,&block) end |
#mkcol(path, **kwargs) {|response| ... } ⇒ Net::HTTPResponse
Sends a MKCOL
HTTP request.
1193 1194 1195 |
# File 'lib/ronin/support/network/http.rb', line 1193 def mkcol(path,**kwargs,&block) request(:mkcol,path,**kwargs,&block) end |
#move(path, **kwargs) {|response| ... } ⇒ Net::HTTPResponse
Sends a MOVE
HTTP request.
1216 1217 1218 |
# File 'lib/ronin/support/network/http.rb', line 1216 def move(path,**kwargs,&block) request(:move,path,**kwargs,&block) end |
#ok?(method = :head, path, **kwargs) ⇒ Boolean
Sends a HTTP request and determines if the response status was 200.
The HTTP method to use for the request.
877 878 879 |
# File 'lib/ronin/support/network/http.rb', line 877 def ok?(method=:head,path,**kwargs) response_status(method,path,**kwargs) == 200 end |
#options(path, **kwargs) {|response| ... } ⇒ Net::HTTPResponse
Sends a OPTIONS
HTTP request.
1239 1240 1241 |
# File 'lib/ronin/support/network/http.rb', line 1239 def (path,**kwargs,&block) request(:options,path,**kwargs,&block) end |
#patch(path, **kwargs) {|response| ... } ⇒ Net::HTTPResponse
Sends a PATCH
HTTP request.
1289 1290 1291 |
# File 'lib/ronin/support/network/http.rb', line 1289 def patch(path,**kwargs,&block) request(:patch,path,**kwargs,&block) end |
#post(path, **kwargs) {|response| ... } ⇒ Net::HTTPResponse
Sends a POST
HTTP request.
1312 1313 1314 |
# File 'lib/ronin/support/network/http.rb', line 1312 def post(path,**kwargs,&block) request(:post,path,**kwargs,&block) end |
#post_body(path, **kwargs) ⇒ String
Sends a POST
HTTP request and returns the response body.
1346 1347 1348 |
# File 'lib/ronin/support/network/http.rb', line 1346 def post_body(path,**kwargs) response_body(:post,path,**kwargs) end |
#post_cookies(path, **kwargs) ⇒ Array<SetCookie>?
Sends an HTTP request and returns the parsed Set-Cookie
header(s).
1101 1102 1103 1104 1105 1106 1107 1108 1109 |
# File 'lib/ronin/support/network/http.rb', line 1101 def (path, **kwargs) response = request(:post,path,**kwargs) if ( = response.get_fields('Set-Cookie')) .map do || SetCookie.parse() end end end |
#post_headers(path, **kwargs) ⇒ Hash{String => String}
Sends a POST
HTTP request and returns the response headers.
1329 1330 1331 |
# File 'lib/ronin/support/network/http.rb', line 1329 def post_headers(path,**kwargs) response_headers(:post,path,**kwargs) end |
#powered_by_header(method: :head, path: '/', **kwargs) ⇒ String?
Sends an HTTP request and returns the X-Powered-By
header.
The HTTP method to use for the request.
950 951 952 953 |
# File 'lib/ronin/support/network/http.rb', line 950 def powered_by_header(method: :head, path: '/',**kwargs) response = request(method,path,**kwargs) response['X-Powered-By'] end |
#prop_find {|response| ... } ⇒ Net::HTTPResponse
Sends a PROPFIND
HTTP request.
1373 1374 1375 |
# File 'lib/ronin/support/network/http.rb', line 1373 def propfind(path,**kwargs,&block) request(:propfind,path,**kwargs,&block) end |
#prop_patch {|response| ... } ⇒ Net::HTTPResponse
Sends a PROPPATCH
HTTP request.
1398 1399 1400 |
# File 'lib/ronin/support/network/http.rb', line 1398 def proppatch(path,**kwargs,&block) request(:proppatch,path,**kwargs,&block) end |
#propfind(path, **kwargs) {|response| ... } ⇒ Net::HTTPResponse
Sends a PROPFIND
HTTP request.
1369 1370 1371 |
# File 'lib/ronin/support/network/http.rb', line 1369 def propfind(path,**kwargs,&block) request(:propfind,path,**kwargs,&block) end |
#proppatch(path, **kwargs) {|response| ... } ⇒ Net::HTTPResponse
Sends a PROPPATCH
HTTP request.
1394 1395 1396 |
# File 'lib/ronin/support/network/http.rb', line 1394 def proppatch(path,**kwargs,&block) request(:proppatch,path,**kwargs,&block) end |
#put(path, **kwargs) {|response| ... } ⇒ Net::HTTPResponse
Sends a PUT
HTTP request.
1419 1420 1421 |
# File 'lib/ronin/support/network/http.rb', line 1419 def put(path,**kwargs,&block) request(:put,path,**kwargs,&block) end |
#request(method, path, query: nil, query_params: nil, headers: nil, content_type: nil, accept: nil, user_agent: @user_agent, cookie: @cookie, user: @user, password: @password, body: nil, form_data: nil, json: nil, **additional_headers) {|response| ... } ⇒ Net::HTTPResponse
Sends an arbitrary HTTP request.
The HTTP method to use for the request.
735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 |
# File 'lib/ronin/support/network/http.rb', line 735 def request(method,path, # query string keyword arguments query: nil, query_params: nil, # header keyword arguments headers: nil, content_type: nil, accept: nil, user_agent: @user_agent, cookie: @cookie, # Basic-Auth keyword arguments user: @user, password: @password, # request body keyword arguments body: nil, form_data: nil, json: nil, **additional_headers, &block) request = Request.build(method,path, headers: @headers, content_type: content_type, accept: accept, user_agent: user_agent, cookie: , user: user, password: password, query: query, query_params: query_params, body: body, form_data: form_data, json: json) if headers # populate any arbitrary headers headers.each do |name,value| request[name] = value end end unless additional_headers.empty? # set additional keyword argument headers (ex: `referer: '...'` additional_headers.each do |name,value| request[name] = value end end return @http.request(request,&block) end |
#response_body(method = :get, path, **kwargs) ⇒ String
Sends an arbitrary HTTP request and returns the response body.
The HTTP method to use for the request.
973 974 975 |
# File 'lib/ronin/support/network/http.rb', line 973 def response_body(method=:get,path,**kwargs) request(method,path,**kwargs).body end |
#response_headers(method = :head, path, **kwargs) ⇒ Hash{String => String}
Sends an arbitrary HTTP request and returns the response headers.
The HTTP method to use for the request.
899 900 901 902 903 904 905 906 907 |
# File 'lib/ronin/support/network/http.rb', line 899 def response_headers(method=:head,path,**kwargs) headers = {} request(method,path,**kwargs).each_capitalized do |name,value| headers[name] = value end return headers end |
#response_status(method = :head, path, **kwargs) ⇒ Integer
Sends an arbitrary HTTP request and returns the response status.
The HTTP method to use for the request.
854 855 856 857 |
# File 'lib/ronin/support/network/http.rb', line 854 def response_status(method=:head,path,**kwargs) response = request(method,path,**kwargs) response.code.to_i end |
#server_header(method: :head, path: '/', **kwargs) ⇒ String?
Sends an HTTP request and returns the Server
header.
The HTTP method to use for the request.
927 928 929 930 |
# File 'lib/ronin/support/network/http.rb', line 927 def server_header(method: :head, path: '/',**kwargs) response = request(method,path,**kwargs) response['Server'] end |
#ssl? ⇒ Boolean
Determines if the HTTP connect is using SSL/TLS.
567 568 569 |
# File 'lib/ronin/support/network/http.rb', line 567 def ssl? @http.use_ssl? end |
#trace(path, **kwargs) {|response| ... } ⇒ Net::HTTPResponse
Sends a TRACE
HTTP request.
1442 1443 1444 |
# File 'lib/ronin/support/network/http.rb', line 1442 def trace(path,**kwargs,&block) request(:trace,path,**kwargs,&block) end |
#unlock(path, **kwargs) {|response| ... } ⇒ Net::HTTPResponse
Sends a UNLOCK
HTTP request.
1465 1466 1467 |
# File 'lib/ronin/support/network/http.rb', line 1465 def unlock(path,**kwargs,&block) request(:unlock,path,**kwargs,&block) end |