1 require File.dirname(__FILE__) + '/spec_helper'
5 @response = Response.new
6 @response.headers['Content-Type'] = 'text/html'
7 @response.headers['Content-Length'] = '0'
11 it 'should output headers' do
12 @response.headers_output.should include("Content-Type: text/html", "Content-Length: 0", "Connection: close")
15 it 'should include server name header' do
16 @response.headers_output.should include("Server: thin")
19 it 'should output head' do
20 @response.head.should include("HTTP/1.1 200 OK", "Content-Type: text/html", "Content-Length: 0",
21 "Connection: close", "\r\n\r\n")
24 it 'should allow duplicates in headers' do
25 @response.headers['Set-Cookie'] = 'mium=7'
26 @response.headers['Set-Cookie'] = 'hi=there'
28 @response.head.should include("Set-Cookie: mium=7", "Set-Cookie: hi=there")
31 it 'should parse simple header values' do
36 @response.head.should include("Host: localhost")
39 it 'should parse multiline header values in several headers' do
41 'Set-Cookie' => "mium=7\nhi=there"
44 @response.head.should include("Set-Cookie: mium=7", "Set-Cookie: hi=there")
47 it 'should ignore nil headers' do
48 @response.headers = nil
49 @response.headers = { 'Host' => 'localhost' }
50 @response.headers = { 'Set-Cookie' => nil }
51 @response.head.should include('Host: localhost')
54 it 'should output body' do
55 @response.body = ['<html>', '</html>']
58 @response.each { |l| out << l }
59 out.should include("\r\n\r\n<html></html>")
62 it 'should output String body' do
63 @response.body = '<html></html>'
66 @response.each { |l| out << l }
67 out.should include("\r\n\r\n<html></html>")
70 it "should not be persistent by default" do
71 @response.should_not be_persistent
74 it "should not be persistent when no Content-Length" do
75 @response = Response.new
76 @response.headers['Content-Type'] = 'text/html'
80 @response.should_not be_persistent
83 it "should be persistent when the status code implies it should stay open" do
84 @response = Response.new
85 @response.status = 100
86 # "There are no required headers for this class of status code" -- HTTP spec 10.1
89 # Specifying it as persistent in the code is NOT required
90 # @response.persistent!
91 @response.should be_persistent
94 it "should be persistent when specified" do
96 @response.should be_persistent
99 it "should be closeable" do