Skip to content

Support for multipart requests, new ways of routing the request to MP graph #3250

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

Open
wants to merge 25 commits into
base: main
Choose a base branch
from
Open
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
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -36,3 +36,4 @@ out
*.errors.txt
tmp/
*.zip
*.tar.gz
42 changes: 40 additions & 2 deletions src/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -615,8 +615,14 @@ cc_library(
"//src/embeddings:embeddingscalculator",
"//src/rerank:rerankcalculator",],
}) + select({
"//:enable_drogon": ["libdrogon_http_server"],
"//conditions:default" : ["libnet_http_server"],
"//:enable_drogon": [
"libdrogon_http_server",
"libovmsmulti_part_parser_drogon_impl",
],
"//conditions:default" : [
"libnet_http_server",
# TODO
],
}) + [
"cpp_headers",
"ovms_header",
Expand Down Expand Up @@ -810,6 +816,7 @@ cc_library(
deps = [
"@com_github_tencent_rapidjson//:rapidjson",
"libovmsclient_connection",
"libovmsmulti_part_parser",
],
visibility = ["//visibility:public"],
copts = COPTS_ADJUSTED,
Expand All @@ -828,6 +835,7 @@ cc_library(
linkopts = LINKOPTS_ADJUSTED,
alwayslink = 1,
)

cc_library(
name = "libhttpclientconnection",
hdrs = ["http_frontend/http_client_connection.hpp"],
Expand All @@ -842,6 +850,33 @@ cc_library(
alwayslink = 1,
)

cc_library(
name = "libovmsmulti_part_parser",
hdrs = ["multi_part_parser.hpp"],
deps = [
],
visibility = ["//visibility:public",],
local_defines = COMMON_LOCAL_DEFINES,
copts = COPTS_ADJUSTED,
linkopts = LINKOPTS_ADJUSTED,
alwayslink = 1,
)

cc_library(
name = "libovmsmulti_part_parser_drogon_impl",
hdrs = ["http_frontend/multi_part_parser_drogon_impl.hpp"],
srcs = ["http_frontend/multi_part_parser_drogon_impl.cpp"],
deps = [
"libovmsmulti_part_parser",
"@drogon//:drogon_cmake",
],
visibility = ["//visibility:public",],
local_defines = COMMON_LOCAL_DEFINES,
copts = COPTS_ADJUSTED,
linkopts = LINKOPTS_ADJUSTED,
alwayslink = 1,
)

cc_library(
name = "libovms_module",
hdrs = ["module.hpp"],
Expand Down Expand Up @@ -2756,6 +2791,7 @@ cc_test(
"test/get_mediapipe_graph_metadata_response_test.cpp",
"test/mediapipe_framework_test.cpp",
"test/http_openai_handler_test.cpp",
"test/multipart_calculator_test.cpp",
],
"//:disable_mediapipe" : [
"test/disabled_mediapipe_test.cpp",
Expand Down Expand Up @@ -2823,6 +2859,7 @@ cc_test(
"test/mediapipe/config_mediapipe_graph_with_side_packets.json",
"test/mediapipe/config_mediapipe_two_inputs.json",
"test/mediapipe/config_mediapipe_two_outputs_dag.json",
"test/mediapipe/config_mediapipe_multipart_mock.json",
"test/mediapipe/config_mp_tf_passthrough.json",
"test/mediapipe/config_standard_add.json",
"test/mediapipe/config_standard_dummy.json",
Expand All @@ -2841,6 +2878,7 @@ cc_test(
"test/mediapipe/graphdummyadapterfull_dummyinputnames.pbtxt",
"test/mediapipe/graphadapterfull_two_outputs_dag.pbtxt",
"test/mediapipe/graphdummyadapterfull_two_outputs.pbtxt",
"test/mediapipe/graph_multipart.pbtxt",
"test/mediapipe/negative/config_exception_during_process.json",
"test/mediapipe/negative/config_no_calc_output_stream.json",
"test/mediapipe/negative/graph_exception_during_process.pbtxt",
Expand Down
42 changes: 42 additions & 0 deletions src/http_frontend/multi_part_parser_drogon_impl.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
//*****************************************************************************
// Copyright 2025 Intel Corporation
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//*****************************************************************************
#include "multi_part_parser_drogon_impl.hpp"

namespace ovms {

// TODO (dkalinow): Test actual drogon parser with mocked request
bool DrogonMultiPartParser::parse() {
this->hasParseError_ = this->parser->parse(request) != 0;
return !this->hasParseError_;
}

bool DrogonMultiPartParser::hasParseError() const {
return this->hasParseError_;
}

std::string DrogonMultiPartParser::getFieldByName(const std::string& name) const {
return this->parser->getParameter<std::string>(name);
}

std::string_view DrogonMultiPartParser::getFileContentByName(const std::string& name) const {
auto it = this->parser->getFilesMap().find(name);
if (it == this->parser->getFilesMap().end()) {
return "";
}
return it->second.fileContent();
}

} // namespace ovms
49 changes: 49 additions & 0 deletions src/http_frontend/multi_part_parser_drogon_impl.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
//*****************************************************************************
// Copyright 2024 Intel Corporation
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//*****************************************************************************
#pragma once

#include "../multi_part_parser.hpp"

#pragma warning(push)
#pragma warning(disable : 6326)
#include <drogon/drogon.h>
#pragma warning(pop)

#include <string>
#include <string_view>
#include <memory>

namespace ovms {

class DrogonMultiPartParser : public MultiPartParser {
bool hasParseError_{true};
const drogon::HttpRequestPtr request{nullptr};
const std::shared_ptr<drogon::MultiPartParser> parser{nullptr};

public:
DrogonMultiPartParser(const drogon::HttpRequestPtr& request) :
request(request),
parser(std::make_shared<drogon::MultiPartParser>()) {}

bool parse() override;

bool hasParseError() const override;

std::string getFieldByName(const std::string& name) const override;
std::string_view getFileContentByName(const std::string& name) const override;
};

} // namespace ovms
5 changes: 4 additions & 1 deletion src/http_payload.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@

#include <memory>
#include <string>
#include <unordered_map>
#include <utility>
#include <vector>
#pragma warning(push)
Expand All @@ -25,15 +26,17 @@
#pragma warning(pop)

#include "client_connection.hpp"
#include "multi_part_parser.hpp"

namespace ovms {

struct HttpPayload {
std::string uri;
std::vector<std::pair<std::string, std::string>> headers;
std::unordered_map<std::string, std::string> headers;
std::string body; // always
std::shared_ptr<rapidjson::Document> parsedJson; // pre-parsed body = null
std::shared_ptr<ClientConnection> client;
std::shared_ptr<MultiPartParser> multipartParser;
};

} // namespace ovms
Loading