lib/ronin/network/extensions/http/net.rb in ronin-0.2.4 vs lib/ronin/network/extensions/http/net.rb in ronin-0.3.0
- old
+ new
@@ -1,9 +1,7 @@
#
-#--
-# Ronin - A Ruby platform designed for information security and data
-# exploration tasks.
+# Ronin - A Ruby platform for exploit development and security research.
#
# Copyright (c) 2006-2009 Hal Brodigan (postmodern.mod3 at gmail.com)
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
@@ -16,45 +14,55 @@
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
-#++
#
require 'ronin/network/http'
require 'ronin/extensions/uri/http'
require 'net/http'
module Net
#
- # Connects to the HTTP server using the given _options_. If a _block_
- # is given it will be passed the newly created <tt>Net::HTTP</tt> object.
+ # Connects to the HTTP server using the given _options_.
#
- # _options_ may contain the following keys:
- # <tt>:url</tt>:: The full URL to request.
- # <tt>:user</tt>:: The user to authenticate with when connecting to the
- # HTTP server.
- # <tt>:password</tt>:: The password to authenticate with when connecting
- # to the HTTP server.
- # <tt>:host</tt>:: The host the HTTP server is running on.
- # <tt>:port</tt>:: The port the HTTP server is running on. Defaults to
- # <tt>Net::HTTP.default_port</tt>.
- # <tt>:path</tt>:: The path to request from the HTTP server.
- # <tt>:proxy</tt>:: A Hash of proxy settings to use when connecting to
- # the HTTP server. Defaults to
- # <tt>Ronin::Network::HTTP.proxy</tt>.
- # <tt>:host</tt>:: The HTTP proxy host to connect to.
- # <tt>:port</tt>:: The HTTP proxy port to connect to.
- # Defaults to <tt>Ronin::Network::HTTP.default_proxy_port</tt>.
- # <tt>:user</tt>:: The user to authenticate with
- # when connecting to the HTTP proxy.
- # <tt>:password</tt>:: The password to authenticate with
- # when connecting to the HTTP
- # proxy.
+ # @param [Hash] options
+ # Additional options
#
+ # @option options [String, URI::HTTP] :url
+ # The full URL to request.
+ #
+ # @option options [String] :user
+ # The user to authenticate with when connecting to the HTTP server.
+ #
+ # @option options [String] :password
+ # The password to authenticate with when connecting to the HTTP server.
+ #
+ # @option options [String] :host
+ # The host the HTTP server is running on.
+ #
+ # @option options [Integer] :port (Net::HTTP.default_port)
+ # The port the HTTP server is listening on.
+ #
+ # @option options [String] :path
+ # The path to request from the HTTP server.
+ #
+ # @option options [String, Hash] :proxy (Ronin::Network::HTTP.proxy)
+ # A Hash of proxy settings to use when connecting to the HTTP server.
+ #
+ # @yield [session]
+ # If a block is given, it will be passed the newly created HTTP
+ # session object.
+ #
+ # @yieldparam [Net::HTTP] session
+ # The newly created HTTP session.
+ #
+ # @return [Net::HTTP]
+ # The HTTP session object.
+ #
def Net.http_session(options={},&block)
options = Ronin::Network::HTTP.expand_options(options)
host = options[:host]
port = options[:port]
@@ -74,38 +82,38 @@
end
#
# Connects to the HTTP server and sends an HTTP Request using the given
# _options_. If a _block_ is given it will be passed the newly created
- # HTTP Request object. Returns the <tt>Net::HTTP::Response</tt> that
- # was returned.
+ # HTTP Request object.
#
- # _options_ may contain the following keys:
- # <tt>:method</tt>:: The HTTP method to use for the request.
- # <tt>:url</tt>:: The full URL to request.
- # <tt>:user</tt>:: The user to authenticate with when connecting to the
- # HTTP server.
- # <tt>:password</tt>:: The password to authenticate with when connecting
- # to the HTTP server.
- # <tt>:host</tt>:: The host the HTTP server is running on.
- # <tt>:port</tt>:: The port the HTTP server is running on. Defaults to
- # <tt>Net::HTTP.default_port</tt>.
- # <tt>:path</tt>:: The path to request from the HTTP server.
- # <tt>:proxy</tt>:: A Hash of proxy settings to use when connecting to
- # the HTTP server. Defaults to
- # <tt>Ronin::Network::HTTP.proxy</tt>.
- # <tt>:host</tt>:: The HTTP proxy host to connect to.
- # <tt>:port</tt>:: The HTTP proxy port to connect to.
- # Defaults to <tt>Ronin::Network::HTTP.default_proxy_port</tt>.
- # <tt>:user</tt>:: The user to authenticate with
- # when connecting to the HTTP proxy.
- # <tt>:password</tt>:: The password to authenticate with
- # when connecting to the HTTP
- # proxy.
- # <tt>:headers</tt>:: A Hash of the HTTP Headers to send with the request.
- # May use Strings or Symbols for the keys of the Hash.
+ # @param [Hash] options
+ # Additional options.
#
+ # @option options [Symbol, String] :method
+ # The HTTP method to use in the request.
+ #
+ # @option options [Hash] :headers
+ # The Hash of the HTTP headers to send with the request.
+ # May contain either Strings or Symbols, lower-case or camel-case keys.
+ #
+ # @yield [request, (options)]
+ # If a block is given, it will be passed the HTTP request object.
+ # If the block has an arity of 2, it will also be passed the expanded
+ # version of the given _options_.
+ #
+ # @yieldparam [Net::HTTP::Request] request
+ # The HTTP request object to use in the request.
+ #
+ # @yieldparam [Hash] options
+ # The expanded version of the given _options_.
+ #
+ # @return [Net::HTTP::Response]
+ # The response of the HTTP request.
+ #
+ # @see http_session
+ #
def Net.http_request(options={},&block)
resp = nil
Net.http_session(options) do |http,expanded_options|
http_body = expanded_options.delete(:body)
@@ -127,74 +135,52 @@
end
#
# Performes an HTTP Copy request with the given _options_. If a _block_
# is given, it will be passed the response from the HTTP server.
- # Returns the response from the HTTP server.
#
- # _options_ may contain the following keys:
- # <tt>:url</tt>:: The full URL to request.
- # <tt>:user</tt>:: The user to authenticate with when connecting to the
- # HTTP server.
- # <tt>:password</tt>:: The password to authenticate with when connecting
- # to the HTTP server.
- # <tt>:host</tt>:: The host the HTTP server is running on.
- # <tt>:port</tt>:: The port the HTTP server is running on. Defaults to
- # <tt>Net::HTTP.default_port</tt>.
- # <tt>:path</tt>:: The path to request from the HTTP server.
- # <tt>:proxy</tt>:: A Hash of proxy settings to use when connecting to
- # the HTTP server. Defaults to
- # <tt>Ronin::Network::HTTP.proxy</tt>.
- # <tt>:host</tt>:: The HTTP proxy host to connect to.
- # <tt>:port</tt>:: The HTTP proxy port to connect to.
- # Defaults to <tt>Ronin::Network::HTTP.default_proxy_port</tt>.
- # <tt>:user</tt>:: The user to authenticate with
- # when connecting to the HTTP proxy.
- # <tt>:password</tt>:: The password to authenticate with
- # when connecting to the HTTP
- # proxy.
- # <tt>:headers</tt>:: A Hash of the HTTP Headers to send with the HTTP
- # Copy request. May use Strings or Symbols for the
- # keys of the Hash.
+ # @param [Hash] options
+ # Additional options.
#
+ # @yield [response]
+ # If a block is given, it will be passed the response received
+ # from the request.
+ #
+ # @yieldparam [Net::HTTP::Response] response
+ # The HTTP response object.
+ #
+ # @return [Net::HTTP::Response]
+ # The response of the HTTP request.
+ #
+ # @see http_request
+ #
def Net.http_copy(options={},&block)
resp = Net.http_request(options.merge(:method => :copy))
block.call(resp) if block
return resp
end
#
# Performes an HTTP Delete request with the given _options_. If a _block_
# is given, it will be passed the response from the HTTP server.
- # Returns the response from the HTTP server.
#
- # _options_ may contain the following keys:
- # <tt>:url</tt>:: The full URL to request.
- # <tt>:user</tt>:: The user to authenticate with when connecting to the
- # HTTP server.
- # <tt>:password</tt>:: The password to authenticate with when connecting
- # to the HTTP server.
- # <tt>:host</tt>:: The host the HTTP server is running on.
- # <tt>:port</tt>:: The port the HTTP server is running on. Defaults to
- # <tt>Net::HTTP.default_port</tt>.
- # <tt>:path</tt>:: The path to request from the HTTP server.
- # <tt>:proxy</tt>:: A Hash of proxy settings to use when connecting to
- # the HTTP server. Defaults to
- # <tt>Ronin::Network::HTTP.proxy</tt>.
- # <tt>:host</tt>:: The HTTP proxy host to connect to.
- # <tt>:port</tt>:: The HTTP proxy port to connect to.
- # Defaults to <tt>Ronin::Network::HTTP.default_proxy_port</tt>.
- # <tt>:user</tt>:: The user to authenticate with
- # when connecting to the HTTP proxy.
- # <tt>:password</tt>:: The password to authenticate with
- # when connecting to the HTTP
- # proxy.
- # <tt>:headers</tt>:: A Hash of the HTTP Headers to send with the HTTP
- # Delete request. May use Strings or Symbols for the
- # keys of the Hash.
+ # @param [Hash] options
+ # Additional options.
#
+ # @yield [response]
+ # If a block is given, it will be passed the response received from
+ # the request.
+ #
+ # @yieldparam [Net::HTTP::Response] response
+ # The HTTP response object.
+ #
+ # @return [Net::HTTP::Response]
+ # The response of the HTTP request.
+ #
+ # @see http_request
+ #
def Net.http_delete(options={},&block)
original_headers = options[:headers]
# set the HTTP Depth header
options[:headers] = {:depth => 'Infinity'}
@@ -210,218 +196,125 @@
end
#
# Performes an HTTP Get request with the given _options_. If a _block_
# is given, it will be passed the response from the HTTP server.
- # Returns the response from the HTTP server.
#
- # _options_ may contain the following keys:
- # <tt>:url</tt>:: The full URL to request.
- # <tt>:user</tt>:: The user to authenticate with when connecting to the
- # HTTP server.
- # <tt>:password</tt>:: The password to authenticate with when connecting
- # to the HTTP server.
- # <tt>:host</tt>:: The host the HTTP server is running on.
- # <tt>:port</tt>:: The port the HTTP server is running on. Defaults to
- # <tt>Net::HTTP.default_port</tt>.
- # <tt>:path</tt>:: The path to request from the HTTP server.
- # <tt>:proxy</tt>:: A Hash of proxy settings to use when connecting to
- # the HTTP server. Defaults to
- # <tt>Ronin::Network::HTTP.proxy</tt>.
- # <tt>:host</tt>:: The HTTP proxy host to connect to.
- # <tt>:port</tt>:: The HTTP proxy port to connect to.
- # Defaults to <tt>Ronin::Network::HTTP.default_proxy_port</tt>.
- # <tt>:user</tt>:: The user to authenticate with
- # when connecting to the HTTP proxy.
- # <tt>:password</tt>:: The password to authenticate with
- # when connecting to the HTTP
- # proxy.
- # <tt>:headers</tt>:: A Hash of the HTTP Headers to send with the HTTP
- # Get request. May use Strings or Symbols for the
- # keys of the Hash.
+ # @param [Hash] options
+ # Additional options.
#
+ # @yield [response]
+ # If a block is given, it will be passed the response received from
+ # the request.
+ #
+ # @yieldparam [Net::HTTP::Response] response
+ # The HTTP response object.
+ #
+ # @return [Net::HTTP::Response]
+ # The response of the HTTP request.
+ #
+ # @see http_request
+ #
def Net.http_get(options={},&block)
resp = Net.http_request(options.merge(:method => :get))
block.call(resp) if block
return resp
end
#
# Performes an HTTP Get request with the given _options_. If a _block_
# is given, it will be passed the response body from the HTTP server.
- # Returns the response body from the HTTP server.
#
- # _options_ may contain the following keys:
- # <tt>:url</tt>:: The full URL to request.
- # <tt>:user</tt>:: The user to authenticate with when connecting to the
- # HTTP server.
- # <tt>:password</tt>:: The password to authenticate with when connecting
- # to the HTTP server.
- # <tt>:host</tt>:: The host the HTTP server is running on.
- # <tt>:port</tt>:: The port the HTTP server is running on. Defaults to
- # <tt>Net::HTTP.default_port</tt>.
- # <tt>:path</tt>:: The path to request from the HTTP server.
- # <tt>:proxy</tt>:: A Hash of proxy settings to use when connecting to
- # the HTTP server. Defaults to
- # <tt>Ronin::Network::HTTP.proxy</tt>.
- # <tt>:host</tt>:: The HTTP proxy host to connect to.
- # <tt>:port</tt>:: The HTTP proxy port to connect to.
- # Defaults to <tt>Ronin::Network::HTTP.default_proxy_port</tt>.
- # <tt>:user</tt>:: The user to authenticate with
- # when connecting to the HTTP proxy.
- # <tt>:password</tt>:: The password to authenticate with
- # when connecting to the HTTP
- # proxy.
- # <tt>:headers</tt>:: A Hash of the HTTP Headers to send with the HTTP
- # Get request. May use Strings or Symbols for the
- # keys of the Hash.
+ # @param [Hash] options
+ # Additional options.
#
+ # @yield [response]
+ # If a block is given, it will be passed the response received from
+ # the request.
+ #
+ # @yieldparam [Net::HTTP::Response] response
+ # The HTTP response object.
+ #
+ # @return [String]
+ # The body of the HTTP response.
+ #
+ # @see http_request
+ #
def Net.http_get_body(options={},&block)
Net.http_get(options,&block).body
end
#
# Performes an HTTP Head request with the given _options_. If a _block_
# is given, it will be passed the response from the HTTP server.
- # Returns the response from the HTTP server.
#
- # _options_ may contain the following keys:
- # <tt>:url</tt>:: The full URL to request.
- # <tt>:user</tt>:: The user to authenticate with when connecting to the
- # HTTP server.
- # <tt>:password</tt>:: The password to authenticate with when connecting
- # to the HTTP server.
- # <tt>:host</tt>:: The host the HTTP server is running on.
- # <tt>:port</tt>:: The port the HTTP server is running on. Defaults to
- # <tt>Net::HTTP.default_port</tt>.
- # <tt>:path</tt>:: The path to request from the HTTP server.
- # <tt>:proxy</tt>:: A Hash of proxy settings to use when connecting to
- # the HTTP server. Defaults to
- # <tt>Ronin::Network::HTTP.proxy</tt>.
- # <tt>:host</tt>:: The HTTP proxy host to connect to.
- # <tt>:port</tt>:: The HTTP proxy port to connect to.
- # Defaults to <tt>Ronin::Network::HTTP.default_proxy_port</tt>.
- # <tt>:user</tt>:: The user to authenticate with
- # when connecting to the HTTP proxy.
- # <tt>:password</tt>:: The password to authenticate with
- # when connecting to the HTTP
- # proxy.
- # <tt>:headers</tt>:: A Hash of the HTTP Headers to send with the HTTP
- # Head request. May use Strings or Symbols for the
- # keys of the Hash.
+ # @param [Hash] options
+ # Additional options.
#
+ # @yield [response]
+ # If a block is given, it will be passed the response received from
+ # the request.
+ #
+ # @yieldparam [Net::HTTP::Response] response
+ # The HTTP response object.
+ #
+ # @return [Net::HTTP::Response]
+ # The response of the HTTP request.
+ #
+ # @see http_request
+ #
def Net.http_head(options={},&block)
resp = Net.http_request(options.merge(:method => :head))
block.call(resp) if block
return resp
end
#
- # Returns +true+ if a HTTP Head request with the given _options_ returns
- # the HTTP status code of 200, returns +false+ otherwise.
+ # Checks if the response has an HTTP OK status code.
#
- # _options_ may contain the following keys:
- # <tt>:url</tt>:: The full URL to request.
- # <tt>:user</tt>:: The user to authenticate with when connecting to the
- # HTTP server.
- # <tt>:password</tt>:: The password to authenticate with when connecting
- # to the HTTP server.
- # <tt>:host</tt>:: The host the HTTP server is running on.
- # <tt>:port</tt>:: The port the HTTP server is running on. Defaults to
- # <tt>Net::HTTP.default_port</tt>.
- # <tt>:path</tt>:: The path to request from the HTTP server.
- # <tt>:proxy</tt>:: A Hash of proxy settings to use when connecting to
- # the HTTP server. Defaults to
- # <tt>Ronin::Network::HTTP.proxy</tt>.
- # <tt>:host</tt>:: The HTTP proxy host to connect to.
- # <tt>:port</tt>:: The HTTP proxy port to connect to.
- # Defaults to <tt>Ronin::Network::HTTP.default_proxy_port</tt>.
- # <tt>:user</tt>:: The user to authenticate with
- # when connecting to the HTTP proxy.
- # <tt>:password</tt>:: The password to authenticate with
- # when connecting to the HTTP
- # proxy.
- # <tt>:headers</tt>:: A Hash of the HTTP Headers to send with the HTTP
- # Head request. May use Strings or Symbols for the
- # keys of the Hash.
+ # @param [Hash] options
+ # Additional options.
#
+ # @return [Boolean]
+ # Specifies wether the response had an HTTP OK status code or not.
#
+ # @see http_request
+ #
def Net.http_ok?(options={})
Net.http_head(options).code == 200
end
#
# Sends a HTTP Head request using the given _options_ and returns the
# HTTP Server header.
#
- # _options_ may contain the following keys:
- # <tt>:url</tt>:: The full URL to request.
- # <tt>:user</tt>:: The user to authenticate with when connecting to the
- # HTTP server.
- # <tt>:password</tt>:: The password to authenticate with when connecting
- # to the HTTP server.
- # <tt>:host</tt>:: The host the HTTP server is running on.
- # <tt>:port</tt>:: The port the HTTP server is running on. Defaults to
- # <tt>Net::HTTP.default_port</tt>.
- # <tt>:path</tt>:: The path to request from the HTTP server.
- # <tt>:proxy</tt>:: A Hash of proxy settings to use when connecting to
- # the HTTP server. Defaults to
- # <tt>Ronin::Network::HTTP.proxy</tt>.
- # <tt>:host</tt>:: The HTTP proxy host to connect to.
- # <tt>:port</tt>:: The HTTP proxy port to connect to.
- # Defaults to <tt>Ronin::Network::HTTP.default_proxy_port</tt>.
- # <tt>:user</tt>:: The user to authenticate with
- # when connecting to the HTTP proxy.
- # <tt>:password</tt>:: The password to authenticate with
- # when connecting to the HTTP
- # proxy.
- # <tt>:headers</tt>:: A Hash of the HTTP Headers to send with the HTTP
- # Head request. May use Strings or Symbols for the
- # keys of the Hash.
+ # @param [Hash] options
+ # Additional options.
#
- # Net.http_server(:url => 'http://www.darkc0de.com/)
- # # => "Apache/2.2.11 (Unix) PHP/4.4.9 mod_ssl/2.2.11 OpenSSL/0.9.8c
- # mod_fastcgi/2.4.6 Phusion_Passenger/2.1.2 DAV/2 SVN/1.4.2"
+ # @return [String]
+ # The HTTP +Server+ header.
#
+ # @see http_request
+ #
def Net.http_server(options={})
Net.http_head(options)['server']
end
#
# Sends an HTTP Head request using the given _options_ and returns the
# HTTP X-Powered-By header.
#
- # _options_ may contain the following keys:
- # <tt>:url</tt>:: The full URL to request.
- # <tt>:user</tt>:: The user to authenticate with when connecting to the
- # HTTP server.
- # <tt>:password</tt>:: The password to authenticate with when connecting
- # to the HTTP server.
- # <tt>:host</tt>:: The host the HTTP server is running on.
- # <tt>:port</tt>:: The port the HTTP server is running on. Defaults to
- # <tt>Net::HTTP.default_port</tt>.
- # <tt>:path</tt>:: The path to request from the HTTP server.
- # <tt>:proxy</tt>:: A Hash of proxy settings to use when connecting to
- # the HTTP server. Defaults to
- # <tt>Ronin::Network::HTTP.proxy</tt>.
- # <tt>:host</tt>:: The HTTP proxy host to connect to.
- # <tt>:port</tt>:: The HTTP proxy port to connect to.
- # Defaults to <tt>Ronin::Network::HTTP.default_proxy_port</tt>.
- # <tt>:user</tt>:: The user to authenticate with
- # when connecting to the HTTP proxy.
- # <tt>:password</tt>:: The password to authenticate with
- # when connecting to the HTTP
- # proxy.
- # <tt>:headers</tt>:: A Hash of the HTTP Headers to send with the HTTP
- # Head request. May use Strings or Symbols for the
- # keys of the Hash.
+ # @param [Hash] options
+ # Additional options.
#
- # Net.http_powered_by(:url => 'http://www.stalkdaily.com/')
- # # => "PHP/5.2.9"
+ # @return [String]
+ # The HTTP +X-Powered-By+ header.
#
+ # @see http_request
+ #
def Net.http_powered_by(options={})
resp = Net.http_head(options)
if resp.code != 200
resp = Net.http_get(options)
@@ -431,267 +324,195 @@
end
#
# Performes an HTTP Lock request with the given _options_. If a _block_
# is given, it will be passed the response from the HTTP server.
- # Returns the response from the HTTP server.
#
- # _options_ may contain the following keys:
- # <tt>:url</tt>:: The full URL to request.
- # <tt>:user</tt>:: The user to authenticate with when connecting to the
- # HTTP server.
- # <tt>:password</tt>:: The password to authenticate with when connecting
- # to the HTTP server.
- # <tt>:host</tt>:: The host the HTTP server is running on.
- # <tt>:port</tt>:: The port the HTTP server is running on. Defaults to
- # <tt>Net::HTTP.default_port</tt>.
- # <tt>:path</tt>:: The path to request from the HTTP server.
- # <tt>:proxy</tt>:: A Hash of proxy settings to use when connecting to
- # the HTTP server. Defaults to
- # <tt>Ronin::Network::HTTP.proxy</tt>.
- # <tt>:host</tt>:: The HTTP proxy host to connect to.
- # <tt>:port</tt>:: The HTTP proxy port to connect to.
- # Defaults to <tt>Ronin::Network::HTTP.default_proxy_port</tt>.
- # <tt>:user</tt>:: The user to authenticate with
- # when connecting to the HTTP proxy.
- # <tt>:password</tt>:: The password to authenticate with
- # when connecting to the HTTP
- # proxy.
- # <tt>:headers</tt>:: A Hash of the HTTP Headers to send with the HTTP
- # Lock request. May use Strings or Symbols for the
- # keys of the Hash.
+ # @param [Hash] options
+ # Additional options.
#
+ # @yield [response]
+ # If a block is given, it will be passed the response received from
+ # the request.
+ #
+ # @yieldparam [Net::HTTP::Response] response
+ # The HTTP response object.
+ #
+ # @return [Net::HTTP::Response]
+ # The response of the HTTP request.
+ #
+ # @see http_request
+ #
def Net.http_lock(options={},&block)
resp = Net.http_request(options.merge(:method => :lock))
block.call(resp) if block
return resp
end
#
# Performes an HTTP Mkcol request with the given _options_. If a _block_
# is given, it will be passed the response from the HTTP server.
- # Returns the response from the HTTP server.
#
- # _options_ may contain the following keys:
- # <tt>:url</tt>:: The full URL to request.
- # <tt>:user</tt>:: The user to authenticate with when connecting to the
- # HTTP server.
- # <tt>:password</tt>:: The password to authenticate with when connecting
- # to the HTTP server.
- # <tt>:host</tt>:: The host the HTTP server is running on.
- # <tt>:port</tt>:: The port the HTTP server is running on. Defaults to
- # <tt>Net::HTTP.default_port</tt>.
- # <tt>:path</tt>:: The path to request from the HTTP server.
- # <tt>:proxy</tt>:: A Hash of proxy settings to use when connecting to
- # the HTTP server. Defaults to
- # <tt>Ronin::Network::HTTP.proxy</tt>.
- # <tt>:host</tt>:: The HTTP proxy host to connect to.
- # <tt>:port</tt>:: The HTTP proxy port to connect to.
- # Defaults to <tt>Ronin::Network::HTTP.default_proxy_port</tt>.
- # <tt>:user</tt>:: The user to authenticate with
- # when connecting to the HTTP proxy.
- # <tt>:password</tt>:: The password to authenticate with
- # when connecting to the HTTP
- # proxy.
- # <tt>:headers</tt>:: A Hash of the HTTP Headers to send with the HTTP
- # Mkcol request. May use Strings or Symbols for the
- # keys of the Hash.
+ # @param [Hash] options
+ # Additional options.
#
+ # @yield [response]
+ # If a block is given, it will be passed the response received from
+ # the request.
+ #
+ # @yieldparam [Net::HTTP::Response] response
+ # The HTTP response object.
+ #
+ # @return [Net::HTTP::Response]
+ # The response of the HTTP request.
+ #
+ # @see http_request
+ #
def Net.http_mkcol(options={},&block)
resp = Net.http_request(options.merge(:method => :mkcol))
block.call(resp) if block
return resp
end
#
# Performes an HTTP Move request with the given _options_. If a _block_
# is given, it will be passed the response from the HTTP server.
- # Returns the response from the HTTP server.
#
- # _options_ may contain the following keys:
- # <tt>:url</tt>:: The full URL to request.
- # <tt>:user</tt>:: The user to authenticate with when connecting to the
- # HTTP server.
- # <tt>:password</tt>:: The password to authenticate with when connecting
- # to the HTTP server.
- # <tt>:host</tt>:: The host the HTTP server is running on.
- # <tt>:port</tt>:: The port the HTTP server is running on. Defaults to
- # <tt>Net::HTTP.default_port</tt>.
- # <tt>:path</tt>:: The path to request from the HTTP server.
- # <tt>:proxy</tt>:: A Hash of proxy settings to use when connecting to
- # the HTTP server. Defaults to
- # <tt>Ronin::Network::HTTP.proxy</tt>.
- # <tt>:host</tt>:: The HTTP proxy host to connect to.
- # <tt>:port</tt>:: The HTTP proxy port to connect to.
- # Defaults to <tt>Ronin::Network::HTTP.default_proxy_port</tt>.
- # <tt>:user</tt>:: The user to authenticate with
- # when connecting to the HTTP proxy.
- # <tt>:password</tt>:: The password to authenticate with
- # when connecting to the HTTP
- # proxy.
- # <tt>:headers</tt>:: A Hash of the HTTP Headers to send with the HTTP
- # Move request. May use Strings or Symbols for the
- # keys of the Hash.
+ # @param [Hash] options
+ # Additional options.
#
+ # @yield [response]
+ # If a block is given, it will be passed the response received from
+ # the request.
+ #
+ # @yieldparam [Net::HTTP::Response] response
+ # The HTTP response object.
+ #
+ # @return [Net::HTTP::Response]
+ # The response of the HTTP request.
+ #
+ # @see http_request
+ #
def Net.http_move(options={},&block)
resp = Net.http_request(options.merge(:method => :move))
block.call(resp) if block
return resp
end
#
# Performes an HTTP Options request with the given _options_. If a _block_
# is given, it will be passed the response from the HTTP server.
- # Returns the response from the HTTP server.
#
- # _options_ may contain the following keys:
- # <tt>:url</tt>:: The full URL to request.
- # <tt>:user</tt>:: The user to authenticate with when connecting to the
- # HTTP server.
- # <tt>:password</tt>:: The password to authenticate with when connecting
- # to the HTTP server.
- # <tt>:host</tt>:: The host the HTTP server is running on.
- # <tt>:port</tt>:: The port the HTTP server is running on. Defaults to
- # <tt>Net::HTTP.default_port</tt>.
- # <tt>:path</tt>:: The path to request from the HTTP server.
- # <tt>:proxy</tt>:: A Hash of proxy settings to use when connecting to
- # the HTTP server. Defaults to
- # <tt>Ronin::Network::HTTP.proxy</tt>.
- # <tt>:host</tt>:: The HTTP proxy host to connect to.
- # <tt>:port</tt>:: The HTTP proxy port to connect to.
- # Defaults to <tt>Ronin::Network::HTTP.default_proxy_port</tt>.
- # <tt>:user</tt>:: The user to authenticate with
- # when connecting to the HTTP proxy.
- # <tt>:password</tt>:: The password to authenticate with
- # when connecting to the HTTP
- # proxy.
- # <tt>:headers</tt>:: A Hash of the HTTP Headers to send with the HTTP
- # Options request. May use Strings or Symbols for
- # the keys of the Hash.
+ # @param [Hash] options
+ # Additional options.
#
+ # @yield [response]
+ # If a block is given, it will be passed the response received from
+ # the request.
+ #
+ # @yieldparam [Net::HTTP::Response] response
+ # The HTTP response object.
+ #
+ # @return [Net::HTTP::Response]
+ # The response of the HTTP request.
+ #
+ # @see http_request
+ #
def Net.http_options(options={},&block)
resp = Net.http_request(options.merge(:method => :options))
block.call(resp) if block
return resp
end
#
# Performes an HTTP Post request with the given _options_. If a _block_
# is given, it will be passed the response from the HTTP server.
- # Returns the response from the HTTP server.
#
- # _options_ may contain the following keys:
- # <tt>:url</tt>:: The full URL to request.
- # <tt>:user</tt>:: The user to authenticate with when connecting to the
- # HTTP server.
- # <tt>:password</tt>:: The password to authenticate with when connecting
- # to the HTTP server.
- # <tt>:host</tt>:: The host the HTTP server is running on.
- # <tt>:port</tt>:: The port the HTTP server is running on. Defaults to
- # <tt>Net::HTTP.default_port</tt>.
- # <tt>:path</tt>:: The path to request from the HTTP server.
- # <tt>:proxy</tt>:: A Hash of proxy settings to use when connecting to
- # the HTTP server. Defaults to
- # <tt>Ronin::Network::HTTP.proxy</tt>.
- # <tt>:host</tt>:: The HTTP proxy host to connect to.
- # <tt>:port</tt>:: The HTTP proxy port to connect to.
- # Defaults to <tt>Ronin::Network::HTTP.default_proxy_port</tt>.
- # <tt>:user</tt>:: The user to authenticate with
- # when connecting to the HTTP proxy.
- # <tt>:password</tt>:: The password to authenticate with
- # when connecting to the HTTP
- # proxy.
- # <tt>:post_data</tt>:: The POSTDATA to send with the HTTP Post request.
- # <tt>:headers</tt>:: A Hash of the HTTP Headers to send with the HTTP
- # Post request. May use Strings or Symbols for the
- # keys of the Hash.
+ # @param [Hash] options
+ # Additional options.
#
+ # @option options [String] :postdata
+ # The +POSTDATA+ to send with the HTTP Post request.
+ #
+ # @yield [response]
+ # If a block is given, it will be passed the response received from
+ # the request.
+ #
+ # @yieldparam [Net::HTTP::Response] response
+ # The HTTP response object.
+ #
+ # @return [Net::HTTP::Response]
+ # The response of the HTTP request.
+ #
+ # @see http_request
+ #
def Net.http_post(options={},&block)
options = options.merge(:method => :post)
- post_data = options.delete(:post_data)
+ postdata = options.delete(:postdata)
if options[:url]
url = URI(options[:url].to_s)
- post_data ||= url.query_params
+ postdata ||= url.query_params
end
resp = Net.http_request(options) do |req,expanded_options|
- req.set_form_data(post_data) if post_data
+ req.set_form_data(postdata) if postdata
end
block.call(resp) if block
return resp
end
#
# Performes an HTTP Post request with the given _options_. If a _block_
# is given, it will be passed the response body from the HTTP server.
- # Returns the response body from the HTTP server.
#
- # _options_ may contain the following keys:
- # <tt>:url</tt>:: The full URL to request.
- # <tt>:user</tt>:: The user to authenticate with when connecting to the
- # HTTP server.
- # <tt>:password</tt>:: The password to authenticate with when connecting
- # to the HTTP server.
- # <tt>:host</tt>:: The host the HTTP server is running on.
- # <tt>:port</tt>:: The port the HTTP server is running on. Defaults to
- # <tt>Net::HTTP.default_port</tt>.
- # <tt>:path</tt>:: The path to request from the HTTP server.
- # <tt>:proxy</tt>:: A Hash of proxy settings to use when connecting to
- # the HTTP server. Defaults to
- # <tt>Ronin::Network::HTTP.proxy</tt>.
- # <tt>:host</tt>:: The HTTP proxy host to connect to.
- # <tt>:port</tt>:: The HTTP proxy port to connect to.
- # Defaults to <tt>Ronin::Network::HTTP.default_proxy_port</tt>.
- # <tt>:user</tt>:: The user to authenticate with
- # when connecting to the HTTP proxy.
- # <tt>:password</tt>:: The password to authenticate with
- # when connecting to the HTTP
- # proxy.
- # <tt>:headers</tt>:: A Hash of the HTTP Headers to send with the HTTP
- # Post request. May use Strings or Symbols for the
- # keys of the Hash.
+ # @param [Hash] options
+ # Additional options.
#
+ # @option options [String] :postdata
+ # The +POSTDATA+ to send with the HTTP Post request.
+ #
+ # @yield [response]
+ # If a block is given, it will be passed the response received from
+ # the request.
+ #
+ # @yieldparam [Net::HTTP::Response] response
+ # The HTTP response object.
+ #
+ # @return [String]
+ # The body of the HTTP response.
+ #
+ # @see http_request
+ #
def Net.http_post_body(options={},&block)
Net.http_post(options,&block).body
end
#
# Performes an HTTP Propfind request with the given _options_. If a
# _block_ is given, it will be passed the response from the HTTP server.
- # Returns the response from the HTTP server.
#
- # _options_ may contain the following keys:
- # <tt>:url</tt>:: The full URL to request.
- # <tt>:user</tt>:: The user to authenticate with when connecting to the
- # HTTP server.
- # <tt>:password</tt>:: The password to authenticate with when connecting
- # to the HTTP server.
- # <tt>:host</tt>:: The host the HTTP server is running on.
- # <tt>:port</tt>:: The port the HTTP server is running on. Defaults to
- # <tt>Net::HTTP.default_port</tt>.
- # <tt>:path</tt>:: The path to request from the HTTP server.
- # <tt>:proxy</tt>:: A Hash of proxy settings to use when connecting to
- # the HTTP server. Defaults to
- # <tt>Ronin::Network::HTTP.proxy</tt>.
- # <tt>:host</tt>:: The HTTP proxy host to connect to.
- # <tt>:port</tt>:: The HTTP proxy port to connect to.
- # Defaults to <tt>Ronin::Network::HTTP.default_proxy_port</tt>.
- # <tt>:user</tt>:: The user to authenticate with
- # when connecting to the HTTP proxy.
- # <tt>:password</tt>:: The password to authenticate with
- # when connecting to the HTTP
- # proxy.
- # <tt>:headers</tt>:: A Hash of the HTTP Headers to send with the HTTP
- # Propfind request. May use Strings or Symbols for
- # the keys of the Hash.
+ # @param [Hash] options
+ # Additional options.
#
+ # @yield [response]
+ # If a block is given, it will be passed the response received from
+ # the request.
+ #
+ # @yieldparam [Net::HTTP::Response] response
+ # The HTTP response object.
+ #
+ # @return [Net::HTTP::Response]
+ # The response of the HTTP request.
+ #
+ # @see http_request
+ #
def Net.http_prop_find(options={},&block)
original_headers = options[:headers]
# set the HTTP Depth header
options[:headers] = {:depth => '0'}
@@ -707,109 +528,76 @@
end
#
# Performes an HTTP Proppatch request with the given _options_. If a
# _block_ is given, it will be passed the response from the HTTP server.
- # Returns the response from the HTTP server.
#
- # _options_ may contain the following keys:
- # <tt>:url</tt>:: The full URL to request.
- # <tt>:user</tt>:: The user to authenticate with when connecting to the
- # HTTP server.
- # <tt>:password</tt>:: The password to authenticate with when connecting
- # to the HTTP server.
- # <tt>:host</tt>:: The host the HTTP server is running on.
- # <tt>:port</tt>:: The port the HTTP server is running on. Defaults to
- # <tt>Net::HTTP.default_port</tt>.
- # <tt>:path</tt>:: The path to request from the HTTP server.
- # <tt>:proxy</tt>:: A Hash of proxy settings to use when connecting to
- # the HTTP server. Defaults to
- # <tt>Ronin::Network::HTTP.proxy</tt>.
- # <tt>:host</tt>:: The HTTP proxy host to connect to.
- # <tt>:port</tt>:: The HTTP proxy port to connect to.
- # Defaults to <tt>Ronin::Network::HTTP.default_proxy_port</tt>.
- # <tt>:user</tt>:: The user to authenticate with
- # when connecting to the HTTP proxy.
- # <tt>:password</tt>:: The password to authenticate with
- # when connecting to the HTTP
- # proxy.
- # <tt>:headers</tt>:: A Hash of the HTTP Headers to send with the HTTP
- # Proppatch request. May use Strings or Symbols for
- # the keys of the Hash.
+ # @param [Hash] options
+ # Additional options.
#
+ # @yield [response]
+ # If a block is given, it will be passed the response received from
+ # the request.
+ #
+ # @yieldparam [Net::HTTP::Response] response
+ # The HTTP response object.
+ #
+ # @return [Net::HTTP::Response]
+ # The response of the HTTP request.
+ #
+ # @see http_request
+ #
def Net.http_prop_patch(options={},&block)
resp = Net.http_request(options.merge(:method => :proppatch))
block.call(resp) if block
return resp
end
#
# Performes an HTTP Trace request with the given _options_. If a _block_
# is given, it will be passed the response from the HTTP server.
- # Returns the response from the HTTP server.
#
- # _options_ may contain the following keys:
- # <tt>:url</tt>:: The full URL to request.
- # <tt>:user</tt>:: The user to authenticate with when connecting to the
- # HTTP server.
- # <tt>:password</tt>:: The password to authenticate with when connecting
- # to the HTTP server.
- # <tt>:host</tt>:: The host the HTTP server is running on.
- # <tt>:port</tt>:: The port the HTTP server is running on. Defaults to
- # <tt>Net::HTTP.default_port</tt>.
- # <tt>:path</tt>:: The path to request from the HTTP server.
- # <tt>:proxy</tt>:: A Hash of proxy settings to use when connecting to
- # the HTTP server. Defaults to
- # <tt>Ronin::Network::HTTP.proxy</tt>.
- # <tt>:host</tt>:: The HTTP proxy host to connect to.
- # <tt>:port</tt>:: The HTTP proxy port to connect to.
- # Defaults to <tt>Ronin::Network::HTTP.default_proxy_port</tt>.
- # <tt>:user</tt>:: The user to authenticate with
- # when connecting to the HTTP proxy.
- # <tt>:password</tt>:: The password to authenticate with
- # when connecting to the HTTP
- # proxy.
- # <tt>:headers</tt>:: A Hash of the HTTP Headers to send with the HTTP
- # Trace request. May use Strings or Symbols for the
- # keys of the Hash.
+ # @param [Hash] options
+ # Additional options.
#
+ # @yield [response]
+ # If a block is given, it will be passed the response received from
+ # the request.
+ #
+ # @yieldparam [Net::HTTP::Response] response
+ # The HTTP response object.
+ #
+ # @return [Net::HTTP::Response]
+ # The response of the HTTP request.
+ #
+ # @see http_request
+ #
def Net.http_trace(options={},&block)
resp = Net.http_request(options.merge(:method => :trace))
block.call(resp) if block
return resp
end
#
# Performes an HTTP Unlock request with the given _options_. If a _block_
# is given, it will be passed the response from the HTTP server.
- # Returns the response from the HTTP server.
#
- # _options_ may contain the following keys:
- # <tt>:url</tt>:: The full URL to request.
- # <tt>:user</tt>:: The user to authenticate with when connecting to the
- # HTTP server.
- # <tt>:password</tt>:: The password to authenticate with when connecting
- # to the HTTP server.
- # <tt>:host</tt>:: The host the HTTP server is running on.
- # <tt>:port</tt>:: The port the HTTP server is running on. Defaults to
- # <tt>Net::HTTP.default_port</tt>.
- # <tt>:path</tt>:: The path to request from the HTTP server.
- # <tt>:proxy</tt>:: A Hash of proxy settings to use when connecting to
- # the HTTP server. Defaults to
- # <tt>Ronin::Network::HTTP.proxy</tt>.
- # <tt>:host</tt>:: The HTTP proxy host to connect to.
- # <tt>:port</tt>:: The HTTP proxy port to connect to.
- # Defaults to <tt>Ronin::Network::HTTP.default_proxy_port</tt>.
- # <tt>:user</tt>:: The user to authenticate with
- # when connecting to the HTTP proxy.
- # <tt>:password</tt>:: The password to authenticate with
- # when connecting to the HTTP
- # proxy.
- # <tt>:headers</tt>:: A Hash of the HTTP Headers to send with the HTTP
- # Unlock request. May use Strings or Symbols for the
- # keys of the Hash.
+ # @param [Hash] options
+ # Additional options.
+ #
+ # @yield [response]
+ # If a block is given, it will be passed the response received from
+ # the request.
+ #
+ # @yieldparam [Net::HTTP::Response] response
+ # The HTTP response object.
+ #
+ # @return [Net::HTTP::Response]
+ # The response of the HTTP request.
+ #
+ # @see http_request
#
def Net.http_unlock(options={},&block)
resp = Net.http_request(options.merge(:method => :unlock))
block.call(resp) if block