Class: Mongrel::HeaderOut
- Inherits:
-
Object
- Object
- Mongrel::HeaderOut
- Defined in:
- lib/mongrel/header_out.rb
Overview
This class implements a simple way of constructing the HTTP headers dynamically via a Hash syntax. Think of it as a write-only Hash. Refer to HttpResponse for information on how this is used.
One consequence of this write-only nature is that you can write multiple headers by just doing them twice (which is sometimes needed in HTTP), but that the normal semantics for Hash (where doing an insert replaces) is not there.
Instance Attribute Summary collapse
-
#allowed_duplicates ⇒ Object
Returns the value of attribute allowed_duplicates.
-
#out ⇒ Object
readonly
Returns the value of attribute out.
Instance Method Summary collapse
-
#[]=(key, value) ⇒ Object
Simply writes “#key: #value” to an output buffer.
-
#initialize(out) ⇒ HeaderOut
constructor
A new instance of HeaderOut.
Constructor Details
#initialize(out) ⇒ HeaderOut
Returns a new instance of HeaderOut.
13 14 15 16 17 18 |
# File 'lib/mongrel/header_out.rb', line 13 def initialize(out) @sent = {} @allowed_duplicates = {"Set-Cookie" => true, "Set-Cookie2" => true, "Warning" => true, "WWW-Authenticate" => true} @out = out end |
Instance Attribute Details
#allowed_duplicates ⇒ Object
Returns the value of attribute allowed_duplicates.
11 12 13 |
# File 'lib/mongrel/header_out.rb', line 11 def allowed_duplicates @allowed_duplicates end |
#out ⇒ Object (readonly)
Returns the value of attribute out.
10 11 12 |
# File 'lib/mongrel/header_out.rb', line 10 def out @out end |
Instance Method Details
#[]=(key, value) ⇒ Object
Simply writes “#key: #value” to an output buffer.
21 22 23 24 25 26 |
# File 'lib/mongrel/header_out.rb', line 21 def[]=(key,value) if not @sent.has_key?(key) or @allowed_duplicates.has_key?(key) @sent[key] = true @out.write(Const::HEADER_FORMAT % [key, value]) end end |