From 05a983cf893162ceb9608746a353fa714af5be32 Mon Sep 17 00:00:00 2001 From: Andreas Merkle Date: Tue, 8 Sep 2020 20:46:35 +0200 Subject: [PATCH] Bugfix: User defined headers and URL encoded parameters must be cleared in begin(). --- src/Web/AsyncHttpClient.cpp | 12 ++++++++++++ src/Web/AsyncHttpClient.h | 11 +++++++++++ 2 files changed, 23 insertions(+) diff --git a/src/Web/AsyncHttpClient.cpp b/src/Web/AsyncHttpClient.cpp index aad24331..512ce5dc 100644 --- a/src/Web/AsyncHttpClient.cpp +++ b/src/Web/AsyncHttpClient.cpp @@ -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. */ @@ -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. */ @@ -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; diff --git a/src/Web/AsyncHttpClient.h b/src/Web/AsyncHttpClient.h index 0b6b0535..0925c4df 100644 --- a/src/Web/AsyncHttpClient.h +++ b/src/Web/AsyncHttpClient.h @@ -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 * @@ -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). * @@ -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. *