lib/zephyr.rb in zephyr-1.0.1 vs lib/zephyr.rb in zephyr-1.0.2

- old
+ new

@@ -13,24 +13,26 @@ # See the License for the specific language governing permissions and # limitations under the License. # Splits headers into < 8KB chunks # @private -module Net::HTTPHeader - def each_capitalized - # 1.9 check - respond_to?(:enum_for) and (block_given? or return enum_for(__method__)) - @header.each do |k,v| - base_length = "#{k}: \r\n".length - values = v.map { |i| i.to_s.split(', ') }.flatten - while !values.empty? - current_line = "" - while values.first && current_line.length + base_length + values.first.length + 2 < 8192 - val = values.shift.strip - current_line += current_line.empty? ? val : ", #{val}" +module Net + module HTTPHeader + def each_capitalized + # 1.9 check + respond_to?(:enum_for) and (block_given? or return enum_for(__method__)) + @header.each do |k,v| + base_length = "#{k}: \r\n".length + values = v.map { |i| i.to_s.split(', ') }.flatten + while !values.empty? + current_line = "" + while values.first && current_line.length + base_length + values.first.length + 2 < 8192 + val = values.shift.strip + current_line += current_line.empty? ? val : ", #{val}" + end + yield capitalize(k), current_line end - yield capitalize(k), current_line end end end end @@ -62,12 +64,10 @@ headers = default_headers.merge(headers) verify_path!(path_components) perform(:head, path_components, headers, expected_statuses, timeout) end - Workfeed::Timer.time_method self, :head, 'http_head' - # Performs a GET request to the specified resource. # # A request to /users/#{@user.id}/things?q=woof with an Accept header of # "text/plain" which is expecting a 200 OK within 50ms # @@ -81,12 +81,10 @@ headers = default_headers.merge(headers) verify_path!(path_components) perform(:get, path_components, headers, expected_statuses, timeout) end - Workfeed::Timer.time_method self, :get, 'http_get' - # The same thing as #get, but decodes the response entity as JSON (if it's # application/json) and adds it under the :json key in the returned hash. def get_json(expected_statuses, timeout, path_components, headers={}, yajl_opts={}) response = get(expected_statuses, timeout, path_components, headers) @@ -116,12 +114,10 @@ headers = default_headers.merge(headers) verify_path_and_entity!(path_components, entity) perform(:put, path_components, headers, expected_statuses, timeout, entity) end - Workfeed::Timer.time_method self, :put, 'http_put' - # The same thing as #put, but encodes the entity as JSON and specifies # "application/json" as the request entity content type. def put_json(expected_statuses, timeout, path_components, entity, headers={}) put(expected_statuses, timeout, path_components, Yajl::Encoder.encode(entity), headers.merge("Content-Type" => "application/json")) end @@ -142,12 +138,10 @@ headers = default_headers.merge(headers) verify_path_and_entity!(path_components, entity) perform(:post, path_components, headers, expected_statuses, timeout, entity) end - Workfeed::Timer.time_method self, :post, 'http_post' - # The same thing as #post, but encodes the entity as JSON and specifies # "application/json" as the request entity content type. def post_json(expected_statuses, timeout, path_components, entity, headers={}) post( expected_statuses, @@ -172,11 +166,9 @@ def delete(expected_statuses, timeout, path_components, headers={}) headers = default_headers.merge(headers) verify_path!(path_components) perform(:delete, path_components, headers, expected_statuses, timeout) end - - Workfeed::Timer.time_method self, :delete, 'http_delete' # Creates a URI object, combining the root_uri passed on initialization # with the given parts. # # Example: