Sha256: d96a861fb26943bef4d6c46419b20ebadeb30d24e6fe2a4e294691212c23d869

Contents?: true

Size: 864 Bytes

Versions: 23

Compression:

Stored size: 864 Bytes

Contents

module WebSocket
  class Driver

    class Headers
      ALLOWED_DUPLICATES = %w[set-cookie set-cookie2 warning www-authenticate]

      def initialize(received = {})
        @raw = received
        clear

        @received = {}
        @raw.each { |k,v| @received[HTTP.normalize_header(k)] = v }
      end

      def clear
        @sent  = Set.new
        @lines = []
      end

      def [](name)
        @received[HTTP.normalize_header(name)]
      end

      def []=(name, value)
        return if value.nil?
        key = HTTP.normalize_header(name)
        return unless @sent.add?(key) or ALLOWED_DUPLICATES.include?(key)
        @lines << "#{ name.strip }: #{ value.to_s.strip }\r\n"
      end

      def inspect
        @raw.inspect
      end

      def to_h
        @raw.dup
      end

      def to_s
        @lines.join('')
      end
    end

  end
end

Version data entries

23 entries across 23 versions & 8 rubygems

Version Path
websocket-driver-0.7.3 lib/websocket/driver/headers.rb
websocket-driver-0.7.2-java lib/websocket/driver/headers.rb
websocket-driver-0.7.2 lib/websocket/driver/headers.rb