userver: userver/server/http/http_response_body_stream.hpp Source File
Loading...
Searching...
No Matches
http_response_body_stream.hpp
Go to the documentation of this file.
1#pragma once
2
3/// @file userver/server/http/http_response_body_stream.hpp
4/// @brief @copybrief server::http::ResponseBodyStream
5
6#include <string>
7
8#include <userver/server/http/http_response.hpp>
9#include <userver/server/request/response_base.hpp>
10
11USERVER_NAMESPACE_BEGIN
12
13namespace server::handlers {
14class HttpHandlerBase;
15}
16
17namespace server::http {
18
19/// @brief Streaming HTTP response body writer that is passed to
20/// @ref server::handlers::HttpHandlerBase::HandleStreamRequest() overloads.
21///
22/// @see @ref scripts/docs/en/userver/http_server.md
23class ResponseBodyStream final {
24public:
25 ResponseBodyStream(ResponseBodyStream&&) = default;
26 ~ResponseBodyStream();
27
28 /// Send a chunk of response data; should not be called after SetBody().
29 /// It may NOT generate exactly one HTTP chunk per call to @ref PushBodyChunk().
30 void PushBodyChunk(std::string&& chunk, engine::Deadline deadline);
31
32 /// Set full response body instead of sending chunks; should not be called after @ref PushBodyChunk()
33 void SetBody(std::string&& body);
34
35 void SetHeader(const std::string&, const std::string&);
36
37 void SetHeader(std::string_view, const std::string&);
38
39 void SetEndOfHeaders();
40
41 /// Set the HTTP status code; should not be called after @ref PushBodyChunk() as the result will be ignored.
42 void SetStatusCode(int status_code);
43
44 /// @overload
46
47private:
48 friend class server::handlers::HttpHandlerBase;
49
50 ResponseBodyStream(HttpResponse::Producer&& queue_producer, HttpResponse& http_response);
51
52 bool headers_ended_{false};
53 bool headers_end_sent_{false};
54 HttpResponse::Producer queue_producer_;
55 HttpResponse& http_response_;
56};
57
58} // namespace server::http
59
60USERVER_NAMESPACE_END