module WebSocket::HTTP::Headers
Constants
- CR
- HEADER_LINE
- LF
- MAX_LINE_LENGTH
Attributes
headers[R]
Public Class Methods
new()
click to toggle source
# File lib/websocket/http/headers.rb, line 13 def initialize @buffer = [] @headers = {} @stage = 0 end
Public Instance Methods
complete?()
click to toggle source
# File lib/websocket/http/headers.rb, line 19 def complete? @stage == 2 end
error?()
click to toggle source
# File lib/websocket/http/headers.rb, line 23 def error? @stage == -1 end
parse(data)
click to toggle source
# File lib/websocket/http/headers.rb, line 27 def parse(data) data.each_byte do |byte| if byte == LF and @stage < 2 @buffer.pop if @buffer.last == CR if @buffer.empty? complete if @stage == 1 else result = case @stage when 0 then start_line(string_buffer) when 1 then header_line(string_buffer) end if result @stage = 1 else error end end @buffer = [] else @buffer << byte if @stage >= 0 error if @stage < 2 and @buffer.size > MAX_LINE_LENGTH end end @env['rack.input'] = StringIO.new(string_buffer) if @env end
Private Instance Methods
complete()
click to toggle source
# File lib/websocket/http/headers.rb, line 56 def complete @stage = 2 end
error()
click to toggle source
# File lib/websocket/http/headers.rb, line 60 def error @stage = -1 end
header_line(line)
click to toggle source
# File lib/websocket/http/headers.rb, line 64 def header_line(line) return false unless parsed = line.scan(HEADER_LINE).first @headers[HTTP.normalize_header(parsed[0])] = parsed[1].strip true end
string_buffer()
click to toggle source
# File lib/websocket/http/headers.rb, line 70 def string_buffer @buffer.pack('C*') end