CCF
Loading...
Searching...
No Matches
http_responder.h
Go to the documentation of this file.
1// Copyright (c) Microsoft Corporation. All rights reserved.
2// Licensed under the Apache 2.0 License.
3#pragma once
4
5#include "ccf/http_consts.h"
7#include "ccf/odata_error.h"
8
9#include <functional>
10
11namespace ccf::http
12{
14 {
15 public:
16 virtual ~HTTPResponder() = default;
17
18 virtual bool send_response(
19 http_status status_code,
20 http::HeaderMap&& headers,
21 http::HeaderMap&& trailers,
22 std::vector<uint8_t>&& body) = 0;
23
25 {
26 nlohmann::json body = ccf::ODataErrorResponse{
27 ccf::ODataError{std::move(error.code), std::move(error.msg), {}}};
28 const std::string s = body.dump();
29 std::vector<uint8_t> v(s.begin(), s.end());
30
31 http::HeaderMap headers;
32 headers[http::headers::CONTENT_TYPE] =
33 http::headervalues::contenttype::JSON;
34
35 return send_response(error.status, std::move(headers), {}, std::move(v));
36 }
37 };
38}
Definition http_responder.h:14
virtual ~HTTPResponder()=default
bool send_odata_error_response(ccf::ErrorDetails &&error)
Definition http_responder.h:24
virtual bool send_response(http_status status_code, http::HeaderMap &&headers, http::HeaderMap &&trailers, std::vector< uint8_t > &&body)=0
Definition http_accept.h:13
std::map< std::string, std::string, std::less<> > HeaderMap
Definition http_header_map.h:10
llhttp_status http_status
Definition http_status.h:9
@ error
Definition tls_session.h:23
Definition odata_error.h:58
Definition odata_error.h:50
Definition odata_error.h:37