Changeset 786

Show
Ignore:
Timestamp:
09/16/08 03:33:27 (10 months ago)
Author:
francis
Message:

supported optional version string in HTTP client.

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/ChangeLog

    r785 r786  
    13613615Sep08: Added attach/detach, contributed by Aman Gupta (tmm1) and Riham Aldakkak, 
    137137        to support working with file descriptors not created in the reactor. 
    138  
     13816Sep08: Added an optional version string to the HTTP client. This is a hack 
     139        that allows a client to specify a version 1.0 request, which 
     140        keeps the server from sending a chunked response. The right way to 
     141        solve this, of course, is to support chunked responses. 
  • trunk/lib/protocols/httpclient.rb

    r769 r786  
    110110    end 
    111111 
     112    version = args[:version] || "1.1" 
     113 
    112114    # Allow an override for the host header if it's not the connect-string. 
    113115    host = args[:host_header] || args[:host] || "_" 
     
    123125    # TODO: We ASSUME the caller wants to send a 1.1 request. May not be a good assumption. 
    124126    req = [ 
    125       "#{verb} #{request}#{qs} HTTP/1.1", 
     127      "#{verb} #{request}#{qs} HTTP/#{version}", 
    126128      "Host: #{host}:#{port}", 
    127129      "User-agent: Ruby EventMachine", 
     
    166168        @status = nil 
    167169        @read_state = :header 
     170        @connection_close = nil 
    168171      when :header 
    169172        ary = data.split( /\r?\n/m, 2 ) 
     
    171174          data = ary.last 
    172175          if ary.first == "" 
    173               if @content_length and @content_length > 0 
     176              if (@content_length and @content_length > 0) || @connection_close 
    174177                  @read_state = :content 
    175178              else 
     
    189192              # content-length headers.) 
    190193              @content_length ||= $'.to_i 
     194            elsif ary.first =~ /\Aconnection:\s*close/i 
     195              @connection_close = true 
    191196            end 
    192197          end 
  • trunk/tests/test_httpclient.rb

    r668 r786  
    112112      assert ok 
    113113  end 
     114 
    114115 
    115116  #--------------------------------------- 
     
    190191  end 
    191192 
     193 
     194 
     195  # We can tell the client to send an HTTP/1.0 request (default is 1.1). 
     196  # This is useful for suppressing chunked responses until those are working. 
     197  def test_version_1_0 
     198    ok = false 
     199    EM.run { 
     200      c = EM::P::HttpClient.request :host => "www.bayshorenetworks.com", 
     201        :port => 80, 
     202        :version => "1.0" 
     203      c.callback {|result| 
     204        ok = true; 
     205        EventMachine.stop 
     206      } 
     207      c.errback {EventMachine.stop} 
     208    } 
     209    assert ok 
     210  end 
     211 
     212 
    192213end 
    193214