Skip to content

Commit

Permalink
Bugfix: User defined headers and URL encoded parameters must be clear…
Browse files Browse the repository at this point in the history
…ed in begin().
  • Loading branch information
BlueAndi committed Sep 8, 2020
1 parent caedf40 commit 05a983c
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 0 deletions.
12 changes: 12 additions & 0 deletions src/Web/AsyncHttpClient.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,8 @@ bool AsyncHttpClient::begin(const String& url)
{
int begin = 0;

clear();

/* Get protocol http or https */
String protocol = url.substring(begin, index);
begin = index + 3; /* Overstep '://' too. */
Expand Down Expand Up @@ -298,6 +300,11 @@ void AsyncHttpClient::addHeader(const String& name, const String& value)
}
}

void AsyncHttpClient::clearHeader()
{
m_headers.clear();
}

void AsyncHttpClient::addPar(const String& name, const String& value)
{
/* Name must be given, value could be empty. */
Expand All @@ -314,6 +321,11 @@ void AsyncHttpClient::addPar(const String& name, const String& value)
}
}

void AsyncHttpClient::clearPar()
{
m_urlEncodedPars.clear();
}

void AsyncHttpClient::regOnResponse(const OnResponse& onResponse)
{
m_onRspCallback = onResponse;
Expand Down
11 changes: 11 additions & 0 deletions src/Web/AsyncHttpClient.h
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,7 @@ class AsyncHttpClient

/**
* Parse all necessary parameters from URL and prepare for sending requests.
* Note, calling this will clear user defined headers and URL encoded parameters.
*
* @param[in] url URL
*
Expand Down Expand Up @@ -149,6 +150,11 @@ class AsyncHttpClient
*/
void addHeader(const String& name, const String& value);

/**
* Clear user defined request headers.
*/
void clearHeader();

/**
* Add parameter to request (application/x-www-form-urlencoded).
*
Expand All @@ -161,6 +167,11 @@ class AsyncHttpClient
*/
void addPar(const String& name, const String& value);

/**
* Clear URL encoded parameters.
*/
void clearPar();

/**
* Register callback function on response reception.
*
Expand Down

0 comments on commit 05a983c

Please sign in to comment.