Class: Noder::HTTP::Response

Inherits:
EventMachine::DelegatedHttpResponse
  • Object
show all
Defined in:
lib/noder/http/response.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(env) ⇒ Response

Returns a new instance of Response.



6
7
8
9
10
# File 'lib/noder/http/response.rb', line 6

def initialize(env)
  super(env[:connection])
  @params = env[:request].params
  @is_rendered = false
end

Instance Attribute Details

#paramsObject

Returns the value of attribute params.



4
5
6
# File 'lib/noder/http/response.rb', line 4

def params
  @params
end

Instance Method Details

#end(content = nil) ⇒ Object



42
43
44
45
46
47
# File 'lib/noder/http/response.rb', line 42

def end(content=nil)
  return if @is_rendered
  @is_rendered = true
  write(content) if content
  send_response
end

#get_header(name) ⇒ Object



34
35
36
# File 'lib/noder/http/response.rb', line 34

def get_header(name)
  @headers[name]
end

#is_rendered?Boolean

Returns:

  • (Boolean)


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

def is_rendered?
  @is_rendered
end

#remove_header(name) ⇒ Object



38
39
40
# File 'lib/noder/http/response.rb', line 38

def remove_header(name)
  @headers.delete(name)
end

#set_header(name, value) ⇒ Object



30
31
32
# File 'lib/noder/http/response.rb', line 30

def set_header(name, value)
  @headers[name] = value
end

#status_codeObject



26
27
28
# File 'lib/noder/http/response.rb', line 26

def status_code
  self.status
end

#status_code=(status) ⇒ Object



22
23
24
# File 'lib/noder/http/response.rb', line 22

def status_code=(status)
  self.status = status
end

#write(content) ⇒ Object



12
13
14
15
# File 'lib/noder/http/response.rb', line 12

def write(content)
  self.content ||=  ''
  self.content << content
end

#write_head(status, headers = {}) ⇒ Object



17
18
19
20
# File 'lib/noder/http/response.rb', line 17

def write_head(status, headers={})
  self.status = status
  @headers.merge!(headers)
end