MCPcopy Create free account
hub / github.com/TelegramMessenger/cocoon / send_headers

Method send_headers

boost-http/http.cpp:207–236  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

205 }
206
207 void send_headers(http::status status, std::string content_type,
208 std::vector<std::pair<std::string, std::string>> headers) {
209 res_.version(req_.version());
210 res_.result((http::status)status);
211 res_.set(http::field::server, "cocoon-client");
212 if (content_type.size() > 0) {
213 res_.set(http::field::content_type, content_type);
214 }
215 res_.keep_alive(req_.keep_alive());
216 for (auto &h : headers) {
217 if (allow_header(h.first)) {
218 res_.set(h.first, h.second);
219 }
220 }
221 res_.chunked(true);
222
223 header_sr_.emplace(res_);
224
225 writing_ = true;
226 http::async_write_header(
227 stream_, *header_sr_,
228 asio::bind_executor(strand_, [self = shared_from_this()](beast::error_code error, std::size_t) {
229 if (error) {
230 LOG(ERROR) << "http: failed to write answer header: " << error.message();
231 self->close();
232 return;
233 }
234 self->write_completed(std::move(error), WriteType::Headers);
235 }));
236 }
237
238 void send_error(http::status status, std::string body) {
239 send_headers(status, "text/plain", {});

Callers 2

receive_answerMethod · 0.80
~CbMethod · 0.80

Calls 3

closeMethod · 0.95
write_completedMethod · 0.95
versionMethod · 0.80

Tested by

no test coverage detected