Skip to content

Commit a85ac6f

Browse files
authored
fix CORS headers (#8314)
1 parent dbb2ffe commit a85ac6f

File tree

2 files changed

+14
-34
lines changed

2 files changed

+14
-34
lines changed

ydb/core/mon/async_http_mon.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -240,9 +240,9 @@ class THttpMonLegacyActorRequest : public TActorBootstrapped<THttpMonLegacyActor
240240
response << "HTTP/1.1 204 No Content\r\n"
241241
"Access-Control-Allow-Origin: " << origin << "\r\n"
242242
"Access-Control-Allow-Credentials: true\r\n"
243-
"Access-Control-Allow-Headers: Content-Type,Authorization,Origin,Accept\r\n"
243+
"Access-Control-Allow-Headers: Content-Type,Authorization,Origin,Accept,X-Trace-Verbosity,X-Want-Trace\r\n"
244244
"Access-Control-Allow-Methods: OPTIONS, GET, POST, PUT, DELETE\r\n"
245-
"Content-Type: " + type + "\r\n"
245+
"Content-Type: " << type << "\r\n"
246246
"Connection: keep-alive\r\n\r\n";
247247
ReplyWith(request->CreateResponseString(response));
248248
PassAway();

ydb/core/viewer/viewer.cpp

Lines changed: 12 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -314,36 +314,12 @@ class TViewer : public TActorBootstrapped<TViewer>, public IViewer {
314314
if (type.empty()) {
315315
type = "application/json";
316316
}
317-
if (AllowOrigin) {
318-
ctx.Send(ev->Sender, new NMon::TEvHttpInfoRes(
319-
"HTTP/1.1 204 No Content\r\n"
320-
"Access-Control-Allow-Origin: " + AllowOrigin + "\r\n"
321-
"Access-Control-Allow-Credentials: true\r\n"
322-
"Access-Control-Allow-Headers: Content-Type,Authorization,Origin,Accept\r\n"
323-
"Access-Control-Allow-Methods: OPTIONS, GET, POST\r\n"
324-
"Allow: OPTIONS, GET, POST\r\n"
325-
"Content-Type: " + type + "\r\n"
326-
"Connection: Keep-Alive\r\n\r\n", 0, NMon::IEvHttpInfoRes::EContentType::Custom));
327-
} else {
328-
TString origin = TString(msg->Request.GetHeader("Origin"));
329-
if (!origin.empty()) {
330-
ctx.Send(ev->Sender, new NMon::TEvHttpInfoRes(
331-
"HTTP/1.1 204 No Content\r\n"
332-
"Access-Control-Allow-Origin: " + origin + "\r\n"
333-
"Access-Control-Allow-Credentials: true\r\n"
334-
"Access-Control-Allow-Headers: Content-Type,Authorization,Origin,Accept\r\n"
335-
"Access-Control-Allow-Methods: OPTIONS, GET, POST\r\n"
336-
"Allow: OPTIONS, GET, POST\r\n"
337-
"Content-Type: " + type + "\r\n"
338-
"Connection: Keep-Alive\r\n\r\n", 0, NMon::IEvHttpInfoRes::EContentType::Custom));
339-
} else {
340-
ctx.Send(ev->Sender, new NMon::TEvHttpInfoRes(
341-
"HTTP/1.1 204 No Content\r\n"
342-
"Allow: OPTIONS, GET, POST\r\n"
343-
"Content-Type: " + type + "\r\n"
344-
"Connection: Keep-Alive\r\n\r\n", 0, NMon::IEvHttpInfoRes::EContentType::Custom));
345-
}
346-
}
317+
TStringBuilder response;
318+
response << "HTTP/1.1 204 No Content\r\n";
319+
response << GetCORS(msg);
320+
response << "Content-Type: " + type + "\r\n"
321+
"Connection: Keep-Alive\r\n\r\n";
322+
Send(ev->Sender, new NMon::TEvHttpInfoRes(response, 0, NMon::IEvHttpInfoRes::EContentType::Custom));
347323
return;
348324
}
349325
TString filename(msg->Request.GetPage()->Path + msg->Request.GetPathInfo());
@@ -444,11 +420,15 @@ TString TViewer::GetCORS(const NMon::TEvHttpInfo* request) {
444420
} else if (request && request->Request.GetHeaders().HasHeader("Origin")) {
445421
origin = request->Request.GetHeader("Origin");
446422
}
423+
if (origin.empty()) {
424+
origin = "*";
425+
}
447426
if (origin) {
448427
res << "Access-Control-Allow-Origin: " << origin << "\r\n"
449428
<< "Access-Control-Allow-Credentials: true\r\n"
450-
<< "Access-Control-Allow-Headers: Content-Type,Authorization,Origin,Accept\r\n"
451-
<< "Access-Control-Allow-Methods: OPTIONS, GET, POST\r\n";
429+
<< "Access-Control-Allow-Headers: Content-Type,Authorization,Origin,Accept,X-Trace-Verbosity,X-Want-Trace\r\n"
430+
<< "Access-Control-Allow-Methods: OPTIONS, GET, POST, DELETE\r\n"
431+
<< "Allow: OPTIONS, GET, POST, DELETE\r\n";
452432
}
453433
return res;
454434
}

0 commit comments

Comments
 (0)