class Hurley::Request
Constants
- CHUNKED
- DEFAULT_TYPE
- REQUIRED_BODY_VERBS
- SIZE_METHODS
Public Instance Methods
body_io()
click to toggle source
# File lib/hurley/client.rb, line 156 def body_io return unless body if body.respond_to?(:read) body elsif body StringIO.new(body) end end
inspect()
click to toggle source
# File lib/hurley/client.rb, line 170 def inspect "#<%s %s %s>" % [ self.class.name, verb.to_s.upcase, url.to_s, ] end
on_body(*statuses)
click to toggle source
# File lib/hurley/client.rb, line 166 def on_body(*statuses) @body_receiver = [statuses.empty? ? nil : statuses, Proc.new] end
options()
click to toggle source
# File lib/hurley/client.rb, line 144 def options self[:options] ||= RequestOptions.new end
prepare!()
click to toggle source
# File lib/hurley/client.rb, line 178 def prepare! prepare_basic_auth! if body prepare_body! else return unless REQUIRED_BODY_VERBS.include?(verb) end prepare_content_length! end
query_string()
click to toggle source
# File lib/hurley/client.rb, line 152 def query_string url.query.to_query_string end
ssl_options()
click to toggle source
# File lib/hurley/client.rb, line 148 def ssl_options self[:ssl_options] ||= SslOptions.new end
Private Instance Methods
body_receiver()
click to toggle source
# File lib/hurley/client.rb, line 226 def body_receiver @body_receiver ||= [nil, BodyReceiver.new] end
prepare_basic_auth!()
click to toggle source
# File lib/hurley/client.rb, line 192 def prepare_basic_auth! value = !header[:authorization] && url.basic_auth header[:authorization] = value if value end
prepare_body!()
click to toggle source
# File lib/hurley/client.rb, line 197 def prepare_body! ctype = nil case body when Query ctype, io = body.to_form self.body = io when Hash ctype, io = options.build_form(body) self.body = io end header[:content_type] ||= ctype || DEFAULT_TYPE end
prepare_content_length!()
click to toggle source
# File lib/hurley/client.rb, line 210 def prepare_content_length! if header.key?(:content_length) || header[:transfer_encoding] == CHUNKED return end if body if sizer = SIZE_METHODS.detect { |method| body.respond_to?(method) } header[:content_length] = body.send(sizer).to_i else header[:transfer_encoding] = CHUNKED end else header[:content_length] = 0 end end