Class: Thin::Headers
- Inherits:
-
Object
- Object
- Thin::Headers
- Defined in:
- lib/thin/headers.rb
Overview
Store HTTP header name-value pairs direcly to a string and allow duplicated entries on some names.
Constant Summary collapse
- HEADER_FORMAT =
"%s: %s\r\n".freeze
- ALLOWED_DUPLICATES =
%w(set-cookie set-cookie2 warning www-authenticate).freeze
Instance Method Summary collapse
-
#[]=(key, value) ⇒ Object
Add
key: valuepair to the headers. - #has_key?(key) ⇒ Boolean
-
#initialize ⇒ Headers
constructor
A new instance of Headers.
- #to_s ⇒ Object
Constructor Details
#initialize ⇒ Headers
Returns a new instance of Headers.
8 9 10 11 |
# File 'lib/thin/headers.rb', line 8 def initialize @sent = {} @out = [] end |
Instance Method Details
#[]=(key, value) ⇒ Object
Add key: value pair to the headers. Ignore if already sent and no duplicates are allowed for this key.
16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 |
# File 'lib/thin/headers.rb', line 16 def []=(key, value) downcase_key = key.downcase if !@sent.has_key?(downcase_key) || ALLOWED_DUPLICATES.include?(downcase_key) @sent[downcase_key] = true value = case value when Time value.httpdate when NilClass return else value.to_s end @out << HEADER_FORMAT % [key, value] end end |
#has_key?(key) ⇒ Boolean
32 33 34 |
# File 'lib/thin/headers.rb', line 32 def has_key?(key) @sent[key.downcase] end |
#to_s ⇒ Object
36 37 38 |
# File 'lib/thin/headers.rb', line 36 def to_s @out.join end |