Skip to content

Commit

Permalink
Fix viewer content type header parsing (ydb-platform#4205)
Browse files Browse the repository at this point in the history
Changelog entry

According to HTTP 1.1 header nama must be case insensitive

Changelog category

Bugfix
  • Loading branch information
dcherednik committed May 1, 2024
1 parent eba8317 commit 63f1161
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 13 deletions.
15 changes: 2 additions & 13 deletions ydb/core/viewer/json_query.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
#pragma once
#include "viewer.h"
#include <unordered_map>
#include <ydb/library/actors/core/actor_bootstrapped.h>
#include <ydb/library/actors/core/interconnect.h>
#include <ydb/library/actors/core/mon.h>
Expand All @@ -12,7 +11,6 @@
#include <ydb/core/kqp/common/kqp.h>
#include <ydb/core/kqp/executer_actor/kqp_executer.h>
#include <ydb/core/viewer/json/json.h>
//#include <ydb/public/lib/deprecated/kicli/kicli.h>
#include <ydb/public/lib/json_value/ydb_json_value.h>
#include <ydb/public/sdk/cpp/client/ydb_result/result.h>
#include "json_pipe_req.h"
Expand Down Expand Up @@ -102,17 +100,8 @@ class TJsonQuery : public TViewerPipeClient<TJsonQuery> {
}
}

bool IsPostContent() {
if (Event->Get()->Request.GetMethod() == HTTP_METHOD_POST) {
const THttpHeaders& headers = Event->Get()->Request.GetHeaders();
auto itContentType = FindIf(headers, [](const auto& header) { return header.Name() == "Content-Type"; });
if (itContentType != headers.end()) {
TStringBuf contentTypeHeader = itContentType->Value();
TStringBuf contentType = contentTypeHeader.NextTok(';');
return contentType == "application/json";
}
}
return false;
bool IsPostContent() const {
return NViewer::IsPostContent(Event);
}

TJsonQuery(IViewer* viewer, NMon::TEvHttpInfo::TPtr& ev)
Expand Down
17 changes: 17 additions & 0 deletions ydb/core/viewer/viewer_request.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -83,5 +83,22 @@ IActor* CreateViewerRequestHandler(TEvViewer::TEvViewerRequest::TPtr& request) {
return nullptr;
}

bool IsPostContent(const NMon::TEvHttpInfo::TPtr& event) {
if (event->Get()->Request.GetMethod() == HTTP_METHOD_POST) {
const THttpHeaders& headers = event->Get()->Request.GetHeaders();

auto itContentType = FindIf(headers, [](const auto& header) {
return AsciiEqualsIgnoreCase(header.Name(), "Content-Type");
});

if (itContentType != headers.end()) {
TStringBuf contentTypeHeader = itContentType->Value();
TStringBuf contentType = contentTypeHeader.NextTok(';');
return contentType == "application/json";
}
}
return false;
}

}
}
1 change: 1 addition & 0 deletions ydb/core/viewer/viewer_request.h
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ union ViewerWhiteboardCookie {
};

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

}
}

0 comments on commit 63f1161

Please sign in to comment.