From: Minero Aoki Date: 2001-02-23T16:21:45+09:00 Subject: [ruby-list:28176] Re: net/http で、 HTTPBadResponse あおきです。 In mail "[ruby-list:28175] Re: net/http で、 HTTPBadResponse" Beyond wrote: > Beyondです。 > 前回のパッチと、今回のパッチをあてることで、「www.yahoo.co.jp」(HTTP/1.0) > については大丈夫になりました。 > > しかし、色々試したところ「www.watch.impress.co.jp」(HTTP/1.1)だと、同 > 様の例外が発生します。サーバーに Microsoft-IIS を使っているようなのです > が、IIS が悪いんでしょうか(^^;。 はい、たぶん (^^;; HEAD に対して本体を返してきていて、かつ HTTP/1.1 リプライですね。 これが本当にサーバのせいならまだいいですけど、CGI が出してたり するとどうにも判断しようがないです。 とりあえず本体がない(はず)の時は全面的に Keep-Alive をあきらめる ようにして対応してみました。impress と yahoo はいけるはずです。 いろいろやってるのでパッチがあたらないかもしれませんが、その場合は CVS から取るか、RAA に 1.1.34 が出るまで待ってください。 ------------------------------------------------------------------- 青木峰郎 --- http.rb 2001/02/23 04:25:41 1.10.2.55 +++ http.rb 2001/02/23 07:21:23 @@ -445,7 +445,7 @@ header = procheader( u_header ) recv = err = nil - connecting( header ) { + connecting( header, body_exist ) { recv = HTTPResponseReceiver.new( @command, body_exist ) yield header begin @@ -455,30 +455,33 @@ end recv.terminate - recv.response + recv } raise err if err recv.response end - def connecting( header ) + def connecting( header, body_exist ) if not @socket then header['Connection'] = 'close' start elsif @socket.closed? then @socket.reopen end - if @seems_1_0 then + if not body_exist or @seems_1_0 then header['Connection'] = 'close' end - resp = yield + recv = yield if @command.http_version == '1.0' then @seems_1_0 = true end - unless keep_alive? resp then + if not recv.body then + # close connection always (for corrupted servers) + @socket.close + elsif not keep_alive? header, recv.response then if @socket.closed? then @seems_1_0 = true else @@ -487,9 +490,10 @@ end end - def keep_alive?( resp ) + def keep_alive?( header, resp ) /close/i === resp['connection'].to_s and return false /close/i === resp['proxy-connection'].to_s and return false + /close/i === header['connection'].to_s and return false @seems_1_0 and return false /keep-alive/i === resp['connection'].to_s and return true