1
0
Fork 0
mirror of https://github.com/ton-blockchain/ton synced 2025-03-09 15:40:10 +00:00

Correctly return errors from proxy

This commit is contained in:
SpyCheese 2022-06-29 15:53:48 +03:00
parent c55b6f84a5
commit 9107bcaf24
6 changed files with 75 additions and 36 deletions

View file

@ -44,13 +44,22 @@ void HttpInboundConnection::send_server_error() {
loop();
}
void HttpInboundConnection::send_proxy_error() {
static const auto s =
"HTTP/1.1 502 Bad Gateway\r\n"
"Connection: keep-alive\r\n"
"Content-length: 0\r\n"
"\r\n";
buffered_fd_.output_buffer().append(td::Slice(s, strlen(s)));
void HttpInboundConnection::send_proxy_error(td::Status error) {
if (error.code() == ErrorCode::timeout) {
static const auto s =
"HTTP/1.1 504 Gateway Timeout\r\n"
"Connection: keep-alive\r\n"
"Content-length: 0\r\n"
"\r\n";
buffered_fd_.output_buffer().append(td::Slice(s, strlen(s)));
} else {
static const auto s =
"HTTP/1.1 502 Bad Gateway\r\n"
"Connection: keep-alive\r\n"
"Content-length: 0\r\n"
"\r\n";
buffered_fd_.output_buffer().append(td::Slice(s, strlen(s)));
}
loop();
}
@ -83,7 +92,7 @@ td::Status HttpInboundConnection::receive(td::ChainBufferReader &input) {
auto a = R.move_as_ok();
td::actor::send_closure(SelfId, &HttpInboundConnection::send_answer, std::move(a.first), std::move(a.second));
} else {
td::actor::send_closure(SelfId, &HttpInboundConnection::send_proxy_error);
td::actor::send_closure(SelfId, &HttpInboundConnection::send_proxy_error, R.move_as_error());
}
});
http_callback_->receive_request(std::move(cur_request_), payload, std::move(P));

View file

@ -54,7 +54,7 @@ class HttpInboundConnection : public HttpConnection {
void send_client_error();
void send_server_error();
void send_proxy_error();
void send_proxy_error(td::Status error);
void payload_written() override {
writing_payload_ = nullptr;

View file

@ -864,7 +864,7 @@ tl_object_ptr<ton_api::http_response> HttpResponse::store_tl() {
} else {
headers.push_back(HttpHeader{"Connection", "Close"}.store_tl());
}
return create_tl_object<ton_api::http_response>(proto_version_, code_, reason_, std::move(headers));
return create_tl_object<ton_api::http_response>(proto_version_, code_, reason_, std::move(headers), false);
}
td::Status HttpHeader::basic_check() {