Skip to content

Commit da26de2

Browse files
committed
Create authorisation base64 encoded string without newlines
Rather than first creating a string with newlines and then stripping it away in the fast path of constructing the query, we can call the right method and trust that the result does not have newlines anymore.
1 parent 779820e commit da26de2

File tree

1 file changed

+3
-3
lines changed

1 file changed

+3
-3
lines changed

libraries/ESP8266HTTPClient/src/ESP8266HTTPClient.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -317,7 +317,7 @@ bool HTTPClient::beginInternal(String url, const char* expectedProtocol)
317317
// auth info
318318
String auth = host.substring(0, index);
319319
host.remove(0, index + 1); // remove auth part including @
320-
_base64Authorization = base64::encode(auth);
320+
_base64Authorization = base64::encode(auth, false /* doNewLines */);
321321
}
322322

323323
// get port
@@ -502,7 +502,7 @@ void HTTPClient::setAuthorization(const char * user, const char * password)
502502
String auth = user;
503503
auth += ":";
504504
auth += password;
505-
_base64Authorization = base64::encode(auth);
505+
_base64Authorization = base64::encode(auth, false /* doNewLines */);
506506
}
507507
}
508508

@@ -514,6 +514,7 @@ void HTTPClient::setAuthorization(const char * auth)
514514
{
515515
if(auth) {
516516
_base64Authorization = auth;
517+
_base64Authorization.replace(String('\n'), emptyString);
517518
}
518519
}
519520

@@ -1241,7 +1242,6 @@ bool HTTPClient::sendHeader(const char * type)
12411242
}
12421243

12431244
if(_base64Authorization.length()) {
1244-
_base64Authorization.replace("\n", "");
12451245
header += F("Authorization: Basic ");
12461246
header += _base64Authorization;
12471247
header += "\r\n";

0 commit comments

Comments
 (0)