Module: Ronin::Network::HTTP
- Defined in:
- lib/ronin/network/http/http.rb,
lib/ronin/network/http/proxy.rb,
lib/ronin/network/http/exceptions/unknown_request.rb
Overview
Settings and helper methods for HTTP.
Defined Under Namespace
Classes: Proxy, UnknownRequest
Class Method Summary collapse
-
.expand_options(options = {}) ⇒ Hash
private
Expands the given HTTP options.
-
.expand_url(url) ⇒ Hash{Symbol => Object}
private
Expands the URL into options.
-
.header_name(name) ⇒ String
private
Converts an underscored, dashed, lowercase or uppercase HTTP header name to the standard camel-case HTTP header name.
-
.headers(options = {}) ⇒ Hash
private
Converts underscored, dashed, lowercase and uppercase HTTP headers to standard camel-cased HTTP headers.
-
.proxy ⇒ Proxy
The Ronin HTTP proxy to use.
-
.proxy=(new_proxy) ⇒ Proxy
Sets the Ronin HTTP proxy to use.
-
.request(options = {}) ⇒ HTTP::Request
private
Creates a specific type of HTTP request object.
-
.user_agent ⇒ String?
The default Ronin HTTP User-Agent string.
-
.user_agent=(agent) ⇒ Object
Sets the default Ronin HTTP User-Agent string.
Class Method Details
.expand_options(options = {}) ⇒ Hash
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Expands the given HTTP options.
166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 |
# File 'lib/ronin/network/http/http.rb', line 166 def HTTP.(={}) = .dup [:port] ||= Net::HTTP.default_port [:path] ||= '/' if [:ssl] == true [:ssl] = {} end if (url = .delete(:url)) .merge!(HTTP.(url)) end [:proxy] = if .has_key?(:proxy) HTTP::Proxy.create([:proxy]) else HTTP.proxy end return end |
.expand_url(url) ⇒ Hash{Symbol => Object}
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Expands the URL into options.
104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 |
# File 'lib/ronin/network/http/http.rb', line 104 def HTTP.(url) = {} url = case url when URI url when Hash URI::HTTP.build(url) else URI(url.to_s) end [:ssl] = {} if url.scheme == 'https' [:host] = url.host [:port] = url.port [:user] = url.user if url.user [:password] = url.password if url.password [:path] = unless url.path.empty? url.path else '/' end [:path] += "?#{url.query}" if url.query return end |
.header_name(name) ⇒ String
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Converts an underscored, dashed, lowercase or uppercase HTTP header name to the standard camel-case HTTP header name.
201 202 203 204 205 206 |
# File 'lib/ronin/network/http/http.rb', line 201 def HTTP.header_name(name) words = name.to_s.split(/[\s+_-]/) words.each { |word| word.capitalize! } return words.join('-') end |
.headers(options = {}) ⇒ Hash
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Converts underscored, dashed, lowercase and uppercase HTTP headers to standard camel-cased HTTP headers.
220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 |
# File 'lib/ronin/network/http/http.rb', line 220 def HTTP.headers(={}) headers = {} if HTTP.user_agent headers['User-Agent'] = HTTP.user_agent end if .each do |name,value| headers[HTTP.header_name(name)] = value.to_s end end return headers end |
.proxy ⇒ Proxy
The Ronin HTTP proxy to use. Parses the value of the HTTP_PROXY
environment variable if set.
42 43 44 45 46 47 48 |
# File 'lib/ronin/network/http/http.rb', line 42 def HTTP.proxy @proxy ||= if ENV['HTTP_PROXY'] Proxy.parse(ENV['HTTP_PROXY']) else Proxy.new end end |
.proxy=(new_proxy) ⇒ Proxy
Sets the Ronin HTTP proxy to use.
65 66 67 |
# File 'lib/ronin/network/http/http.rb', line 65 def HTTP.proxy=(new_proxy) @proxy = Proxy.create(new_proxy) end |
.request(options = {}) ⇒ HTTP::Request
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Creates a specific type of HTTP request object.
277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 |
# File 'lib/ronin/network/http/http.rb', line 277 def HTTP.request(={}) unless [:method] raise(ArgumentError,"the :method option must be specified") end name = [:method].to_s.capitalize unless Net::HTTP.const_defined?(name) raise(UnknownRequest,"unknown HTTP request type #{name.dump}") end headers = HTTP.headers([:headers]) path = ([:path] || '/').to_s request = Net::HTTP.const_get(name).new(path,headers) if request.request_body_permitted? if [:form_data] request.set_form_data([:form_data]) elsif [:body] request.body = [:body] end end if (user = .delete(:user)) user = user.to_s if (password = .delete(:password)) password = password.to_s end request.basic_auth(user,password) end return request end |