aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorandrew-rykov <arykov@ydb.tech>2023-11-16 14:07:03 +0300
committerandrew-rykov <arykov@ydb.tech>2023-11-16 15:05:58 +0300
commitbb41968b0c80a285d9c35e9c6895896b7b8852a3 (patch)
treeccdab01db989b8f812dc469a712073b51946ce7b
parentdfff32a40242f1c6be37ffc69620c5642473234c (diff)
downloadydb-bb41968b0c80a285d9c35e9c6895896b7b8852a3.tar.gz
added Access-Control-Allow headers for tablet TForwardingActor
-rw-r--r--ydb/core/tablet/tablet_monitoring_proxy.cpp28
1 files changed, 26 insertions, 2 deletions
diff --git a/ydb/core/tablet/tablet_monitoring_proxy.cpp b/ydb/core/tablet/tablet_monitoring_proxy.cpp
index 3cf4530fde..09b9e701dd 100644
--- a/ydb/core/tablet/tablet_monitoring_proxy.cpp
+++ b/ydb/core/tablet/tablet_monitoring_proxy.cpp
@@ -126,9 +126,33 @@ public:
Detach(ctx);
}
+ TString GetCORS() {
+ TStringBuilder res;
+ TString origin;
+ for (const auto& header : Request.headers()) {
+ if (header.name() == "Origin") {
+ origin = header.value();
+ }
+ }
+ if (origin.empty()) {
+ origin = "*";
+ }
+ res << "Access-Control-Allow-Origin: " << origin << "\r\n";
+ res << "Access-Control-Allow-Credentials: true\r\n";
+ res << "Access-Control-Allow-Headers: Content-Type,Authorization,Origin,Accept\r\n";
+ res << "Access-Control-Allow-Methods: OPTIONS, GET, POST\r\n";
+ return res;
+ }
+
void Handle(NMon::TEvRemoteJsonInfoRes::TPtr &ev, const TActorContext &ctx) {
- static const char HTTPOKJSON[] = "HTTP/1.1 200 Ok\r\nContent-Type: application/json\r\n\r\n";
- ctx.Send(Sender, new NMon::TEvHttpInfoRes(HTTPOKJSON + ev->Get()->Json, 0, NMon::IEvHttpInfoRes::EContentType::Custom));
+ TStringStream str;
+ str << "HTTP/1.1 200 Ok\r\n"
+ << "Content-Type: application/json\r\n"
+ << GetCORS()
+ << "\r\n"
+ << ev->Get()->Json;
+
+ ctx.Send(Sender, new NMon::TEvHttpInfoRes(str.Str(), 0, NMon::IEvHttpInfoRes::EContentType::Custom));
Detach(ctx);
}