lib/rev/http_client.rb in rev-0.2.0 vs lib/rev/http_client.rb in rev-0.2.1

- old
+ new

@@ -66,11 +66,11 @@ } end # Map all header keys to a downcased string version def munge_header_keys(head) - head.reduce({}) { |h, (k, v)| h[k.to_s.downcase] = v; h } + head.inject({}) { |h, (k, v)| h[k.to_s.downcase] = v; h } end # HTTP is kind of retarded that you have to specify # a Host header, but if you include port 80 then further # redirects will tack on the :80 which is annoying. @@ -96,19 +96,19 @@ def encode_field(k, v) FIELD_ENCODING % [k, v] end def encode_headers(head) - head.reduce('') do |result, (k, v)| + head.inject('') do |result, (key, value)| # Munge keys from foo-bar-baz to Foo-Bar-Baz - k = k.split('-').map(&:capitalize).join('-') - result << encode_field(k, v) + key = key.split('-').map { |k| k.capitalize }.join('-') + result << encode_field(key, value) end end def encode_cookies(cookies) - cookies.reduce('') { |result, (k, v)| result << encode_field('Cookie', encode_param(k, v)) } + cookies.inject('') { |result, (k, v)| result << encode_field('Cookie', encode_param(k, v)) } end end # HTTP client class implemented as a subclass of Rev::TCPSocket. Encodes # requests and allows streaming consumption of the response. Response is @@ -165,10 +165,10 @@ # # body: String # Specify the request body (you must encode it for now) # def request(method, path, options = {}) - raise ArgumentError, "invalid request path" unless path[0] == '/' + raise ArgumentError, "invalid request path" unless /^\// === path raise RuntimeError, "request already sent" if @requested @method, @path, @options = method, path, options @requested = true