Module: Ronin::Network::HTTP
Public Visibility
Public Class Method Summary
| expand_options(options = {}) |
Expands the given HTTP options. Returns: Hash |
|---|---|
| headers(options = {}) |
Converts underscored, dashed, lowercase and uppercase HTTP headers. Returns: Hash |
| proxy |
Returns: Proxy |
| request(options = {}) |
Creates an HTTP request object with the specified type and. Returns: HTTP::Request |
| user_agent |
Returns: String |
| user_agent=(agent) |
Sets the default Ronin HTTP User-Agent. |
Public Class Method Details
expand_options
Expands the given HTTP options.
84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 |
# File 'lib/ronin/network/http/http.rb', line 84 def HTTP.(={}) = .dup if [:url] url = URI(.delete(:url).to_s) [:host] = url.host [:port] = url.port [:user] = url.user if url.user [:password] = url.password if url.password unless url.path.empty? [:path] = url.path else [:path] = '/' end [:path] << "?#{url.query}" if url.query else [:port] ||= ::Net::HTTP.default_port [:path] ||= '/' end if (proxy = [:proxy]) unless proxy.kind_of?(Hash) [:proxy] = Ronin::Network::HTTP::Proxy.parse(proxy) end else [:proxy] = Ronin::Network::HTTP.proxy end return end |
headers
Converts underscored, dashed, lowercase and uppercase HTTP headers to standard camel-cased HTTP headers.
129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 |
# File 'lib/ronin/network/http/http.rb', line 129 def HTTP.headers(={}) headers = {} if HTTP.user_agent headers['User-Agent'] = HTTP.user_agent end if .each do |name,value| header_name = name.to_s.split(/[\s+_-]/).map { |word| word.capitalize }.join('-') headers[header_name] = value.to_s end end return headers end |
proxy
32 33 34 |
# File 'lib/ronin/network/http/http.rb', line 32 def HTTP.proxy @@http_proxy ||= Proxy.new end |
request
Creates an HTTP request object with the specified type and given options. If type does not represent the name of an Net:HTTP Request Class an UnknownRequest exception will be raised.
184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 |
# File 'lib/ronin/network/http/http.rb', line 184 def HTTP.request(={}) unless [:method] raise(ArgumentError,"the :method option must be specified",caller) end name = [:method].to_s.capitalize unless Net::HTTP.const_defined?(name) raise(UnknownRequest,"unknown HTTP request type #{name.dump}",caller) end headers = HTTP.headers([:headers]) path = ([:path] || '/').to_s request = Net::HTTP.const_get(name).new(path,headers) 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 |
user_agent
40 41 42 |
# File 'lib/ronin/network/http/http.rb', line 40 def HTTP.user_agent @@http_user_agent ||= nil end |
user_agent=
Sets the default Ronin HTTP User-Agent.
50 51 52 |
# File 'lib/ronin/network/http/http.rb', line 50 def HTTP.user_agent=(agent) @@http_user_agent = agent end |