Skip to content

Fix viewer content type header parsing (#4205) #4280

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
May 6, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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);

}
}
Loading