File: test_keep_alive.rb

package info (click to toggle)
libwww-mechanize-ruby 1.0.0-1
  • links: PTS, VCS
  • area: main
  • in suites: squeeze
  • size: 956 kB
  • ctags: 883
  • sloc: ruby: 6,621; makefile: 4
file content (31 lines) | stat: -rw-r--r-- 873 bytes parent folder | download
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
require "helper"

class TestKeepAlive < Test::Unit::TestCase
  def setup
    @agent = Mechanize.new
  end

  def test_keep_alive
    page = @agent.get('http://localhost/http_headers')
    headers = {}
    page.body.split(/[\r\n]+/).each do |header|
      headers.[]=(*header.chomp.split(/\|/))
    end
    assert(headers.has_key?('connection'))
    assert_equal('keep-alive', headers['connection'])
    assert(headers.has_key?('keep-alive'))
    assert_equal('300', headers['keep-alive'])
  end

  def test_close_connection
    @agent.keep_alive = false
    page = @agent.get('http://localhost/http_headers')
    headers = {}
    page.body.split(/[\r\n]+/).each do |header|
      headers.[]=(*header.chomp.split(/\|/))
    end
    assert(headers.has_key?('connection'))
    assert_equal('close', headers['connection'])
    assert(!headers.has_key?('keep-alive'))
  end
end