Skip to content

Commit 19756b2

Browse files
authored
fix viewer redirects (ydb-platform#7103) (ydb-platform#7120)
1 parent 690f5e8 commit 19756b2

File tree

2 files changed

+37
-10
lines changed

2 files changed

+37
-10
lines changed

ydb/core/mon/async_http_mon.cpp

Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -551,9 +551,36 @@ class THttpMonServiceNodeRequest : public TActorBootstrapped<THttpMonServiceNode
551551
}
552552
}
553553

554+
TString RewriteLocationWithNode(const TString& response) {
555+
NHttp::THttpParser<NHttp::THttpResponse, NHttp::TSocketBuffer> parser(response);
556+
557+
NHttp::THeadersBuilder headers(parser.Headers);
558+
headers.Set("Location", TStringBuilder() << "/node/" << TActivationContext::ActorSystem()->NodeId << headers["Location"]);
559+
560+
NHttp::THttpRenderer<NHttp::THttpResponse, NHttp::TSocketBuffer> renderer;
561+
renderer.InitResponse(parser.Protocol, parser.Version, parser.Status, parser.Message);
562+
renderer.Set(headers);
563+
if (parser.HaveBody()) {
564+
renderer.SetBody(parser.Body); // it shouldn't be here, 30x with a body is a bad idea
565+
}
566+
renderer.Finish();
567+
return renderer.AsString();
568+
}
569+
554570
void Handle(NHttp::TEvHttpProxy::TEvHttpOutgoingResponse::TPtr& ev) {
571+
TString httpResponse = ev->Get()->Response->AsString();
572+
switch (FromStringWithDefault<int>(ev->Get()->Response->Status)) {
573+
case 301:
574+
case 303:
575+
case 307:
576+
case 308:
577+
if (!NHttp::THeaders(ev->Get()->Response->Headers).Get("Location").starts_with("/node/")) {
578+
httpResponse = RewriteLocationWithNode(httpResponse);
579+
}
580+
break;
581+
}
555582
auto response = std::make_unique<TEvMon::TEvMonitoringResponse>();
556-
response->Record.SetHttpResponse(ev->Get()->Response->AsString());
583+
response->Record.SetHttpResponse(httpResponse);
557584
Send(Event->Sender, response.release(), 0, Event->Cookie);
558585
PassAway();
559586
}

ydb/core/viewer/viewer.cpp

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -188,15 +188,15 @@ class TViewer : public TActorBootstrapped<TViewer>, public IViewer {
188188
JsonHandlers.JsonHandlersIndex[oldPath] = JsonHandlers.JsonHandlersIndex[newPath];
189189
}
190190

191-
// TODO: redirect old paths
192-
Redirect307["/viewer/v2/json/config"] = "/viewer/config";
193-
Redirect307["/viewer/v2/json/sysinfo"] = "/viewer/sysinfo";
194-
Redirect307["/viewer/v2/json/pdiskinfo"] = "/viewer/pdiskinfo";
195-
Redirect307["/viewer/v2/json/vdiskinfo"] = "/viewer/vdiskinfo";
196-
Redirect307["/viewer/v2/json/storage"] = "/viewer/storage";
197-
Redirect307["/viewer/v2/json/nodelist"] = "/viewer/nodelist";
198-
Redirect307["/viewer/v2/json/tabletinfo"] = "/viewer/tabletinfo";
199-
Redirect307["/viewer/v2/json/nodeinfo"] = "/viewer/nodeinfo";
191+
// TODO: redirect of very old paths
192+
JsonHandlers.JsonHandlersIndex["/viewer/v2/json/config"] = JsonHandlers.JsonHandlersIndex["/viewer/config"];
193+
JsonHandlers.JsonHandlersIndex["/viewer/v2/json/sysinfo"] = JsonHandlers.JsonHandlersIndex["/viewer/sysinfo"];
194+
JsonHandlers.JsonHandlersIndex["/viewer/v2/json/pdiskinfo"] = JsonHandlers.JsonHandlersIndex["/viewer/pdiskinfo"];
195+
JsonHandlers.JsonHandlersIndex["/viewer/v2/json/vdiskinfo"] = JsonHandlers.JsonHandlersIndex["/viewer/vdiskinfo"];
196+
JsonHandlers.JsonHandlersIndex["/viewer/v2/json/storage"] = JsonHandlers.JsonHandlersIndex["/viewer/storage"];
197+
JsonHandlers.JsonHandlersIndex["/viewer/v2/json/nodelist"] = JsonHandlers.JsonHandlersIndex["/viewer/nodelist"];
198+
JsonHandlers.JsonHandlersIndex["/viewer/v2/json/tabletinfo"] = JsonHandlers.JsonHandlersIndex["/viewer/tabletinfo"];
199+
JsonHandlers.JsonHandlersIndex["/viewer/v2/json/nodeinfo"] = JsonHandlers.JsonHandlersIndex["/viewer/nodeinfo"];
200200

201201
TWhiteboardInfo<NKikimrWhiteboard::TEvNodeStateResponse>::InitMerger();
202202
TWhiteboardInfo<NKikimrWhiteboard::TEvBSGroupStateResponse>::InitMerger();

0 commit comments

Comments
 (0)