Sha256: 6516d2b6f365283e0fa1f9a9e432a6bcca66a46f5ca7b8b3ba90cf09cb7ec131

Contents?: true

Size: 748 Bytes

Versions: 8

Compression:

Stored size: 748 Bytes

Contents

module Thin
  # Store HTTP header name-value pairs direcly to a string
  # and allow duplicated entries on some names.
  class Headers
    HEADER_FORMAT      = "%s: %s\r\n".freeze
    ALLOWED_DUPLICATES = %w(Set-Cookie Set-Cookie2 Warning WWW-Authenticate).freeze
    
    def initialize
      @sent = {}
      @out = []
    end
    
    # Add <tt>key: value</tt> pair to the headers.
    # Ignore if already sent and no duplicates are allowed
    # for this +key+.
    def []=(key, value)
      if !@sent.has_key?(key) || ALLOWED_DUPLICATES.include?(key)
        @sent[key] = true
        @out << HEADER_FORMAT % [key, value]
      end
    end
    
    def has_key?(key)
      @sent[key]
    end
    
    def to_s
      @out.join
    end
  end
end

Version data entries

8 entries across 8 versions & 2 rubygems

Version Path
grockit-thin-0.8.2 lib/thin/headers.rb
thin-0.7.0-x86-mswin32-60 lib/thin/headers.rb
thin-0.7.1 lib/thin/headers.rb
thin-0.8.0 lib/thin/headers.rb
thin-0.7.0 lib/thin/headers.rb
thin-0.7.1-x86-mswin32-60 lib/thin/headers.rb
thin-0.8.2 lib/thin/headers.rb
thin-0.8.1 lib/thin/headers.rb