lib/rufus/verbs/endpoint.rb in rufus-verbs-0.8 vs lib/rufus/verbs/endpoint.rb in rufus-verbs-0.9
- old
+ new
@@ -38,10 +38,11 @@
require 'zlib'
require 'rufus/verbs/version'
require 'rufus/verbs/cookies'
require 'rufus/verbs/digest'
+require 'rufus/verbs/verbose'
module Rufus
module Verbs
@@ -67,10 +68,11 @@
#
class EndPoint
include CookieMixin
include DigestAuthMixin
+ include VerboseMixin
#
# The endpoint initialization opts (Hash instance)
#
attr_reader :opts
@@ -161,24 +163,35 @@
mention_cookies(req, opts)
# if the :cookies option is disabled (the default)
# will have no effect
+ vlog_request opts, req
+
return req if o(opts, :dry_run) == true
# trigger request
http = prepare_http opts
+ vlog_http opts, http
+
res = nil
http.start do
res = http.request req
end
# handle response
+ class << res
+ attr_accessor :request
+ end
+ res.request = req
+
+ vlog_response opts, res
+
register_cookies res, opts
# if the :cookies option is disabled (the default)
# will have no effect
return res if o(opts, :raw_response)
@@ -244,11 +257,11 @@
[ opts[:scheme] || 'http',
opts[:host],
opts[:port] || 80,
opts[:path] || '/',
- opts[:query] || opts[:params] || {} ]
+ opts[:query] || opts[:params] ]
elsif u
u = URI.parse u.to_s unless u.is_a?(URI)
[ u.scheme,
@@ -263,12 +276,17 @@
opts[:scheme] = r[0] || @opts[:scheme]
opts[:host] = r[1] || @opts[:host]
opts[:port] = r[2] || @opts[:port]
opts[:path] = r[3] || @opts[:path]
- opts[:query] = r[4] || @opts[:query] || @opts[:params]
+ opts[:query] =
+ r[4] ||
+ opts[:params] || opts[:query] ||
+ @opts[:query] || @opts[:params] ||
+ {}
+
opts.delete :path if opts[:path] == ""
opts[:c_uri] = [
opts[:scheme],
opts[:host],
@@ -430,10 +448,12 @@
path = "/#{b}" if b
path += "/#{r}" if r
path += "/#{i}" if i
end
- query = opts[:query]
+ path = path[1..-1] if path[0..1] == '//'
+
+ query = opts[:query] || opts[:params]
return path if not query or query.size < 1
path + '?' + h_to_query(query, opts)
end