Sha256: d2da07aaf5ec783bd4a7a8ed31a9ed0c254981f290239221a380fd138946cbd4

Contents?: true

Size: 1.01 KB

Versions: 15

Compression:

Stored size: 1.01 KB

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)
      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
    
    def has_key?(key)
      @sent[key.downcase]
    end
    
    def to_s
      @out.join
    end
  end
end

Version data entries

15 entries across 15 versions & 5 rubygems

Version Path
thin-1.8.0 lib/thin/headers.rb
gross-1.7.2 lib/thin/headers.rb
thin-1.7.2 lib/thin/headers.rb
thin-1.7.1 lib/thin/headers.rb
arcabouco-0.2.13 vendor/bundle/gems/thin-1.7.0/lib/thin/headers.rb
thin-1.7.0 lib/thin/headers.rb
ish_lib_manager-0.0.1 test/dummy/vendor/bundle/ruby/2.3.0/gems/thin-1.6.4/lib/thin/headers.rb
thin-1.6.4 lib/thin/headers.rb
swee-0.0.1 lib/swee/thin/headers.rb
thin-1.6.3 lib/thin/headers.rb
thin-1.6.2 lib/thin/headers.rb
thin-1.6.1 lib/thin/headers.rb
thin-1.6.0 lib/thin/headers.rb
thin-1.5.1 lib/thin/headers.rb
thin-1.5.0 lib/thin/headers.rb