Class: Web2Go::WebrickResponse

Inherits:
Object
  • Object
show all
Defined in:
lib/Web2Go/WebrickResponse.rb

Instance Method Summary collapse

Constructor Details

#initialize(response) ⇒ WebrickResponse

Returns a new instance of WebrickResponse.


8
9
10
# File 'lib/Web2Go/WebrickResponse.rb', line 8

def initialize(response)
  @response = response 
end

Instance Method Details


37
38
39
40
41
42
43
# File 'lib/Web2Go/WebrickResponse.rb', line 37

def add_cookie(name,value,domain=nil,path=nil,expires=nil)
  cookie = WEBrick::Cookie.new(name,value)
  cookie.expires = expires unless expires.nil?
  cookie.domain  = domain unless domain.nil?
  cookie.path    = path.nil? ? '/' : path
  set_cookie(cookie)
end

#body=(content) ⇒ Object


12
13
14
# File 'lib/Web2Go/WebrickResponse.rb', line 12

def body=(content)
  @response.body=(content)
end

#content_type=(type) ⇒ Object


16
17
18
# File 'lib/Web2Go/WebrickResponse.rb', line 16

def content_type=(type)
  @response['Content-Type'] = type
end

#cookiesObject


33
34
35
# File 'lib/Web2Go/WebrickResponse.rb', line 33

def cookies
  @response.cookies
end

#failedObject


24
25
26
# File 'lib/Web2Go/WebrickResponse.rb', line 24

def failed
  @response.set_error(HTTPStatus::RC_NOT_FOUND)
end

#redirect_to=(url) ⇒ Object


20
21
22
# File 'lib/Web2Go/WebrickResponse.rb', line 20

def redirect_to=(url)
  @response.set_redirect(WEBrick::HTTPStatus[302],url)
end

28
29
30
31
# File 'lib/Web2Go/WebrickResponse.rb', line 28

def set_cookie(cookie)
  @response.cookies.delete_if { |item| item.name == cookie.name }
  @response.cookies.push(cookie)
end