Skip to content

Commit

Permalink
Merge pull request #30 from pf-telos/fix/query-uri-encoding
Browse files Browse the repository at this point in the history
Fix/query uri encoding
  • Loading branch information
JnsHndr authored Jan 17, 2025
2 parents 1dc616c + a4fa670 commit bb9bfec
Showing 1 changed file with 16 additions and 4 deletions.
20 changes: 16 additions & 4 deletions src/pf_driver/src/pf/http_helpers/curl_resource.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#include "pf_driver/pf/http_helpers/curl_resource.h"
#include <curlpp/Infos.hpp>

CurlResource::CurlResource(const std::string& host) : url_("http://" + host)
{
Expand All @@ -17,7 +18,7 @@ void CurlResource::append_query(const std::initializer_list<param_type>& list, b
url_ += "?";
for (const auto& p : list)
{
url_ += p.first + "=" + p.second + "&";
url_ += p.first + "=" + curlpp::escape(p.second) + "&";
}
url_.pop_back();
}
Expand All @@ -27,7 +28,7 @@ void CurlResource::append_query(const param_map_type& params, bool do_encoding)
url_ += "?";
for (const auto& p : params)
{
url_ += p.first + "=" + p.second + "&";
url_ += p.first + "=" + curlpp::escape(p.second) + "&";
}
url_.pop_back();
}
Expand All @@ -37,8 +38,19 @@ void CurlResource::get(Json::Value& json_resp)
request_.setOpt(curlpp::options::Url(url_));
request_.perform();

Json::Reader reader;
reader.parse(response_, json_resp);
long code = curlpp::infos::ResponseCode::get(request_);
if (code == 200)
{
Json::Reader reader;
reader.parse(response_, json_resp);
}
else
{
json_resp.clear();
/* Negate to make HTTP error code distinguishable from PFSDP error codes */
json_resp["error_code"] = Json::Value((Json::Value::Int)-code);
json_resp["error_text"] = Json::Value("HTTP Server Error");
}
}

void CurlResource::print()
Expand Down

0 comments on commit bb9bfec

Please sign in to comment.