Skip to content

Commit d906f97

Browse files
authored
Merge 3b343e9 into 22f57bd
2 parents 22f57bd + 3b343e9 commit d906f97

File tree

5 files changed

+34
-27
lines changed

5 files changed

+34
-27
lines changed

ydb/core/viewer/json_autocomplete.h

Lines changed: 4 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,9 @@
55
#include <ydb/core/base/tablet_pipe.h>
66
#include <ydb/library/services/services.pb.h>
77
#include <ydb/core/viewer/json/json.h>
8-
#include "viewer.h"
8+
99
#include "query_autocomplete_helper.h"
10+
#include "viewer_request.h"
1011

1112
namespace NKikimr {
1213
namespace NViewer {
@@ -139,17 +140,8 @@ class TJsonAutocomplete : public TViewerPipeClient<TJsonAutocomplete> {
139140
}
140141
}
141142

142-
bool IsPostContent() {
143-
if (Event->Get()->Request.GetMethod() == HTTP_METHOD_POST) {
144-
const THttpHeaders& headers = Event->Get()->Request.GetHeaders();
145-
auto itContentType = FindIf(headers, [](const auto& header) { return header.Name() == "Content-Type"; });
146-
if (itContentType != headers.end()) {
147-
TStringBuf contentTypeHeader = itContentType->Value();
148-
TStringBuf contentType = contentTypeHeader.NextTok(';');
149-
return contentType == "application/json";
150-
}
151-
}
152-
return false;
143+
bool IsPostContent() const {
144+
return NViewer::IsPostContent(Event);
153145
}
154146

155147
TAutoPtr<NSchemeCache::TSchemeCacheNavigate> MakeSchemeCacheRequest() {

ydb/core/viewer/json_query.h

Lines changed: 2 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
#pragma once
22
#include "viewer.h"
3-
#include <unordered_map>
43
#include <ydb/library/actors/core/actor_bootstrapped.h>
54
#include <ydb/library/actors/core/interconnect.h>
65
#include <ydb/library/actors/core/mon.h>
@@ -12,7 +11,6 @@
1211
#include <ydb/core/kqp/common/kqp.h>
1312
#include <ydb/core/kqp/executer_actor/kqp_executer.h>
1413
#include <ydb/core/viewer/json/json.h>
15-
//#include <ydb/public/lib/deprecated/kicli/kicli.h>
1614
#include <ydb/public/lib/json_value/ydb_json_value.h>
1715
#include <ydb/public/sdk/cpp/client/ydb_result/result.h>
1816
#include "json_pipe_req.h"
@@ -102,17 +100,8 @@ class TJsonQuery : public TViewerPipeClient<TJsonQuery> {
102100
}
103101
}
104102

105-
bool IsPostContent() {
106-
if (Event->Get()->Request.GetMethod() == HTTP_METHOD_POST) {
107-
const THttpHeaders& headers = Event->Get()->Request.GetHeaders();
108-
auto itContentType = FindIf(headers, [](const auto& header) { return header.Name() == "Content-Type"; });
109-
if (itContentType != headers.end()) {
110-
TStringBuf contentTypeHeader = itContentType->Value();
111-
TStringBuf contentType = contentTypeHeader.NextTok(';');
112-
return contentType == "application/json";
113-
}
114-
}
115-
return false;
103+
bool IsPostContent() const {
104+
return NViewer::IsPostContent(Event);
116105
}
117106

118107
TJsonQuery(IViewer* viewer, NMon::TEvHttpInfo::TPtr& ev)

ydb/core/viewer/viewer_request.cpp

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,5 +89,22 @@ IActor* CreateViewerRequestHandler(TEvViewer::TEvViewerRequest::TPtr& request) {
8989
return nullptr;
9090
}
9191

92+
bool IsPostContent(const NMon::TEvHttpInfo::TPtr& event) {
93+
if (event->Get()->Request.GetMethod() == HTTP_METHOD_POST) {
94+
const THttpHeaders& headers = event->Get()->Request.GetHeaders();
95+
96+
auto itContentType = FindIf(headers, [](const auto& header) {
97+
return AsciiEqualsIgnoreCase(header.Name(), "Content-Type");
98+
});
99+
100+
if (itContentType != headers.end()) {
101+
TStringBuf contentTypeHeader = itContentType->Value();
102+
TStringBuf contentType = contentTypeHeader.NextTok(';');
103+
return contentType == "application/json";
104+
}
105+
}
106+
return false;
107+
}
108+
92109
}
93110
}

ydb/core/viewer/viewer_request.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ union ViewerWhiteboardCookie {
3838
};
3939

4040
IActor* CreateViewerRequestHandler(TEvViewer::TEvViewerRequest::TPtr& request);
41+
bool IsPostContent(const NMon::TEvHttpInfo::TPtr& event);
4142

4243
}
4344
}

ydb/core/viewer/viewer_ut.cpp

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1108,7 +1108,7 @@ Y_UNIT_TEST_SUITE(Viewer) {
11081108
}
11091109
}
11101110

1111-
void JsonAutocompleteTest(HTTP_METHOD method, NJson::TJsonValue& value, TString prefix = "", TString database = "", TVector<TString> tables = {}, ui32 limit = 10) {
1111+
void JsonAutocompleteTest(HTTP_METHOD method, NJson::TJsonValue& value, TString prefix = "", TString database = "", TVector<TString> tables = {}, ui32 limit = 10, bool lowerCaseContentType = false) {
11121112
TPortManager tp;
11131113
ui16 port = tp.GetPort(2134);
11141114
ui16 grpcPort = tp.GetPort(2135);
@@ -1148,7 +1148,8 @@ Y_UNIT_TEST_SUITE(Viewer) {
11481148
{"prefix", prefix}
11491149
};
11501150
httpReq.PostContent = NJson::WriteJson(root);
1151-
httpReq.HttpHeaders.AddHeader("Content-Type", "application/json");
1151+
auto contType = lowerCaseContentType ? "content-type" : "Content-Type";
1152+
httpReq.HttpHeaders.AddHeader(contType, "application/json");
11521153
}
11531154
httpReq.CgiParameters.emplace("limit", ToString(limit));
11541155
httpReq.CgiParameters.emplace("direct", "1");
@@ -1275,6 +1276,13 @@ Y_UNIT_TEST_SUITE(Viewer) {
12751276
"/Root/MyDatabase",
12761277
"/Root/TestDatabase"
12771278
});
1279+
1280+
JsonAutocompleteTest(HTTP_METHOD_POST, value, "/Root/Database", "", {}, 2, true);
1281+
VerifyJsonAutocompleteSuccess(value, {
1282+
"/Root/MyDatabase",
1283+
"/Root/TestDatabase"
1284+
});
1285+
12781286
}
12791287

12801288
Y_UNIT_TEST(JsonAutocompleteScheme) {

0 commit comments

Comments
 (0)