Skip to content

Commit ec017a1

Browse files
authored
Fix viewer content type header parsing (#4205) (#4280)
Changelog entry According to HTTP 1.1 header name must be case insensitive Changelog category Bugfix
1 parent be2fb17 commit ec017a1

File tree

3 files changed

+20
-13
lines changed

3 files changed

+20
-13
lines changed

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
@@ -83,5 +83,22 @@ IActor* CreateViewerRequestHandler(TEvViewer::TEvViewerRequest::TPtr& request) {
8383
return nullptr;
8484
}
8585

86+
bool IsPostContent(const NMon::TEvHttpInfo::TPtr& event) {
87+
if (event->Get()->Request.GetMethod() == HTTP_METHOD_POST) {
88+
const THttpHeaders& headers = event->Get()->Request.GetHeaders();
89+
90+
auto itContentType = FindIf(headers, [](const auto& header) {
91+
return AsciiEqualsIgnoreCase(header.Name(), "Content-Type");
92+
});
93+
94+
if (itContentType != headers.end()) {
95+
TStringBuf contentTypeHeader = itContentType->Value();
96+
TStringBuf contentType = contentTypeHeader.NextTok(';');
97+
return contentType == "application/json";
98+
}
99+
}
100+
return false;
101+
}
102+
86103
}
87104
}

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
}

0 commit comments

Comments
 (0)