mirror of
https://github.com/esp8266/Arduino.git
synced 2025-06-12 01:53:07 +03:00
Cleanup base64::encode functions (#6607)
* Cleanup base64::encode functions The implementation choice here using libb64 is generally good as it is a relatively fast implementation, however the adaptation to use PROGMEM for the translation function was a bad choice, as reading randomly PROGMEM with byte-wide access is very very very slow. Doing a naive if-snake is between 20% and 55% faster and uses less flash (about 120 bytes less) and also for reasons I don't understand 8 bytes less data RAM (maybe the removal of static?). In addition the base64::encode function was allocating for larger input a huge amount of memory (twice the total size). we can reduce that by doing a chunk-wise conversation to base64. * 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.
This commit is contained in:
committed by
Earle F. Philhower, III
parent
348c58b644
commit
14262af0d1
@ -319,7 +319,7 @@ bool HTTPClient::beginInternal(const String& __url, const char* expectedProtocol
|
||||
// auth info
|
||||
String auth = host.substring(0, index);
|
||||
host.remove(0, index + 1); // remove auth part including @
|
||||
_base64Authorization = base64::encode(auth);
|
||||
_base64Authorization = base64::encode(auth, false /* doNewLines */);
|
||||
}
|
||||
|
||||
// get port
|
||||
@ -504,7 +504,7 @@ void HTTPClient::setAuthorization(const char * user, const char * password)
|
||||
String auth = user;
|
||||
auth += ':';
|
||||
auth += password;
|
||||
_base64Authorization = base64::encode(auth);
|
||||
_base64Authorization = base64::encode(auth, false /* doNewLines */);
|
||||
}
|
||||
}
|
||||
|
||||
@ -516,6 +516,7 @@ void HTTPClient::setAuthorization(const char * auth)
|
||||
{
|
||||
if(auth) {
|
||||
_base64Authorization = auth;
|
||||
_base64Authorization.replace(String('\n'), emptyString);
|
||||
}
|
||||
}
|
||||
|
||||
@ -1243,7 +1244,6 @@ bool HTTPClient::sendHeader(const char * type)
|
||||
}
|
||||
|
||||
if(_base64Authorization.length()) {
|
||||
_base64Authorization.replace("\n", "");
|
||||
header += F("Authorization: Basic ");
|
||||
header += _base64Authorization;
|
||||
header += "\r\n";
|
||||
|
Reference in New Issue
Block a user