Class: Response::HTML

Inherits:
Response show all
Defined in:
lib/response/html.rb

Overview

HTML response

Constant Summary collapse

HEADERS =
IceNine.deep_freeze('Content-Type' => 'text/html; charset=UTF-8')

Constants inherited from Response

TEXT_PLAIN, Undefined

Instance Attribute Summary

Attributes inherited from Response

#body, #headers, #status

Class Method Summary collapse

Methods inherited from Response

#cache_control, #content_type, #last_modified, #merge_headers, #rack_array, #to_rack_response, #valid?, #with_body, #with_headers, #with_status

Class Method Details

.build(body) ⇒ Response::HTML

Build html response with defaults

Examples:


# With defaults
response = Response::HTML.build("<html><body>Hello</body></html>")
response.status  # => Response::Status::OK
response.headers # => { 'Content-Type' => 'text/html; charset=UTF-8' }
response.body    # => "<html><body>Hello</body></html>"

# With overriding defaults
response = Response::HTML.build("<html><body>Hello</body></html>") do |response|
  response.with_status(Respnse::Status::NOT_FOUND)
end

response.status  # => Response::Status::NOT_FOUND
response.headers # => { 'Content-Type' => 'text/html; charset=UTF-8' }
response.body    # => "<html><body>Hello</body></html>"

Parameters:

  • body (Object)

    rack compatible body

Returns:



32
33
34
# File 'lib/response/html.rb', line 32

def self.build(body)
  super(Status::OK, HEADERS, body)
end