[Groonga-commit] ranguba/groonga-client at a501edd [master] http: set user-agent

Back to archive index

Kouhei Sutou null+****@clear*****
Tue Sep 30 19:43:29 JST 2014


Kouhei Sutou	2014-09-30 19:43:29 +0900 (Tue, 30 Sep 2014)

  New Revision: a501edd89aab57f82651b905e88d85d97c061297
  https://github.com/ranguba/groonga-client/commit/a501edd89aab57f82651b905e88d85d97c061297

  Message:
    http: set user-agent
    
    "groonga-client/#{VERSION}" is used.

  Modified files:
    lib/groonga/client/protocol/http.rb
    lib/groonga/client/protocol/http/coolio.rb
    lib/groonga/client/protocol/http/synchronous.rb

  Modified: lib/groonga/client/protocol/http.rb (+8 -1)
===================================================================
--- lib/groonga/client/protocol/http.rb    2014-09-30 19:38:05 +0900 (3c1156b)
+++ lib/groonga/client/protocol/http.rb    2014-09-30 19:43:29 +0900 (1b857ad)
@@ -17,6 +17,7 @@
 # License along with this library; if not, write to the Free Software
 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
 
+require "groonga/client/version"
 require "groonga/client/protocol/error"
 
 module Groonga
@@ -34,7 +35,7 @@ module Groonga
         def initialize(options)
           @host = options[:host] || "127.0.0.1"
           @port = options[:port] || 10041
-          @options = options
+          @options = default_options.merge(options)
           @backend = create_backend
         end
 
@@ -51,6 +52,12 @@ module Groonga
         end
 
         private
+        def default_options
+          {
+            :user_agent => "groonga-client/#{VERSION}",
+          }
+        end
+
         def create_backend
           backend = @options[:backend] || :thread
 

  Modified: lib/groonga/client/protocol/http/coolio.rb (+1 -0)
===================================================================
--- lib/groonga/client/protocol/http/coolio.rb    2014-09-30 19:38:05 +0900 (dede62c)
+++ lib/groonga/client/protocol/http/coolio.rb    2014-09-30 19:43:29 +0900 (71dda8d)
@@ -81,6 +81,7 @@ module Groonga
               options = {
                 :head => {
                   "content-type" => "application/json",
+                  "user-agent"   => @options[:user_agent],
                 },
                 :body => raw_values,
               }

  Modified: lib/groonga/client/protocol/http/synchronous.rb (+9 -2)
===================================================================
--- lib/groonga/client/protocol/http/synchronous.rb    2014-09-30 19:38:05 +0900 (95d6e22)
+++ lib/groonga/client/protocol/http/synchronous.rb    2014-09-30 19:43:29 +0900 (6f12c48)
@@ -17,6 +17,7 @@
 
 require "net/http"
 
+require "groonga/client/version"
 require "groonga/client/empty-request"
 require "groonga/client/protocol/error"
 
@@ -94,14 +95,20 @@ module Groonga
               command[:values] = nil
               path = command.to_uri_format
               command[:values] = raw_values
-              request = Net::HTTP::Post.new(path)
+              request = Net::HTTP::Post.new(path, headers)
               request.content_type = "application/json"
               request.body = raw_values
               http.request(request)
             else
-              http.get(command.to_uri_format)
+              http.get(command.to_uri_format, headers)
             end
           end
+
+          def headers
+            {
+              "user-agent" => @options[:user_agent],
+            }
+          end
         end
       end
     end
-------------- next part --------------
HTML����������������������������...
Télécharger 



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