Sean Cribbs avatar Sean Cribbs committed dbc545d

Refactor RequestHeaders so it can be used by multiple backends.

Comments (0)

Files changed (2)

riak-client/lib/riak/client/curb_backend.rb

       private
       def perform(method, uri, headers, expect, data=nil)
         # Setup
-        curl.headers = create_request_headers(headers)
+        curl.headers = RequestHeaders.new(headers).to_a
         curl.url = uri.to_s
         response_headers.initialize_http_header(nil)
         if block_given?
           # Hacks around limitations in curb's PUT semantics
           _headers, curl.headers = curl.headers, {}
           curl.put_data = data
-          curl.headers = create_request_headers(curl.headers) + _headers
+          curl.headers = RequestHeaders.new(curl.headers).to_a + _headers
           curl.http("PUT")
         else
           curl.send("http_#{method}")

riak-client/lib/riak/client/http_backend.rb

       end
 
       private
-      def create_request_headers(hash)
-        h = Riak::Util::Headers.new
-        hash.each {|k,v| h.add_field(k,v) }
-        [].tap do |arr|
-          h.each_capitalized do |k,v|
-            arr << "#{k}: #{v}"
+      def response_headers
+        Thread.current[:response_headers] ||= Riak::Util::Headers.new
+      end
+
+      # @private
+      class RequestHeaders < Riak::Util::Headers
+        alias each each_capitalized
+
+        def initialize(hash)
+          initialize_http_header(hash)
+        end
+
+        def to_a
+          [].tap do |arr|
+            each_capitalized do |k,v|
+              arr << "#{k}: #{v}"
+            end
           end
         end
       end
 
-      def response_headers
-        Thread.current[:response_headers] ||= Riak::Util::Headers.new
-      end
     end
   end
 end
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.