diff options
| author | Alexey Efimov <[email protected]> | 2024-07-25 21:38:39 +0700 |
|---|---|---|
| committer | GitHub <[email protected]> | 2024-07-25 14:38:39 +0000 |
| commit | e5a42a27eb29d02906852ab35e62ecac0ff6550e (patch) | |
| tree | 6141e3c8538e9f036ef3f6b2b961492842fc2e95 | |
| parent | fcb8576bca10e09299cbc77439666d99abfb7f90 (diff) | |
fix viewer redirects (#7103)
| -rw-r--r-- | ydb/core/mon/async_http_mon.cpp | 29 | ||||
| -rw-r--r-- | ydb/core/viewer/viewer.cpp | 18 |
2 files changed, 37 insertions, 10 deletions
diff --git a/ydb/core/mon/async_http_mon.cpp b/ydb/core/mon/async_http_mon.cpp index 7eabb9f8409..398bb1a6e47 100644 --- a/ydb/core/mon/async_http_mon.cpp +++ b/ydb/core/mon/async_http_mon.cpp @@ -551,9 +551,36 @@ public: } } + TString RewriteLocationWithNode(const TString& response) { + NHttp::THttpParser<NHttp::THttpResponse, NHttp::TSocketBuffer> parser(response); + + NHttp::THeadersBuilder headers(parser.Headers); + headers.Set("Location", TStringBuilder() << "/node/" << TActivationContext::ActorSystem()->NodeId << headers["Location"]); + + NHttp::THttpRenderer<NHttp::THttpResponse, NHttp::TSocketBuffer> renderer; + renderer.InitResponse(parser.Protocol, parser.Version, parser.Status, parser.Message); + renderer.Set(headers); + if (parser.HaveBody()) { + renderer.SetBody(parser.Body); // it shouldn't be here, 30x with a body is a bad idea + } + renderer.Finish(); + return renderer.AsString(); + } + void Handle(NHttp::TEvHttpProxy::TEvHttpOutgoingResponse::TPtr& ev) { + TString httpResponse = ev->Get()->Response->AsString(); + switch (FromStringWithDefault<int>(ev->Get()->Response->Status)) { + case 301: + case 303: + case 307: + case 308: + if (!NHttp::THeaders(ev->Get()->Response->Headers).Get("Location").starts_with("/node/")) { + httpResponse = RewriteLocationWithNode(httpResponse); + } + break; + } auto response = std::make_unique<TEvMon::TEvMonitoringResponse>(); - response->Record.SetHttpResponse(ev->Get()->Response->AsString()); + response->Record.SetHttpResponse(httpResponse); Send(Event->Sender, response.release(), 0, Event->Cookie); PassAway(); } diff --git a/ydb/core/viewer/viewer.cpp b/ydb/core/viewer/viewer.cpp index 779571ef32e..675c1e392fa 100644 --- a/ydb/core/viewer/viewer.cpp +++ b/ydb/core/viewer/viewer.cpp @@ -197,15 +197,15 @@ public: JsonHandlers.JsonHandlersIndex[oldPath] = JsonHandlers.JsonHandlersIndex[newPath]; } - // TODO: redirect old paths - Redirect307["/viewer/v2/json/config"] = "/viewer/config"; - Redirect307["/viewer/v2/json/sysinfo"] = "/viewer/sysinfo"; - Redirect307["/viewer/v2/json/pdiskinfo"] = "/viewer/pdiskinfo"; - Redirect307["/viewer/v2/json/vdiskinfo"] = "/viewer/vdiskinfo"; - Redirect307["/viewer/v2/json/storage"] = "/viewer/storage"; - Redirect307["/viewer/v2/json/nodelist"] = "/viewer/nodelist"; - Redirect307["/viewer/v2/json/tabletinfo"] = "/viewer/tabletinfo"; - Redirect307["/viewer/v2/json/nodeinfo"] = "/viewer/nodeinfo"; + // TODO: redirect of very old paths + JsonHandlers.JsonHandlersIndex["/viewer/v2/json/config"] = JsonHandlers.JsonHandlersIndex["/viewer/config"]; + JsonHandlers.JsonHandlersIndex["/viewer/v2/json/sysinfo"] = JsonHandlers.JsonHandlersIndex["/viewer/sysinfo"]; + JsonHandlers.JsonHandlersIndex["/viewer/v2/json/pdiskinfo"] = JsonHandlers.JsonHandlersIndex["/viewer/pdiskinfo"]; + JsonHandlers.JsonHandlersIndex["/viewer/v2/json/vdiskinfo"] = JsonHandlers.JsonHandlersIndex["/viewer/vdiskinfo"]; + JsonHandlers.JsonHandlersIndex["/viewer/v2/json/storage"] = JsonHandlers.JsonHandlersIndex["/viewer/storage"]; + JsonHandlers.JsonHandlersIndex["/viewer/v2/json/nodelist"] = JsonHandlers.JsonHandlersIndex["/viewer/nodelist"]; + JsonHandlers.JsonHandlersIndex["/viewer/v2/json/tabletinfo"] = JsonHandlers.JsonHandlersIndex["/viewer/tabletinfo"]; + JsonHandlers.JsonHandlersIndex["/viewer/v2/json/nodeinfo"] = JsonHandlers.JsonHandlersIndex["/viewer/nodeinfo"]; TWhiteboardInfo<NKikimrWhiteboard::TEvNodeStateResponse>::InitMerger(); TWhiteboardInfo<NKikimrWhiteboard::TEvBSGroupStateResponse>::InitMerger(); |
