lib/ronin/network/extensions/http/net.rb in ronin-0.2.3 vs lib/ronin/network/extensions/http/net.rb in ronin-0.2.4
- old
+ new
@@ -30,18 +30,18 @@
#
# 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.
#
# _options_ may contain the following keys:
- # <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>: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.
@@ -51,136 +51,374 @@
# when connecting to the HTTP proxy.
# <tt>:password</tt>:: The password to authenticate with
# when connecting to the HTTP
# proxy.
#
- #
def Net.http_session(options={},&block)
+ options = Ronin::Network::HTTP.expand_options(options)
+
host = options[:host]
- port = (options[:port] || ::Net::HTTP.default_port)
+ port = options[:port]
+ proxy = options[:proxy]
- if options[:url]
- url = URI(options[:url].to_s)
+ sess = Net::HTTP::Proxy(proxy[:host],proxy[:port],proxy[:user],proxy[:pass]).start(host,port)
- host = url.host
- port = url.port
-
- options[:user] = url.user if url.user
- options[:password] = url.password if url.password
-
- if url.query
- options[:path] = "#{url.path}?#{url.query}"
+ if block
+ if block.arity == 2
+ block.call(sess,options)
else
- options[:path] = url.path
+ block.call(sess)
end
end
- proxy = (options[:proxy] || Ronin::Network::HTTP.proxy)
+ return sess
+ end
- if proxy
- proxy_host = proxy[:host]
- proxy_port = (proxy[:port] || Ronin::Network::HTTP.default_proxy_port)
- proxy_user = proxy[:user]
- proxy_pass = proxy[:password]
- 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.
+ #
+ # _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.
+ #
+ def Net.http_request(options={},&block)
+ resp = nil
- sess = Net::HTTP::Proxy(proxy_host,proxy_port,proxy_user,proxy_pass).start(host,port)
+ Net.http_session(options) do |http,expanded_options|
+ http_body = expanded_options.delete(:body)
- block.call(sess) if block
- return sess
+ req = Ronin::Network::HTTP.request(expanded_options)
+
+ if block
+ if block.arity == 2
+ block.call(req,expanded_options)
+ else
+ block.call(req)
+ end
+ end
+
+ resp = http.request(req,http_body)
+ end
+
+ return resp
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.
+ #
def Net.http_copy(options={},&block)
- Net.http_session(options) do |http|
- resp = http.request(Ronin::Network::HTTP.request(:copy,options))
+ resp = Net.http_request(options.merge(:method => :copy))
- block.call(resp) if block
- return resp
- end
+ 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.
+ #
def Net.http_delete(options={},&block)
- Net.http_session(options) do |http|
- req = Ronin::Network::HTTP.request(:delete,options)
- req['Depth'] = (options[:depth].to_s || 'Infinity')
+ original_headers = options[:headers]
- resp = http.request(req)
+ # set the HTTP Depth header
+ options[:headers] = {:depth => 'Infinity'}
- block.call(resp) if block
- return resp
+ if original_headers
+ options[:header].merge!(original_headers)
end
+
+ resp = Net.http_request(options.merge(:method => :delete))
+
+ 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 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.
+ #
def Net.http_get(options={},&block)
- Net.http_session(options) do |http|
- resp = http.request(Ronin::Network::HTTP.request(:get,options))
+ resp = Net.http_request(options.merge(:method => :get))
- block.call(resp) if block
- return resp
- end
+ 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.
+ #
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.
+ #
def Net.http_head(options={},&block)
- Net.http_session(options) do |http|
- resp = http.request(Ronin::Network::HTTP.request(:head,options))
+ resp = Net.http_request(options.merge(:method => :head))
- block.call(resp) if block
- return resp
- end
+ 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.
#
+ # _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.
+ #
+ #
def Net.http_ok?(options={})
Net.http_head(options).code == 200
end
#
- # Returns the HTTP Server header for the given _options_.
+ # 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.
+ #
# 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"
#
def Net.http_server(options={})
Net.http_head(options)['server']
end
#
- # Returns the HTTP X-Powered-By header for the given _options_.
+ # 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.
+ #
# Net.http_powered_by(:url => 'http://www.stalkdaily.com/')
# # => "PHP/5.2.9"
#
def Net.http_powered_by(options={})
resp = Net.http_head(options)
@@ -195,144 +433,387 @@
#
# 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.
+ #
def Net.http_lock(options={},&block)
- Net.http_session(options) do |http|
- resp = http.request(Ronin::Network::HTTP.request(:lock,options),options[:body])
+ resp = Net.http_request(options.merge(:method => :lock))
- block.call(resp) if block
- return resp
- end
+ 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.
+ #
def Net.http_mkcol(options={},&block)
- Net.http_session(options) do |http|
- resp = http.request(Ronin::Network::HTTP.request(:mkcol,options),options[:body])
+ resp = Net.http_request(options.merge(:method => :mkcol))
- block.call(resp) if block
- return resp
- end
+ 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.
+ #
def Net.http_move(options={},&block)
- Net.http_session(options) do |http|
- resp = http.request(Ronin::Network::HTTP.request(:move,options))
+ resp = Net.http_request(options.merge(:method => :move))
- block.call(resp) if block
- return resp
- end
+ 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.
+ #
def Net.http_options(options={},&block)
- Net.http_session(options) do |http|
- resp = http.request(Ronin::Network::HTTP.request(:options,options))
+ resp = Net.http_request(options.merge(:method => :options))
- block.call(resp) if block
- return resp
- 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 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.
+ #
def Net.http_post(options={},&block)
- Net.http_session(options) do |http|
+ options = options.merge(:method => :post)
+ post_data = options.delete(:post_data)
+
+ if options[:url]
url = URI(options[:url].to_s)
- post_data = (options[:post_data] || url.query_params)
+ post_data ||= url.query_params
+ end
- req = Ronin::Network::HTTP.request(:post,options)
- req.set_form_data(post_data)
-
- resp = http.request(req)
-
- block.call(resp) if block
- return resp
+ resp = Net.http_request(options) do |req,expanded_options|
+ req.set_form_data(post_data) if post_data
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.
+ #
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.
+ #
def Net.http_prop_find(options={},&block)
- Net.http_session(options) do |http|
- req = Ronin::Network::HTTP.request(:propfind,options)
- req['Depth'] = (options[:depth] || '0')
+ original_headers = options[:headers]
- resp = http.request(req,options[:body])
+ # set the HTTP Depth header
+ options[:headers] = {:depth => '0'}
- block.call(resp) if block
- return resp
+ if original_headers
+ options[:header].merge!(original_headers)
end
+
+ resp = Net.http_request(options.merge(:method => :propfind))
+
+ block.call(resp) if block
+ return resp
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.
+ #
def Net.http_prop_patch(options={},&block)
- Net.http_session(options) do |http|
- resp = http.request(Ronin::Network::HTTP.request(:proppatch,options),options[:body])
+ resp = Net.http_request(options.merge(:method => :proppatch))
- block.call(resp) if block
- return resp
- end
+ 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.
+ #
def Net.http_trace(options={},&block)
- Net.http_session(options) do |http|
- resp = http.request(Ronin::Network::HTTP.request(:trace,options))
+ resp = Net.http_request(options.merge(:method => :trace))
- block.call(resp) if block
- return resp
- end
+ 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.
+ #
def Net.http_unlock(options={},&block)
- Net.http_session(options) do |http|
- resp = http.request(Ronin::Network::HTTP.request(:unlock,options),options[:body])
+ resp = Net.http_request(options.merge(:method => :unlock))
- block.call(resp) if block
- return resp
- end
+ block.call(resp) if block
+ return resp
end
end