Skip to content

Commit 817c19e

Browse files
committed
Fix DELETE macro issue on Windows
1 parent f59dd84 commit 817c19e

File tree

17 files changed

+121
-106
lines changed

17 files changed

+121
-106
lines changed

core-framework/include/http/BaseHTTPClient.h

Lines changed: 25 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,31 @@
2929
#include "utils/ByteArrayCallback.h"
3030
#include "utils/gsl.h"
3131

32+
namespace org::apache::nifi::minifi::http {
33+
enum class HttpRequestMethod {
34+
Get, Post, Put, Patch, Delete, Connect, Head, Options, Trace
35+
};
36+
} // namespace org::apache::nifi::minifi::http
37+
38+
namespace magic_enum::customize {
39+
using HttpRequestMethod = org::apache::nifi::minifi::http::HttpRequestMethod;
40+
template<>
41+
constexpr customize_t enum_name<HttpRequestMethod>(HttpRequestMethod type) noexcept {
42+
switch (type) {
43+
case HttpRequestMethod::Get: return "GET";
44+
case HttpRequestMethod::Post: return "POST";
45+
case HttpRequestMethod::Put: return "PUT";
46+
case HttpRequestMethod::Patch: return "PATCH";
47+
case HttpRequestMethod::Delete: return "DELETE";
48+
case HttpRequestMethod::Connect: return "CONNECT";
49+
case HttpRequestMethod::Head: return "HEAD";
50+
case HttpRequestMethod::Options: return "OPTIONS";
51+
case HttpRequestMethod::Trace: return "TRACE";
52+
}
53+
return invalid_tag;
54+
}
55+
} // namespace magic_enum::customize
56+
3257
namespace org::apache::nifi::minifi::http {
3358

3459
struct HTTPProxy {
@@ -177,12 +202,6 @@ namespace HTTPRequestResponse {
177202
int seek_callback(void *p, int64_t offset, int);
178203
}
179204

180-
#undef DELETE // this is a macro in winnt.h
181-
182-
enum class HttpRequestMethod {
183-
GET, POST, PUT, PATCH, DELETE, CONNECT, HEAD, OPTIONS, TRACE
184-
};
185-
186205
class BaseHTTPClient {
187206
public:
188207
BaseHTTPClient() = default;

core-framework/src/http/BaseHTTPClient.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ std::string get_token(BaseHTTPClient* client, const std::string& username, const
6666

6767
client->setContentType("application/x-www-form-urlencoded");
6868

69-
client->set_request_method(HttpRequestMethod::POST);
69+
client->set_request_method(HttpRequestMethod::Post);
7070

7171
std::string payload = "username=" + username + "&" + "password=" + password;
7272

core-framework/src/http/HTTPClient.cpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -255,7 +255,7 @@ void HTTPClient::setReadCallback(std::unique_ptr<HTTPReadCallback> callback) {
255255
void HTTPClient::setUploadCallback(std::unique_ptr<HTTPUploadCallback> callback) {
256256
logger_->log_debug("Setting callback for {}", url_);
257257
write_callback_ = std::move(callback);
258-
if (method_ == http::HttpRequestMethod::PUT) {
258+
if (method_ == http::HttpRequestMethod::Put) {
259259
curl_easy_setopt(http_session_.get(), CURLOPT_INFILESIZE_LARGE, (curl_off_t) write_callback_->size());
260260
}
261261
curl_easy_setopt(http_session_.get(), CURLOPT_READFUNCTION, &HTTPRequestResponse::send_write);
@@ -412,19 +412,19 @@ void HTTPClient::set_request_method(http::HttpRequestMethod method) {
412412
return;
413413
method_ = method;
414414
switch (*method_) {
415-
case http::HttpRequestMethod::POST:
415+
case http::HttpRequestMethod::Post:
416416
curl_easy_setopt(http_session_.get(), CURLOPT_POST, 1L);
417417
curl_easy_setopt(http_session_.get(), CURLOPT_CUSTOMREQUEST, nullptr);
418418
break;
419-
case http::HttpRequestMethod::HEAD:
419+
case http::HttpRequestMethod::Head:
420420
curl_easy_setopt(http_session_.get(), CURLOPT_NOBODY, 1L);
421421
curl_easy_setopt(http_session_.get(), CURLOPT_CUSTOMREQUEST, nullptr);
422422
break;
423-
case http::HttpRequestMethod::GET:
423+
case http::HttpRequestMethod::Get:
424424
curl_easy_setopt(http_session_.get(), CURLOPT_HTTPGET, 1L);
425425
curl_easy_setopt(http_session_.get(), CURLOPT_CUSTOMREQUEST, nullptr);
426426
break;
427-
case http::HttpRequestMethod::PUT:
427+
case http::HttpRequestMethod::Put:
428428
curl_easy_setopt(http_session_.get(), CURLOPT_UPLOAD, 1L);
429429
curl_easy_setopt(http_session_.get(), CURLOPT_CUSTOMREQUEST, nullptr);
430430
break;

0 commit comments

Comments
 (0)