10#include <userver/concurrent/queue.hpp>
11#include <userver/engine/single_consumer_event.hpp>
12#include <userver/http/content_type.hpp>
13#include <userver/http/header_map.hpp>
14#include <userver/server/http/http_response_cookie.hpp>
15#include <userver/server/request/response_base.hpp>
16#include <userver/utils/impl/projecting_view.hpp>
17#include <userver/utils/str_icase.hpp>
21USERVER_NAMESPACE_BEGIN
23namespace server::
http {
31inline constexpr std::string_view kDefaultContentType =
"application/octet-stream";
33class Http2ResponseWriter;
37void OutputHeader(USERVER_NAMESPACE::http::
headers::HeadersString& header, std::string_view key, std::string_view val);
46 using HeadersMap = USERVER_NAMESPACE::http::
headers::HeaderMap;
48 using HeadersMapKeys =
decltype(utils::impl::MakeKeysView(HeadersMap()));
50 using CookiesMap = Cookie::CookiesMap;
52 using CookiesMapKeys =
decltype(utils::impl::MakeKeysView(CookiesMap()));
55 HttpResponse(
const HttpRequestImpl& request,
request::ResponseDataAccounter& data_accounter);
57 const HttpRequestImpl& request,
58 request::ResponseDataAccounter& data_accounter,
59 std::chrono::steady_clock::time_point now,
62 ~HttpResponse()
override;
64 void SetSendFailed(std::chrono::steady_clock::time_point failure_time)
override;
70 bool SetHeader(std::string name, std::string value);
75 bool SetHeader(std::string_view name, std::string value);
78 bool SetHeader(
const USERVER_NAMESPACE::http::
headers::PredefinedHeader& header, std::string value);
110 const std::string&
GetHeader(std::string_view header_name)
const;
112 const std::string&
GetHeader(
const USERVER_NAMESPACE::http::
headers::PredefinedHeader& header_name)
const;
118 bool HasHeader(
const USERVER_NAMESPACE::http::
headers::PredefinedHeader& header_name)
const;
125 const Cookie&
GetCookie(std::string_view cookie_name)
const;
129 void SendResponse(engine::
io::
RwBase& socket)
override;
132 void SetStatusServiceUnavailable()
override {
SetStatus(HttpStatus::kServiceUnavailable
); }
133 void SetStatusOk()
override {
SetStatus(HttpStatus::kOk
); }
134 void SetStatusNotFound()
override {
SetStatus(HttpStatus::kNotFound
); }
136 bool WaitForHeadersEnd()
override;
137 void SetHeadersEnd()
override;
140 using Producer = std::variant<std::monostate, Queue::Producer, impl::Http2StreamEventProducer>;
142 void SetStreamBody();
143 bool IsBodyStreamed()
const override;
145 Producer GetBodyProducer();
148 friend class Http2ResponseWriter;
151 std::size_t SetBodyStreamed(engine::
io::
RwBase& socket, USERVER_NAMESPACE::http::
headers::HeadersString& header);
154 std::size_t SetBodyNotStreamed(engine::
io::
RwBase& socket, USERVER_NAMESPACE::http::
headers::HeadersString& header);
156 const HttpRequestImpl& request_;
157 HttpStatus status_ = HttpStatus::kOk;
161 engine::SingleConsumerEvent headers_end_{engine::SingleConsumerEvent::NoAutoReset()};
162 std::optional<Queue::Consumer> body_stream_;
163 Producer body_stream_producer_;
164 bool is_stream_body_{
false};
167void SetThrottleReason(
http::HttpResponse& http_response, std::string log_reason, std::string http_header_reason);