Sha256: 5962d1231c6f1f41ba1ac4b861577b2e31edcea92572d12251aae2862ff349ce

Contents?: true

Size: 1 KB

Versions: 4

Compression:

Stored size: 1 KB

Contents

$:.unshift File.join(File.dirname(__FILE__), "..", "lib")

require 'test/unit'
require 'rubygems'
require 'mechanize'
require 'test_includes'

class TestKeepAlive < Test::Unit::TestCase
  include TestMethods

  def setup
    @agent = WWW::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

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
mechanize-0.6.10 test/tc_keep_alive.rb
mechanize-0.6.11 test/tc_keep_alive.rb
mechanize-0.6.8 test/tc_keep_alive.rb
mechanize-0.6.9 test/tc_keep_alive.rb