Skip to content

Commit

Permalink
Clean up BuildHeaders()
Browse files Browse the repository at this point in the history
  • Loading branch information
ErikMinekus committed Apr 15, 2021
1 parent e2cff7d commit f9d358f
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 19 deletions.
27 changes: 9 additions & 18 deletions httprequest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,48 +24,38 @@
#include "httpfilecontext.h"

HTTPRequest::HTTPRequest(const std::string &url)
: url(url)
: url(url)
{
SetHeader("Accept", "application/json");
SetHeader("Content-Type", "applicaton/json");
}

void HTTPRequest::Perform(const char *method, json_t *data, IChangeableForward *forward, cell_t value)
{
struct curl_slist *headers = NULL;
headers = this->BuildHeaders(headers);

HTTPRequestContext *context = new HTTPRequestContext(method, this->BuildURL(), data, headers, forward, value,
this->connectTimeout, this->maxRedirects, this->timeout, this->maxSendSpeed, this->maxRecvSpeed,
this->useBasicAuth, this->username, this->password);
HTTPRequestContext *context = new HTTPRequestContext(method, BuildURL(), data, BuildHeaders(), forward, value,
connectTimeout, maxRedirects, timeout, maxSendSpeed, maxRecvSpeed, useBasicAuth, username, password);

g_RipExt.AddRequestToQueue(context);
}

void HTTPRequest::DownloadFile(const char *path, IChangeableForward *forward, cell_t value)
{
struct curl_slist *headers = NULL;
SetHeader("Accept", "*/*");
SetHeader("Content-Type", "application/octet-stream");
headers = this->BuildHeaders(headers);

HTTPFileContext *context = new HTTPFileContext(false, this->BuildURL(), path, headers, forward, value,
this->connectTimeout, this->maxRedirects, this->timeout, this->maxSendSpeed, this->maxRecvSpeed,
this->useBasicAuth, this->username, this->password);
HTTPFileContext *context = new HTTPFileContext(false, BuildURL(), path, BuildHeaders(), forward, value,
connectTimeout, maxRedirects, timeout, maxSendSpeed, maxRecvSpeed, useBasicAuth, username, password);

g_RipExt.AddRequestToQueue(context);
}

void HTTPRequest::UploadFile(const char *path, IChangeableForward *forward, cell_t value)
{
struct curl_slist *headers = NULL;
SetHeader("Accept", "*/*");
SetHeader("Content-Type", "application/octet-stream");
headers = this->BuildHeaders(headers);

HTTPFileContext *context = new HTTPFileContext(true, this->BuildURL(), path, headers, forward, value,
this->connectTimeout, this->maxRedirects, this->timeout, this->maxSendSpeed, this->maxRecvSpeed,
this->useBasicAuth, this->username, this->password);
HTTPFileContext *context = new HTTPFileContext(true, BuildURL(), path, BuildHeaders(), forward, value,
connectTimeout, maxRedirects, timeout, maxSendSpeed, maxRecvSpeed, useBasicAuth, username, password);

g_RipExt.AddRequestToQueue(context);
}
Expand Down Expand Up @@ -102,8 +92,9 @@ void HTTPRequest::AppendQueryParam(const char *name, const char *value)
curl_easy_cleanup(curl);
}

struct curl_slist *HTTPRequest::BuildHeaders(struct curl_slist *headers)
struct curl_slist *HTTPRequest::BuildHeaders()
{
struct curl_slist *headers = NULL;
char header[8192];

for (HTTPHeaderMap::iterator iter = this->headers.iter(); !iter.empty(); iter.next())
Expand Down
2 changes: 1 addition & 1 deletion httprequest.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ class HTTPRequest
const std::string BuildURL() const;
void AppendQueryParam(const char *name, const char *value);

struct curl_slist *BuildHeaders(struct curl_slist *headers);
struct curl_slist *BuildHeaders();
void SetHeader(const char *name, const char *value);

bool UseBasicAuth() const;
Expand Down

0 comments on commit f9d358f

Please sign in to comment.