Module: Ronin::Network::HTTP
- Included in:
- Net, Mixins::HTTP, Support, URI::HTTP
- Defined in:
- lib/ronin/network/http/http.rb,
lib/ronin/network/http/proxy.rb,
lib/ronin/network/http/exceptions/unknown_request.rb
Overview
Provides helper methods for communicating with HTTP Servers.
Defined Under Namespace
Classes: Proxy, UnknownRequest
Class Method Summary (collapse)
-
+ (Hash) expand_options(options = {})
private
Expands the given HTTP options.
-
+ (Hash{Symbol => Object}) expand_url(url)
private
Expands the URL into options.
-
+ (String) header_name(name)
private
Converts an underscored, dashed, lowercase or uppercase HTTP header name to the standard camel-case HTTP header name.
-
+ (Hash) headers(options = {})
private
Converts underscored, dashed, lowercase and uppercase HTTP headers to standard camel-cased HTTP headers.
-
+ (Proxy) proxy
The Ronin HTTP proxy to use.
-
+ (Proxy) proxy=(new_proxy)
Sets the Ronin HTTP proxy to use.
-
+ (HTTP::Request) request(options = {})
private
Creates a specific type of HTTP request object.
-
+ (String?) user_agent
The default Ronin HTTP User-Agent string.
-
+ (Object) user_agent=(agent)
Sets the default Ronin HTTP User-Agent string.
Instance Method Summary (collapse)
-
- (Net::HTTP) http_connect(options = {}) {|http| ... }
Starts a HTTP connection with the server.
-
- (Net::HTTP::Response) http_copy(options = {}) {|response| ... }
Performs an HTTP Copy request.
-
- (Net::HTTP::Response) http_delete(options = {}) {|response| ... }
Performs an HTTP Delete request.
-
- (Net::HTTP::Response) http_get(options = {}) {|response| ... }
Performs an HTTP Get request.
-
- (String) http_get_body(options = {})
Performs an HTTP Get request and returns the Respond Body.
-
- (Hash{String => Array<String>}) http_get_headers(options = {})
Performs an HTTP Get request and returns the Response Headers.
-
- (Net::HTTP::Response) http_head(options = {}) {|response| ... }
Performs an HTTP Head request.
-
- (Net::HTTP::Response) http_lock(options = {}) {|response| ... }
Performs an HTTP Lock request.
-
- (Net::HTTP::Response) http_mkcol(options = {}) {|response| ... }
Performs an HTTP Mkcol request.
-
- (Net::HTTP::Response) http_move(options = {}) {|response| ... }
Performs an HTTP Move request.
-
- (Boolean) http_ok?(options = {})
Checks if the response has an HTTP OK status code.
-
- (Net::HTTP::Response) http_options(options = {}) {|response| ... }
Performs an HTTP Options request.
-
- (Net::HTTP::Response) http_post(options = {}) {|response| ... }
Performs an HTTP Post request.
-
- (String) http_post_body(options = {})
Performs an HTTP Post request and returns the Response Body.
-
- (Hash{String => Array<String>}) http_post_headers(options = {})
Performs an HTTP Post request and returns the Response Headers.
-
- (String) http_powered_by(options = {})
Sends an HTTP Head request and returns the HTTP X-Powered-By header.
-
- (Net::HTTP::Response) http_prop_find(options = {}) {|response| ... }
Performs an HTTP Propfind request.
-
- (Net::HTTP::Response) http_prop_patch(options = {}) {|response| ... }
Performs an HTTP Proppatch request.
-
- (Net::HTTP::Response) http_put(options = {}) {|response| ... }
Performs an HTTP PUT request.
-
- (Net::HTTP::Response) http_request(options = {}) {|request, (options)| ... }
Connects to the HTTP server and sends an HTTP Request.
-
- (String) http_server(options = {})
Sends a HTTP Head request and returns the HTTP Server header.
-
- (nil) http_session(options = {}) {|http| ... }
Creates a new temporary HTTP session with the server.
-
- (Integer) http_status(options = {})
Returns the Status Code of the Response.
-
- (Net::HTTP::Response) http_trace(options = {}) {|response| ... }
Performs an HTTP Trace request.
-
- (Net::HTTP::Response) http_unlock(options = {}) {|response| ... }
Performs an HTTP Unlock request.
Class Method Details
+ (Hash) expand_options(options = {})
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.
178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 |
# File 'lib/ronin/network/http/http.rb', line 178 def self.(={}) = .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 |
+ (Hash{Symbol => Object}) expand_url(url)
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.
116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 |
# File 'lib/ronin/network/http/http.rb', line 116 def self.(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 |
+ (String) header_name(name)
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.
213 214 215 216 217 218 |
# File 'lib/ronin/network/http/http.rb', line 213 def self.header_name(name) words = name.to_s.split(/[\s+_-]/) words.each { |word| word.capitalize! } return words.join('-') end |
+ (Hash) headers(options = {})
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.
232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 |
# File 'lib/ronin/network/http/http.rb', line 232 def self.headers(={}) headers = {} if user_agent headers['User-Agent'] = user_agent end if .each do |name,value| headers[HTTP.header_name(name)] = value.to_s end end return headers end |
+ (Proxy) proxy
If the HTTP_PROXY environment variable is specified, it will
be used as the default value.
The Ronin HTTP proxy to use.
54 55 56 57 58 59 60 |
# File 'lib/ronin/network/http/http.rb', line 54 def self.proxy @proxy ||= if ENV['HTTP_PROXY'] Proxy.parse(ENV['HTTP_PROXY']) else Proxy.new end end |
+ (Proxy) proxy=(new_proxy)
Sets the Ronin HTTP proxy to use.
77 78 79 |
# File 'lib/ronin/network/http/http.rb', line 77 def self.proxy=(new_proxy) @proxy = Proxy.create(new_proxy) end |
+ (HTTP::Request) request(options = {})
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.
295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 |
# File 'lib/ronin/network/http/http.rb', line 295 def self.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 = headers([:headers]) path = ([:path] || '/').to_s query = if [:query] URI.escape([:query]) elsif [:query_params] URI::QueryParams.dump([:query_params]) end if query # append the query-string onto the path path += if path.include?('?') "&#{query}" else "?#{query}" end end 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] user = [:user].to_s password = if [:password] [:password].to_s end request.basic_auth(user,password) end return request end |
+ (String?) user_agent
The default Ronin HTTP User-Agent string.
89 90 91 |
# File 'lib/ronin/network/http/http.rb', line 89 def self.user_agent @user_agent ||= nil end |
+ (Object) user_agent=(agent)
Sets the default Ronin HTTP User-Agent string.
101 102 103 |
# File 'lib/ronin/network/http/http.rb', line 101 def self.user_agent=(agent) @user_agent = agent end |
Instance Method Details
- (Net::HTTP) http_connect(options = {}) {|http| ... }
Starts a HTTP connection with the server.
387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 |
# File 'lib/ronin/network/http/http.rb', line 387 def http_connect(={},&block) = HTTP.() host = [:host].to_s port = [:port] proxy = [:proxy] proxy_host = if (proxy && proxy[:host]) proxy[:host].to_s end http = Net::HTTP::Proxy( proxy_host, proxy[:port], proxy[:user], proxy[:password] ).new(host,port) if [:ssl] http.use_ssl = true http.verify_mode = SSL::VERIFY[[:ssl][:verify]] end http.start() if block if block.arity == 2 block.call(http,) else block.call(http) end end return http end |
- (Net::HTTP::Response) http_copy(options = {}) {|response| ... }
Performs an HTTP Copy request.
649 650 651 652 653 654 |
# File 'lib/ronin/network/http/http.rb', line 649 def http_copy(={}) response = http_request(.merge(:method => :copy)) yield response if block_given? return response end |
- (Net::HTTP::Response) http_delete(options = {}) {|response| ... }
Performs an HTTP Delete request.
676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 |
# File 'lib/ronin/network/http/http.rb', line 676 def http_delete(={},&block) original_headers = [:headers] # set the HTTP Depth header [:headers] = {:depth => 'Infinity'} if original_headers [:header].merge!(original_headers) end response = http_request(.merge(:method => :delete)) yield response if block_given? return response end |
- (Net::HTTP::Response) http_get(options = {}) {|response| ... }
Performs an HTTP Get request.
712 713 714 715 716 717 |
# File 'lib/ronin/network/http/http.rb', line 712 def http_get(={},&block) response = http_request(.merge(:method => :get)) yield response if block_given? return response end |
- (String) http_get_body(options = {})
Performs an HTTP Get request and returns the Respond Body.
757 758 759 |
# File 'lib/ronin/network/http/http.rb', line 757 def http_get_body(={}) http_get().body end |
- (Hash{String => Array<String>}) http_get_headers(options = {})
Performs an HTTP Get request and returns the Response Headers.
734 735 736 737 738 739 740 741 742 |
# File 'lib/ronin/network/http/http.rb', line 734 def http_get_headers(={}) headers = {} http_get().each_header do |name,value| headers[HTTP.header_name(name)] = value end return headers end |
- (Net::HTTP::Response) http_head(options = {}) {|response| ... }
Performs an HTTP Head request.
781 782 783 784 785 786 |
# File 'lib/ronin/network/http/http.rb', line 781 def http_head(={},&block) response = http_request(.merge(:method => :head)) yield response if block_given? return response end |
- (Net::HTTP::Response) http_lock(options = {}) {|response| ... }
Performs an HTTP Lock request.
808 809 810 811 812 813 |
# File 'lib/ronin/network/http/http.rb', line 808 def http_lock(={},&block) response = http_request(.merge(:method => :lock)) yield response if block_given? return response end |
- (Net::HTTP::Response) http_mkcol(options = {}) {|response| ... }
Performs an HTTP Mkcol request.
835 836 837 838 839 840 |
# File 'lib/ronin/network/http/http.rb', line 835 def http_mkcol(={},&block) response = http_request(.merge(:method => :mkcol)) yield response if block_given? return response end |
- (Net::HTTP::Response) http_move(options = {}) {|response| ... }
Performs an HTTP Move request.
862 863 864 865 866 867 |
# File 'lib/ronin/network/http/http.rb', line 862 def http_move(={},&block) response = http_request(.merge(:method => :move)) yield response if block_given? return response end |
- (Boolean) http_ok?(options = {})
Checks if the response has an HTTP OK status code.
581 582 583 |
# File 'lib/ronin/network/http/http.rb', line 581 def http_ok?(={}) http_status() == 200 end |
- (Net::HTTP::Response) http_options(options = {}) {|response| ... }
Performs an HTTP Options request.
889 890 891 892 893 894 |
# File 'lib/ronin/network/http/http.rb', line 889 def (={},&block) response = http_request(.merge(:method => :options)) yield response if block_given? return response end |
- (Net::HTTP::Response) http_post(options = {}) {|response| ... }
Performs an HTTP Post request.
919 920 921 922 923 924 |
# File 'lib/ronin/network/http/http.rb', line 919 def http_post(={},&block) response = http_request(.merge(:method => :post)) yield response if block_given? return response end |
- (String) http_post_body(options = {})
Performs an HTTP Post request and returns the Response Body.
970 971 972 |
# File 'lib/ronin/network/http/http.rb', line 970 def http_post_body(={}) http_post().body end |
- (Hash{String => Array<String>}) http_post_headers(options = {})
Performs an HTTP Post request and returns the Response Headers.
944 945 946 947 948 949 950 951 952 |
# File 'lib/ronin/network/http/http.rb', line 944 def http_post_headers(={}) headers = {} http_post().each_header do |name,value| headers[HTTP.header_name(name)] = value end return headers end |
- (String) http_powered_by(options = {})
Sends an HTTP Head request and returns the HTTP X-Powered-By header.
623 624 625 626 627 |
# File 'lib/ronin/network/http/http.rb', line 623 def http_powered_by(={}) = {:method => :get}.merge() return http_request()['x-powered-by'] end |
- (Net::HTTP::Response) http_prop_find(options = {}) {|response| ... }
Performs an HTTP Propfind request.
1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 |
# File 'lib/ronin/network/http/http.rb', line 1029 def http_prop_find(={},&block) original_headers = [:headers] # set the HTTP Depth header [:headers] = {:depth => '0'} if original_headers [:header].merge!(original_headers) end response = http_request(.merge(:method => :propfind)) yield response if block_given? return response end |
- (Net::HTTP::Response) http_prop_patch(options = {}) {|response| ... }
Performs an HTTP Proppatch request.
1065 1066 1067 1068 1069 1070 |
# File 'lib/ronin/network/http/http.rb', line 1065 def http_prop_patch(={},&block) response = http_request(.merge(:method => :proppatch)) yield response if block_given? return response end |
- (Net::HTTP::Response) http_put(options = {}) {|response| ... }
Performs an HTTP PUT request.
1002 1003 1004 1005 1006 1007 |
# File 'lib/ronin/network/http/http.rb', line 1002 def http_put(={}) response = http_request(.merge(:method => :put)) yield response if block_given? return response end |
- (Net::HTTP::Response) http_request(options = {}) {|request, (options)| ... }
Connects to the HTTP server and sends an HTTP Request.
521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 |
# File 'lib/ronin/network/http/http.rb', line 521 def http_request(={},&block) response = nil http_session() do |http,| req = HTTP.request() if block if block.arity == 2 block.call(req,) else block.call(req) end end response = http.request(req) end return response end |
- (String) http_server(options = {})
Sends a HTTP Head request and returns the HTTP Server header.
601 602 603 604 605 |
# File 'lib/ronin/network/http/http.rb', line 601 def http_server(={}) = {:method => :head}.merge() return http_request()['server'] end |
- (nil) http_session(options = {}) {|http| ... }
Creates a new temporary HTTP session with the server.
465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 |
# File 'lib/ronin/network/http/http.rb', line 465 def http_session(={},&block) http_connect() do |http,| if block if block.arity == 2 block.call(http,) else block.call(http) end end http.finish end return nil end |
- (Integer) http_status(options = {})
Returns the Status Code of the Response.
559 560 561 562 563 |
# File 'lib/ronin/network/http/http.rb', line 559 def http_status(={}) = {:method => :head}.merge() return http_request().code.to_i end |
- (Net::HTTP::Response) http_trace(options = {}) {|response| ... }
Performs an HTTP Trace request.
1092 1093 1094 1095 1096 1097 |
# File 'lib/ronin/network/http/http.rb', line 1092 def http_trace(={},&block) response = http_request(.merge(:method => :trace)) yield response if block_given? return response end |
- (Net::HTTP::Response) http_unlock(options = {}) {|response| ... }
Performs an HTTP Unlock request.
1119 1120 1121 1122 1123 1124 |
# File 'lib/ronin/network/http/http.rb', line 1119 def http_unlock(={},&block) response = http_request(.merge(:method => :unlock)) yield response if block_given? return response end |