Class: GRHttp::HTTPRequest::Cookies

Inherits:
Hash
  • Object
show all
Defined in:
lib/grhttp/http_cookies.rb

Overview

Sets magic cookies - NOT part of the API.

magic cookies keep track of both incoming and outgoing cookies, setting the response's cookies as well as the combined cookie respetory (held by the request object).

use only the []= for magic cookies. merge and update might not set the response cookies.

Instance Method Summary collapse

Instance Method Details

#[]=(key, val) ⇒ Object

overrides the []= method to set the cookie for the response (by encoding it and preparing it to be sent), as well as to save the cookie in the combined cookie jar (unencoded and available).


16
17
18
19
20
21
22
23
24
25
# File 'lib/grhttp/http_cookies.rb', line 16

def []= key, val
	return super unless @response
	if key.is_a?(Symbol) && self.has_key?( key.to_s)
		key = key.to_s
	elsif self.has_key?( key.to_s.to_sym)
		key = key.to_s.to_sym
	end
	@response.set_cookie key, (val ? val.to_s.dup : nil)
	super
end

#set_response(response) ⇒ Object

sets the Magic Cookie's controller object (which holds the response object and it's `set_cookie` method).


12
13
14
# File 'lib/grhttp/http_cookies.rb', line 12

def set_response response
	@response = response
end