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: value
pair 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 |
# File 'lib/thin/headers.rb', line 16 def []=(key, value) if !@sent.has_key?(key) || ALLOWED_DUPLICATES.include?(key) @sent[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
31 32 33 |
# File 'lib/thin/headers.rb', line 31 def has_key?(key) @sent[key] end |
#to_s ⇒ Object
35 36 37 |
# File 'lib/thin/headers.rb', line 35 def to_s @out.join end |