Commit 2e066e16 authored by Kenton Varda's avatar Kenton Varda

Add HttpService::Response::sendError() convenience method.

parent d2cc9fe2
......@@ -2643,6 +2643,18 @@ kj::Own<HttpService> newHttpService(HttpClient& client) {
// =======================================================================================
kj::Promise<void> HttpService::Response::sendError(
uint statusCode, kj::StringPtr statusText, const HttpHeaders& headers) {
auto stream = send(statusCode, statusText, headers, statusText.size());
auto promise = stream->write(statusText.begin(), statusText.size());
return promise.attach(kj::mv(stream));
}
kj::Promise<void> HttpService::Response::sendError(
uint statusCode, kj::StringPtr statusText, const HttpHeaderTable& headerTable) {
return sendError(statusCode, statusText, HttpHeaders(headerTable));
}
kj::Promise<void> HttpService::openWebSocket(
kj::StringPtr url, const HttpHeaders& headers, WebSocketResponse& response) {
class EmptyStream final: public kj::AsyncInputStream {
......
......@@ -518,6 +518,17 @@ public:
//
// `statusText` and `headers` need only remain valid until send() returns (they can be
// stack-allocated).
kj::Promise<void> sendError(uint statusCode, kj::StringPtr statusText,
const HttpHeaders& headers);
kj::Promise<void> sendError(uint statusCode, kj::StringPtr statusText,
const HttpHeaderTable& headerTable);
// Convenience wrapper around send() which sends a basic error. A generic error page specifying
// the error code is sent as the body.
//
// You must provide headers or a header table because downstream service wrappers may be
// expecting response headers built with a particular table so that they can insert additional
// headers.
};
virtual kj::Promise<void> request(
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment