public
Description: A very fast & simple Ruby web server
Homepage: http://code.macournoyer.com/thin/
Clone URL: git://github.com/macournoyer/thin.git
Search Repo:
Alter response headers to output directly to a string.
macournoyer (author)
Sun Jan 20 20:36:32 -0800 2008
commit  a6b4cae783e97e083a63221b4fa4878c4b5f0198
tree    31b3ff142cdb9b36e1e7439b3f51bc9868269ae6
parent  d50a45e3eff6c028d9e298f49b2cd8167f8bb501
...
1
 
2
3
4
...
1
2
3
4
5
0
@@ -1,4 +1,5 @@
0
 == 0.5.5 Pony release
0
+ * Alter response headers to output directly to a string.
0
  * Improve specs stability.
0
  * Move request body to a Tempfile if too big (> 112 MB)
0
  * Remove useless check for max header size in Request (already done in the parser)
...
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
33
34
 
35
36
37
...
1
 
2
3
4
5
6
7
8
9
 
10
11
12
13
 
 
 
 
 
14
15
 
16
17
18
19
 
 
 
 
 
 
 
 
 
 
20
 
21
22
23
24
0
@@ -1,37 +1,24 @@
0
 module Thin
0
- # Acts like a Hash, but allows duplicated keys
0
+ # Store HTTP header name-value pairs direcly to a string
0
+ # and allow duplicated entries on some names.
0
   class Headers
0
     HEADER_FORMAT = "%s: %s\r\n".freeze
0
     ALLOWED_DUPLICATES = %w(Set-Cookie Set-Cookie2 Warning WWW-Authenticate).freeze
0
     
0
     def initialize
0
       @sent = {}
0
- @items = []
0
+ @out = ''
0
     end
0
     
0
     def []=(key, value)
0
- if @sent.has_key?(key) && !ALLOWED_DUPLICATES.include?(key)
0
- # If we don't allow duplicate for that field
0
- # we overwrite the one that is already there
0
- @items.assoc(key)[1] = value
0
- else
0
+ if !@sent[key] || ALLOWED_DUPLICATES.include?(key)
0
         @sent[key] = true
0
- @items << [key, value]
0
+ @out << HEADER_FORMAT % [key, value]
0
       end
0
     end
0
     
0
- def [](key)
0
- if item = @items.assoc(key)
0
- item[1]
0
- end
0
- end
0
-
0
- def size
0
- @items.size
0
- end
0
-
0
     def to_s
0
- @items.inject('') { |out, (name, value)| out << HEADER_FORMAT % [name, value] }
0
+ @out
0
     end
0
   end
0
 end
...
23
24
25
26
 
27
28
29
...
23
24
25
 
26
27
28
29
0
@@ -23,7 +23,7 @@
0
     File.exist?(@server.pid_file).should be_true
0
     @pid = @server.pid
0
 
0
- proc { sleep 0.1 while File.exist?(@server.pid_file) }.should take_less_then(2)
0
+ proc { sleep 0.1 while File.exist?(@server.pid_file) }.should take_less_then(5)
0
   end
0
   
0
   it 'should redirect stdio to a log file' do
...
9
10
11
12
 
13
14
15
16
17
18
19
20
21
22
23
24
25
 
26
27
28
...
9
10
11
 
12
13
14
15
16
17
 
18
 
 
 
 
 
 
19
20
21
22
0
@@ -9,20 +9,14 @@
0
     @headers['Set-Cookie'] = 'twice'
0
     @headers['Set-Cookie'] = 'is cooler the once'
0
     
0
- @headers.size.should == 2
0
+ @headers.to_s.should == "Set-Cookie: twice\r\nSet-Cookie: is cooler the once\r\n"
0
   end
0
   
0
   it 'should overwrite value on non duplicate fields' do
0
     @headers['Host'] = 'this is unique'
0
     @headers['Host'] = 'so is this'
0
- @headers['Host'] = 'so this will overwrite ^'
0
 
0
- @headers['Host'].should == 'so this will overwrite ^'
0
- end
0
-
0
- it 'should return first header value' do
0
- @headers['Set-Cookie'] = 'hi'
0
- @headers['Set-Cookie'].should == 'hi'
0
+ @headers.to_s.should == "Host: this is unique\r\n"
0
   end
0
   
0
   it 'should output to string' do
...
52
53
54
55
 
56
57
58
...
52
53
54
 
55
56
57
58
0
@@ -52,7 +52,7 @@
0
     out.should include("\r\n\r\n<html></html>")
0
   end
0
   
0
- it "should be faster then #{max_parsing_time = 0.00011} ms" do
0
+ it "should be faster then #{max_parsing_time = 0.00011} RubySecond" do
0
     @response.body << <<-EOS
0
 <html><head><title>Dir listing</title></head>
0
 <body><h1>Listing stuff</h1><ul>

Comments

    No one has commented yet.