Class: Low::Factories::ResponseFactory

Inherits:
Object
  • Object
show all
Defined in:
lib/factories/response_factory.rb

Class Method Summary collapse

Class Method Details

.file(path:, content_type:) ⇒ Object



17
18
19
20
21
22
23
# File 'lib/factories/response_factory.rb', line 17

def file(path:, content_type:)
  headers = Protocol::HTTP::Headers.new(['content-type', content_type])
  file = File.open(path, 'rb')
  body = Protocol::HTTP::Body::File.new(file)

  Protocol::HTTP::Response.new('http/1.1', 200, headers, body)
end

.html(body:) ⇒ Object



10
11
12
13
14
15
# File 'lib/factories/response_factory.rb', line 10

def html(body:)
  headers = Protocol::HTTP::Headers.new(['content-type', 'text/html'])
  body = Protocol::HTTP::Body::Buffered.wrap(body)

  Protocol::HTTP::Response.new('http/1.1', 200, headers, body)
end