Skip to content

Commit bc59684

Browse files
author
mortee
committed
add raw authorization header option, comes in handy when trying to use Pushetta's (non-standard?) "Token <token>" scheme
1 parent e5746c0 commit bc59684

File tree

2 files changed

+26
-11
lines changed

2 files changed

+26
-11
lines changed

libraries/ESP8266HTTPClient/src/ESP8266HTTPClient.cpp

Lines changed: 24 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -156,7 +156,8 @@ bool HTTPClient::beginInternal(String url, const char* expectedProtocol)
156156
// auth info
157157
String auth = host.substring(0, index);
158158
host.remove(0, index + 1); // remove auth part including @
159-
_base64Authorization = base64::encode(auth);
159+
_rawAuthorization = "Basic ";
160+
_rawAuthorization += base64::encode(auth);
160161
}
161162

162163
// get port
@@ -269,7 +270,7 @@ void HTTPClient::setUserAgent(const String& userAgent)
269270
}
270271

271272
/**
272-
* set the Authorizatio for the http request
273+
* set the Authorization for the http request
273274
* @param user const char *
274275
* @param password const char *
275276
*/
@@ -279,18 +280,31 @@ void HTTPClient::setAuthorization(const char * user, const char * password)
279280
String auth = user;
280281
auth += ":";
281282
auth += password;
282-
_base64Authorization = base64::encode(auth);
283+
_rawAuthorization = "Basic ";
284+
_rawAuthorization += base64::encode(auth);
283285
}
284286
}
285287

286288
/**
287-
* set the Authorizatio for the http request
289+
* set the Authorization for the http request
288290
* @param auth const char * base64
289291
*/
290292
void HTTPClient::setAuthorization(const char * auth)
291293
{
292294
if(auth) {
293-
_base64Authorization = auth;
295+
_rawAuthorization = "Basic ";
296+
_rawAuthorization += auth;
297+
}
298+
}
299+
300+
/**
301+
* set the full raw Authorization header value for the http request
302+
* @param rawAuth const char *
303+
*/
304+
void HTTPClient::setRawAuthorization(const char * rawAuth)
305+
{
306+
if(rawAuth) {
307+
_rawAuthorization = rawAuth;
294308
}
295309
}
296310

@@ -742,7 +756,7 @@ void HTTPClient::addHeader(const String& name, const String& value, bool first,
742756
if(!name.equalsIgnoreCase(F("Connection")) &&
743757
!name.equalsIgnoreCase(F("User-Agent")) &&
744758
!name.equalsIgnoreCase(F("Host")) &&
745-
!(name.equalsIgnoreCase(F("Authorization")) && _base64Authorization.length())){
759+
!(name.equalsIgnoreCase(F("Authorization")) && _rawAuthorization.length())){
746760

747761
String headerLine = name;
748762
headerLine += ": ";
@@ -901,10 +915,10 @@ bool HTTPClient::sendHeader(const char * type)
901915
header += F("Accept-Encoding: identity;q=1,chunked;q=0.1,*;q=0\r\n");
902916
}
903917

904-
if(_base64Authorization.length()) {
905-
_base64Authorization.replace("\n", "");
906-
header += F("Authorization: Basic ");
907-
header += _base64Authorization;
918+
if (_rawAuthorization.length()) {
919+
_rawAuthorization.replace("\n", "");
920+
header += F("Authorization: ");
921+
header += _rawAuthorization;
908922
header += "\r\n";
909923
}
910924

libraries/ESP8266HTTPClient/src/ESP8266HTTPClient.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -148,6 +148,7 @@ class HTTPClient
148148
void setUserAgent(const String& userAgent);
149149
void setAuthorization(const char * user, const char * password);
150150
void setAuthorization(const char * auth);
151+
void setRawAuthorization(const char * rawAuth);
151152
void setTimeout(uint16_t timeout);
152153

153154
void useHTTP10(bool usehttp10 = true);
@@ -213,7 +214,7 @@ class HTTPClient
213214
String _protocol;
214215
String _headers;
215216
String _userAgent = "ESP8266HTTPClient";
216-
String _base64Authorization;
217+
String _rawAuthorization;
217218

218219
/// Response handling
219220
RequestArgument* _currentHeaders = nullptr;

0 commit comments

Comments
 (0)