From db11d7a4d93d1df4e52aa0c5492a72582aa78f97 Mon Sep 17 00:00:00 2001 From: andrey Date: Thu, 16 Jul 2026 10:01:10 +0300 Subject: [PATCH] refactor: add unified gatherArgument helper for request parsing --- pipeline-runner/src/messageutils.cpp | 7 +++++++ pipeline-runner/src/messageutils.h | 2 ++ pipeline-runner/src/server.cpp | 8 +------- 3 files changed, 10 insertions(+), 7 deletions(-) diff --git a/pipeline-runner/src/messageutils.cpp b/pipeline-runner/src/messageutils.cpp index e908882..61239bc 100644 --- a/pipeline-runner/src/messageutils.cpp +++ b/pipeline-runner/src/messageutils.cpp @@ -28,4 +28,11 @@ PIHTTP::MessageMutable noContent() { return msg; } +PIString gatherArgument(const PIHTTP::MessageConst & request, const PIString & key) { + PIJSON js = PIJSON::fromJSON(PIString::fromUTF8(request.body())); + if (js.contains(key)) return js[key].toString(); + if (request.arguments().contains(key)) return request.arguments().value(key); + return {}; +} + } // namespace MessageUtils diff --git a/pipeline-runner/src/messageutils.h b/pipeline-runner/src/messageutils.h index a4365af..ef67126 100644 --- a/pipeline-runner/src/messageutils.h +++ b/pipeline-runner/src/messageutils.h @@ -12,6 +12,8 @@ PIHTTP::MessageMutable errorReply(PIHTTP::Code code, const PIString & message); PIHTTP::MessageMutable successReply(const PIJSON & json); PIHTTP::MessageMutable noContent(); +PIString gatherArgument(const PIHTTP::MessageConst & request, const PIString & key); + } // namespace MessageUtils #endif diff --git a/pipeline-runner/src/server.cpp b/pipeline-runner/src/server.cpp index 165762e..493174e 100644 --- a/pipeline-runner/src/server.cpp +++ b/pipeline-runner/src/server.cpp @@ -183,13 +183,7 @@ PIHTTP::MessageMutable Server::deletePipeline(const PIHTTP::MessageConst & reque PIHTTP::MessageMutable Server::startRun(const PIHTTP::MessageConst & request) { piCout << "POST /api/runs"; - PIString body = PIString::fromUTF8(request.body()); - PIJSON j = PIJSON::fromJSON(body); - if (!j.isObject()) { - return MessageUtils::errorReply(PIHTTP::Code::BadRequest, "Invalid JSON"); - } - - PIString pipeline_id = j["pipeline_id"].toString(); + PIString pipeline_id = MessageUtils::gatherArgument(request, "pipeline_id"); if (pipeline_id.isEmpty()) { return MessageUtils::errorReply(PIHTTP::Code::BadRequest, "pipeline_id is required"); }