Skip to content

Commit 9e878a2

Browse files
committed
fix CORS headers (ydb-platform#8303)
1 parent 38f8453 commit 9e878a2

File tree

1 file changed

+8
-31
lines changed

1 file changed

+8
-31
lines changed

ydb/core/viewer/viewer.cpp

Lines changed: 8 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -475,36 +475,12 @@ class TViewer : public TActorBootstrapped<TViewer>, public IViewer {
475475
if (type.empty()) {
476476
type = "application/json";
477477
}
478-
if (AllowOrigin) {
479-
ctx.Send(ev->Sender, new NMon::TEvHttpInfoRes(
480-
"HTTP/1.1 204 No Content\r\n"
481-
"Access-Control-Allow-Origin: " + AllowOrigin + "\r\n"
482-
"Access-Control-Allow-Credentials: true\r\n"
483-
"Access-Control-Allow-Headers: Content-Type,Authorization,Origin,Accept,X-Trace-Verbosity,X-Want-Trace\r\n"
484-
"Access-Control-Allow-Methods: OPTIONS, GET, POST\r\n"
485-
"Allow: OPTIONS, GET, POST\r\n"
486-
"Content-Type: " + type + "\r\n"
487-
"Connection: Keep-Alive\r\n\r\n", 0, NMon::IEvHttpInfoRes::EContentType::Custom));
488-
} else {
489-
TString origin = TString(msg->Request.GetHeader("Origin"));
490-
if (!origin.empty()) {
491-
ctx.Send(ev->Sender, new NMon::TEvHttpInfoRes(
492-
"HTTP/1.1 204 No Content\r\n"
493-
"Access-Control-Allow-Origin: " + origin + "\r\n"
494-
"Access-Control-Allow-Credentials: true\r\n"
495-
"Access-Control-Allow-Headers: Content-Type,Authorization,Origin,Accept,X-Trace-Verbosity,X-Want-Trace\r\n"
496-
"Access-Control-Allow-Methods: OPTIONS, GET, POST\r\n"
497-
"Allow: OPTIONS, GET, POST\r\n"
498-
"Content-Type: " + type + "\r\n"
499-
"Connection: Keep-Alive\r\n\r\n", 0, NMon::IEvHttpInfoRes::EContentType::Custom));
500-
} else {
501-
ctx.Send(ev->Sender, new NMon::TEvHttpInfoRes(
502-
"HTTP/1.1 204 No Content\r\n"
503-
"Allow: OPTIONS, GET, POST\r\n"
504-
"Content-Type: " + type + "\r\n"
505-
"Connection: Keep-Alive\r\n\r\n", 0, NMon::IEvHttpInfoRes::EContentType::Custom));
506-
}
507-
}
478+
TStringBuilder response;
479+
response << "HTTP/1.1 204 No Content\r\n";
480+
FillCORS(response, msg);
481+
response << "Content-Type: " + type + "\r\n"
482+
"Connection: Keep-Alive\r\n\r\n";
483+
Send(ev->Sender, new NMon::TEvHttpInfoRes(response, 0, NMon::IEvHttpInfoRes::EContentType::Custom));
508484
return;
509485
}
510486
TString path("/" + msg->Request.GetPage()->Path + msg->Request.GetPathInfo());
@@ -615,7 +591,8 @@ void TViewer::FillCORS(TStringBuilder& stream, const TRequestState& request) {
615591
stream << "Access-Control-Allow-Origin: " << origin << "\r\n"
616592
<< "Access-Control-Allow-Credentials: true\r\n"
617593
<< "Access-Control-Allow-Headers: Content-Type,Authorization,Origin,Accept,X-Trace-Verbosity,X-Want-Trace\r\n"
618-
<< "Access-Control-Allow-Methods: OPTIONS, GET, POST\r\n";
594+
<< "Access-Control-Allow-Methods: OPTIONS, GET, POST, DELETE\r\n"
595+
<< "Allow: OPTIONS, GET, POST, DELETE\r\n";
619596
}
620597
}
621598

0 commit comments

Comments
 (0)