Class: LibWebSocket::Cookie::Response

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

Overview

Construct or parse a WebSocket response 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, #parse

Constructor Details

This class inherits a constructor from LibWebSocket::Cookie

Instance Attribute Details

#commentObject

Returns the value of attribute comment.



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

def comment
  @comment
end

#comment_urlObject

Returns the value of attribute comment_url.



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

def comment_url
  @comment_url
end

#discardObject

Returns the value of attribute discard.



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

def discard
  @discard
end

#max_ageObject

Returns the value of attribute max_age.



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

def max_age
  @max_age
end

#nameObject

Returns the value of attribute name.



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

def name
  @name
end

#pathObject

Returns the value of attribute path.



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

def path
  @path
end

#portlistObject

Returns the value of attribute portlist.



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

def portlist
  @portlist
end

#secureObject

Returns the value of attribute secure.



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

def secure
  @secure
end

#valueObject

Returns the value of attribute value.



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

def value
  @value
end

Instance Method Details

#to_sObject

Construct a WebSocket response cookie.

Examples:

cookie = LibWebSocket::Cookie::Response.new(
  :name    => 'foo',
  :value   => 'bar',
  :discard => 1,
  :max_age => 0
)
cookie.to_s # foo=bar; Discard; Max-Age=0; Version=1


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

def to_s
  pairs = []

  pairs.push([self.name, self.value])

  pairs.push ['Comment', self.comment] if self.comment
  pairs.push ['CommentURL', self.comment_url] if self.comment_url
  pairs.push ['Discard'] if self.discard
  pairs.push ['Max-Age', self.max_age] if self.max_age
  pairs.push ['Path', self.path] if self.path

  if self.portlist
    self.portlist = Array(self.portlist)
    list          = self.portlist.join(' ')
    pairs.push ['Port', "\"#{list}\""]
  end

  pairs.push ['Secure'] if self.secure
  pairs.push ['Version', '1']

  self.pairs = pairs

  super
end