[Groonga-commit] ranguba/groonga-client at ce9563e [master] http thread: support "bad request" response

アーカイブの一覧に戻る

Kouhei Sutou null+****@clear*****
Thu May 8 16:19:15 JST 2014


Kouhei Sutou	2014-05-08 16:19:15 +0900 (Thu, 08 May 2014)

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

  Message:
    http thread: support "bad request" response

  Modified files:
    lib/groonga/client/protocol/http/thread.rb

  Modified: lib/groonga/client/protocol/http/thread.rb (+12 -5)
===================================================================
--- lib/groonga/client/protocol/http/thread.rb    2014-03-28 22:21:42 +0900 (363d8ad)
+++ lib/groonga/client/protocol/http/thread.rb    2014-05-08 16:19:15 +0900 (326dae3)
@@ -15,7 +15,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 "open-uri"
+require "net/http"
 
 require "groonga/client/empty-request"
 require "groonga/client/protocol/error"
@@ -45,11 +45,18 @@ module Groonga
             url = "http://#{@host}:#{@port}#{command.to_uri_format}"
             thread = ::Thread.new do
               begin
-                open(url) do |response|
-                  body = response.read
-                  yield(body)
+                Net::HTTP.start(@host, @port) do |http|
+                  response = http.get(command.to_uri_format)
+                  case response
+                  when Net::HTTPSuccess, Net::HTTPBadRequest
+                    yield(response.body)
+                  else
+                    message =
+                      "#{response.code} #{response.message}: #{response.body}"
+                    raise Error.new(message)
+                  end
                 end
-              rescue OpenURI::HTTPError, Timeout::Error
+              rescue SystemCallError, Timeout::Error
                 raise WrappedError.new($!)
               end
             end
-------------- next part --------------
HTML����������������������������...
ダウンロード 



More information about the Groonga-commit mailing list
アーカイブの一覧に戻る