[Groonga-commit] droonga/droonga-client-ruby at e509896 [master] http: extract request creation code

Back to archive index

Kouhei Sutou null+****@clear*****
Mon Jan 20 16:32:16 JST 2014


Kouhei Sutou	2014-01-20 16:32:16 +0900 (Mon, 20 Jan 2014)

  New Revision: e50989650d964ba6d326fdc99a6d2861e2e51eba
  https://github.com/droonga/droonga-client-ruby/commit/e50989650d964ba6d326fdc99a6d2861e2e51eba

  Message:
    http: extract request creation code

  Modified files:
    lib/droonga/client/connection/http.rb

  Modified: lib/droonga/client/connection/http.rb (+16 -12)
===================================================================
--- lib/droonga/client/connection/http.rb    2014-01-20 16:31:23 +0900 (cbc03e3)
+++ lib/droonga/client/connection/http.rb    2014-01-20 16:32:16 +0900 (f7a1154)
@@ -124,19 +124,8 @@ module Droonga
           read_timeout = options[:read_timeout] if options.key?(:read_timeout)
           http.open_timeout = open_timeout
           http.read_timeout = read_timeout
+          request = build_request(message)
           http.start do
-            request = nil
-            method = http_method(message)
-            case method
-            when "POST"
-              request = Net::HTTP::Post.new(build_path(message), build_headers(message))
-              request.body = JSON.generate(message["body"])
-            when "GET"
-              request = Net::HTTP::Get.new(build_path(message), build_headers(message))
-            else
-              raise ArgumentError.new("Unsupport HTTP Method: #{method}, " +
-                                        "in the message: #{JSON.generate(message)}")
-            end
             http.request(request) do |response|
               yield(response)
             end
@@ -150,6 +139,21 @@ module Droonga
         end
 
         private
+        def build_request(message)
+          request = nil
+          method = http_method(message)
+          case method
+          when "POST"
+            request = Net::HTTP::Post.new(build_path(message), build_headers(message))
+            request.body = JSON.generate(message["body"])
+          when "GET"
+            request = Net::HTTP::Get.new(build_path(message), build_headers(message))
+          else
+            raise ArgumentError.new("Unsupport HTTP Method: #{method}, " +
+                                      "in the message: #{JSON.generate(message)}")
+          end
+        end
+
         def build_path(message)
           type = message["type"]
           body = message["body"] || {}
-------------- next part --------------
HTML����������������������������...
Download 



More information about the Groonga-commit mailing list
Back to archive index