File: test_post_io.rb

package info (click to toggle)
ruby1.8 1.8.7.302-2squeeze2
  • links: PTS, VCS
  • area: main
  • in suites: squeeze
  • size: 26,640 kB
  • ctags: 38,616
  • sloc: ruby: 245,002; ansic: 144,156; yacc: 5,890; sh: 2,677; lisp: 1,626; tcl: 949; makefile: 358; sed: 129; xml: 122; awk: 36; cpp: 28; asm: 25; perl: 18; python: 6
file content (32 lines) | stat: -rw-r--r-- 851 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
require 'test/unit'
require 'net/http'
require 'stringio'

class HTTPPostIOTest < Test::Unit::TestCase
  def test_post_io_chunk_size
    t = nil
    TCPServer.open("127.0.0.1", 0) {|serv|
      _, port, _, _ = serv.addr
      t = Thread.new {
        begin
          req = Net::HTTP::Post.new("/test.cgi")
          req['Transfer-Encoding'] = 'chunked'
          req.body_stream = StringIO.new("\0" * (16 * 1024 + 1))
          http = Net::HTTP.new("127.0.0.1", port)
          res = http.start { |http| http.request(req) }
        rescue EOFError, Errno::EPIPE
        end
      }
      sock = serv.accept
      begin
        assert_match(/chunked/, sock.gets("\r\n\r\n"))
        chunk_header = sock.gets.chomp
        assert_equal(16 * 1024, chunk_header.to_i(16))
      ensure
        sock.close
      end
    }
  ensure
    t.join if t
  end
end