Class: Low::ResponseBuilder
- Inherits:
-
Object
- Object
- Low::ResponseBuilder
- Defined in:
- lib/responses/response_builder.rb
Class Method Summary collapse
-
.respond(config:, socket:, response:, keep_alive: true) ⇒ Object
TODO: Use Async wherever we can where it doesn’t have “Task” requirement.
Class Method Details
.respond(config:, socket:, response:, keep_alive: true) ⇒ Object
TODO: Use Async wherever we can where it doesn’t have “Task” requirement.
7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 |
# File 'lib/responses/response_builder.rb', line 7 def respond(config:, socket:, response:, keep_alive: true) file_body = response.body.respond_to?(:file) if file_body content_length = response.body.file.size else body_data = response.body.read || '' content_length = body_data.bytesize end write_status_line(socket, response) write_host_header(socket, config) write_response_headers(socket, response) write_final_headers(socket, content_length, keep_alive) if file_body IO.copy_stream(response.body.file, socket) else socket.write(body_data) end end |