Skip to content

Commit e5a42a2

Browse files
authored
fix viewer redirects (#7103)
1 parent fcb8576 commit e5a42a2

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
@@ -197,15 +197,15 @@ class TViewer : public TActorBootstrapped<TViewer>, public IViewer {
197197
JsonHandlers.JsonHandlersIndex[oldPath] = JsonHandlers.JsonHandlersIndex[newPath];
198198
}
199199

200-
// TODO: redirect old paths
201-
Redirect307["/viewer/v2/json/config"] = "/viewer/config";
202-
Redirect307["/viewer/v2/json/sysinfo"] = "/viewer/sysinfo";
203-
Redirect307["/viewer/v2/json/pdiskinfo"] = "/viewer/pdiskinfo";
204-
Redirect307["/viewer/v2/json/vdiskinfo"] = "/viewer/vdiskinfo";
205-
Redirect307["/viewer/v2/json/storage"] = "/viewer/storage";
206-
Redirect307["/viewer/v2/json/nodelist"] = "/viewer/nodelist";
207-
Redirect307["/viewer/v2/json/tabletinfo"] = "/viewer/tabletinfo";
208-
Redirect307["/viewer/v2/json/nodeinfo"] = "/viewer/nodeinfo";
200+
// TODO: redirect of very old paths
201+
JsonHandlers.JsonHandlersIndex["/viewer/v2/json/config"] = JsonHandlers.JsonHandlersIndex["/viewer/config"];
202+
JsonHandlers.JsonHandlersIndex["/viewer/v2/json/sysinfo"] = JsonHandlers.JsonHandlersIndex["/viewer/sysinfo"];
203+
JsonHandlers.JsonHandlersIndex["/viewer/v2/json/pdiskinfo"] = JsonHandlers.JsonHandlersIndex["/viewer/pdiskinfo"];
204+
JsonHandlers.JsonHandlersIndex["/viewer/v2/json/vdiskinfo"] = JsonHandlers.JsonHandlersIndex["/viewer/vdiskinfo"];
205+
JsonHandlers.JsonHandlersIndex["/viewer/v2/json/storage"] = JsonHandlers.JsonHandlersIndex["/viewer/storage"];
206+
JsonHandlers.JsonHandlersIndex["/viewer/v2/json/nodelist"] = JsonHandlers.JsonHandlersIndex["/viewer/nodelist"];
207+
JsonHandlers.JsonHandlersIndex["/viewer/v2/json/tabletinfo"] = JsonHandlers.JsonHandlersIndex["/viewer/tabletinfo"];
208+
JsonHandlers.JsonHandlersIndex["/viewer/v2/json/nodeinfo"] = JsonHandlers.JsonHandlersIndex["/viewer/nodeinfo"];
209209

210210
TWhiteboardInfo<NKikimrWhiteboard::TEvNodeStateResponse>::InitMerger();
211211
TWhiteboardInfo<NKikimrWhiteboard::TEvBSGroupStateResponse>::InitMerger();

0 commit comments

Comments
 (0)