Class: LibWebSocket::Cookie::Request

Inherits:
LibWebSocket::Cookie show all
Defined in:
lib/libwebsocket/cookie/request.rb

Overview

Construct or parse a WebSocket request cookie.

Constant Summary

Constants inherited from LibWebSocket::Cookie

NAME, QUOTED_STRING, TOKEN, VALUE

Instance Attribute Summary collapse

Attributes inherited from LibWebSocket::Cookie

#pairs

Instance Method Summary collapse

Methods inherited from LibWebSocket::Cookie

#initialize, #to_s

Constructor Details

This class inherits a constructor from LibWebSocket::Cookie

Instance Attribute Details

#domainObject

Returns the value of attribute domain.



6
7
8
# File 'lib/libwebsocket/cookie/request.rb', line 6

def domain
  @domain
end

#nameObject

Returns the value of attribute name.



6
7
8
# File 'lib/libwebsocket/cookie/request.rb', line 6

def name
  @name
end

#pathObject

Returns the value of attribute path.



6
7
8
# File 'lib/libwebsocket/cookie/request.rb', line 6

def path
  @path
end

#valueObject

Returns the value of attribute value.



6
7
8
# File 'lib/libwebsocket/cookie/request.rb', line 6

def value
  @value
end

#versionObject

Returns the value of attribute version.



6
7
8
# File 'lib/libwebsocket/cookie/request.rb', line 6

def version
  @version
end

Instance Method Details

#parse(string) ⇒ Object

Parse a WebSocket request cookie.

Examples:

cookie = LibWebSocket::Cookie::Request.new
cookies = cookie.parse('$Version=1; foo="bar"; $Path=/; bar=baz; $Domain=.example.com')


12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
# File 'lib/libwebsocket/cookie/request.rb', line 12

def parse(string)
  result = super
  return unless result

  cookies = []

  pair = self.pairs.shift
  version = pair[1]

  cookie = nil
  self.pairs.each do |pair|
    next if pair[0].nil?

    if pair[0].match(/^[^\$]/)
      cookies.push(cookie) unless cookie.nil?

      cookie = self.build_cookie( :name => pair[0], :value => pair[1], :version => version)
    elsif pair[0] == '$Path'
      cookie.path = pair[1]
    elsif pair[0] == '$Domain'
      cookie.domain = pair[1]
    end
  end

  cookies.push(cookie) unless cookie.nil?

  return cookies
end