Kouhei Sutou
null+****@clear*****
Tue Sep 30 19:18:50 JST 2014
Kouhei Sutou 2014-09-30 19:18:50 +0900 (Tue, 30 Sep 2014) New Revision: f98d2fab8b673b6d5c39126c5806ab747dac192a https://github.com/ranguba/groonga-client/commit/f98d2fab8b673b6d5c39126c5806ab747dac192a Message: http thread: use POST for load command GitHub: #2 Modified files: lib/groonga/client/protocol/http/thread.rb test/test-client.rb Modified: lib/groonga/client/protocol/http/thread.rb (+17 -1) =================================================================== --- lib/groonga/client/protocol/http/thread.rb 2014-09-30 18:36:33 +0900 (d4cb753) +++ lib/groonga/client/protocol/http/thread.rb 2014-09-30 19:18:50 +0900 (4a0a22c) @@ -45,7 +45,7 @@ module Groonga thread = ::Thread.new do begin Net::HTTP.start(@host, @port) do |http| - response = http.get(command.to_uri_format) + response = send_request(http, command) case response when Net::HTTPSuccess, Net::HTTPBadRequest yield(response.body) @@ -98,6 +98,22 @@ module Groonga EmptyRequest.new end end + + private + def send_request(http, command) + if command.name == "load" + raw_values = command[:values] + command[:values] = nil + path = command.to_uri_format + command[:values] = raw_values + request = Net::HTTP::Post.new(path) + request.content_type = "application/json" + request.body = raw_values + http.request(request) + else + http.get(command.to_uri_format) + end + end end end end Modified: test/test-client.rb (+23 -0) =================================================================== --- test/test-client.rb 2014-09-30 18:36:33 +0900 (492a60c) +++ test/test-client.rb 2014-09-30 19:18:50 +0900 (4bdb6a6) @@ -223,6 +223,20 @@ JSON end end + module LoadTests + def test_load + values = [ + {"content" => "1st content"}, + {"content" => "2nd content"}, + {"content" => "3rd content"}, + ] + stub_response("[#{values.size}]") + response = client.load(:table => "Memos", + :values => JSON.generate(values)) + assert_equal([values.size], response.body) + end + end + module Tests include Utils include Assertions @@ -231,6 +245,7 @@ JSON include ColumnsTests include ParametersTests include OpenTests + include LoadTests end class TestGQTP < self @@ -281,9 +296,17 @@ JSON @port =****@serve*****[1] @protocol = :http + @actual_method = nil + @actual_path = nil + @response_body = nil @thread = Thread.new do client =****@serve***** + first_line = client.gets + if /\A([\w]+) ([^ ]+) HTTP/ =~ first_line + @actual_method = $1 + @actual_path = $2 + end @server.close status = 0 start = Time.now.to_f -------------- next part -------------- HTML����������������������������... Descargar