class
HTTP::Server::Response
- HTTP::Server::Response
- IO
- Reference
- Object
Overview
The response to configure and write to in an HTTP::Server handler.
The response #status and headers must be configured before writing
the response body. Once response output is written, changing the #status
and headers properties has no effect.
The HTTP::Server::Response is a write-only IO, so all IO methods are available
in it.
A response can be upgraded with the #upgrade method. Once invoked, headers
are written and the connection IO (a socket) is yielded to the given block.
This is useful to implement protocol upgrades, such as websockets.
Defined in:
core_ext/http_server_response.cr:4core_ext/http_server_response.cr:169
Instance Method Summary
-
#close : Nil
Closes this response, writing headers and body if not done yet.
-
#flush : Nil
Flushes the output.
-
#respond_with_status(status : HTTP::Status, message : String | Nil = nil) : Nil
Sends status and message as response.
-
#status : HTTP::Status
The status code of this response, which must be set before writing the response body.
- #status=(status : HTTP::Status)
-
#status_code : Int32
Convenience method to retrieve the HTTP status code.
-
#status_code=(status_code : Int32)
Convenience method to set the HTTP status code.
-
#upgrade(protocol : String | Nil = nil, &) : Nil
Upgrades this response, writing headers and yielding the connection
IO(a socket) to the given block. -
#write(slice : Bytes) : Nil
See
IO#write(slice).
Instance Method Detail
Closes this response, writing headers and body if not done yet. This method must be implemented if wrapping the response output.
Flushes the output. This method must be implemented if wrapping the response output.
Sends status and message as response.
This method calls #reset to remove any previous settings and writes the
given status and message to the response IO. Finally, it closes the
response.
If message is nil, the default message for status is used provided
by HTTP::Status#description.
Raises IO::Error if the response is closed or headers were already
sent.
The status code of this response, which must be set before writing the response body. If not set, the default value is 200 (OK).
Upgrades this response, writing headers and yielding the connection IO (a socket) to the given block.
This is useful to implement protocol upgrades, such as websockets.