Class: SWS::Response

Inherits:
Object
  • Object
show all
Defined in:
lib/sws/response.rb

Overview

Represents HTML reponse generated by SWS

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(request, status = "200 SWS/OK") ⇒ Response

Creates new empty Response object



29
30
31
32
33
34
35
36
37
38
# File 'lib/sws/response.rb', line 29

def initialize ( request,status = "200 SWS/OK" ) 
  
  @content = ""
  @headers = Hash.new
  @cookies = Array.new
  @http_version = "HTTP/1.1"
  @status = status
  @request = request
  
end

Instance Attribute Details

#contentObject (readonly)

Returns the value of attribute content.



25
26
27
# File 'lib/sws/response.rb', line 25

def content
  @content
end

#cookiesObject (readonly)

Array of Cookie objects



14
15
16
# File 'lib/sws/response.rb', line 14

def cookies
  @cookies
end

#headersObject (readonly)

Hash of HTTP headers



11
12
13
# File 'lib/sws/response.rb', line 11

def headers
  @headers
end

#http_versionObject

The version of HTTP protocol



17
18
19
# File 'lib/sws/response.rb', line 17

def http_version
  @http_version
end

#requestObject (readonly)

The Request the receiver is associated with



23
24
25
# File 'lib/sws/response.rb', line 23

def request
  @request
end

#statusObject

Status of the response



20
21
22
# File 'lib/sws/response.rb', line 20

def status
  @status
end

Class Method Details

.redirect(request, url) ⇒ Object



40
41
42
43
44
45
46
# File 'lib/sws/response.rb', line 40

def Response.redirect( request, url )

  response = Response.new( request, "302 Found" )
  response.headers["Location"] = url
  return response

end

Instance Method Details

#<<(string) ⇒ Object

Appends a string to the receiver



49
50
51
# File 'lib/sws/response.rb', line 49

def << ( string )
  @content << string
end

#to_sObject

Returns string representation of the receiver



55
56
57
58
59
60
61
62
63
64
65
# File 'lib/sws/response.rb', line 55

def to_s ()
  
  data = ""
  @headers.each_pair { |key, value|  data << "#{key}: #{value}\r\n" }
  @cookies.each { |cookie| data << "#{cookie}\r\n" }
  # End headers
  data << "\r\n"
  data << @content
  return data
  
end