Class: Puppet::Network::HTTP::Response

Inherits:
Object
  • Object
show all
Defined in:
lib/puppet/network/http/response.rb

Instance Method Summary collapse

Constructor Details

#initialize(handler, response) ⇒ Response

Returns a new instance of Response.



4
5
6
7
# File 'lib/puppet/network/http/response.rb', line 4

def initialize(handler, response)
  @handler = handler
  @response = response
end

Instance Method Details

#respond_with(code, type, body) ⇒ Object



9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
# File 'lib/puppet/network/http/response.rb', line 9

def respond_with(code, type, body)
  format = Puppet::Network::FormatHandler.format_for(type)
  mime = format.mime
  charset = format.charset

  if charset
    if body.is_a?(String) && body.encoding != charset
      body.encode!(charset)
    end

    mime += "; charset=#{charset.name.downcase}"
  end

  @handler.set_content_type(@response, mime)
  @handler.set_response(@response, body, code)
end