mirror of
https://github.com/esp8266/Arduino.git
synced 2025-06-12 01:53:07 +03:00
HTTPClient phasing username + password from url
This commit is contained in:
@ -102,27 +102,34 @@ void HTTPClient::begin(String url, String httpsFingerprint) {
|
|||||||
String protocol;
|
String protocol;
|
||||||
// check for : (http: or https:
|
// check for : (http: or https:
|
||||||
int index = url.indexOf(':');
|
int index = url.indexOf(':');
|
||||||
int index2;
|
//int index2;
|
||||||
bool hasPort = false;
|
bool hasPort = false;
|
||||||
if(index) {
|
if(index) {
|
||||||
protocol = url.substring(0, index);
|
protocol = url.substring(0, index);
|
||||||
url.remove(0, (index + 3)); // remove http:// or https://
|
url.remove(0, (index + 3)); // remove http:// or https://
|
||||||
|
|
||||||
index = url.indexOf(':');
|
index = url.indexOf('/');
|
||||||
index2 = url.indexOf('/');
|
String host = url.substring(0, index);
|
||||||
|
url.remove(0, index); // remove host part
|
||||||
|
|
||||||
if(index >= 0 && ((index2 >= 0 && index < index2) || index2 == 0)) { // do we have a port?
|
// get Authorization
|
||||||
_host = url.substring(0, index); // hostname
|
index = host.indexOf('@');
|
||||||
url.remove(0, (index + 1)); // remove hostname + :
|
if(index >= 0) {
|
||||||
|
// auth info
|
||||||
|
String auth = host.substring(0, index);
|
||||||
|
host.remove(0, index +1); // remove auth part including @
|
||||||
|
_base64Authorization = base64::encode(auth);
|
||||||
|
}
|
||||||
|
|
||||||
index = url.indexOf('/');
|
// get port
|
||||||
_port = url.substring(0, index).toInt(); // get port
|
index = host.indexOf(':');
|
||||||
url.remove(0, index); // remove port
|
if(index >= 0) {
|
||||||
|
_host = host.substring(0, index); // hostname
|
||||||
|
host.remove(0, (index + 1)); // remove hostname + :
|
||||||
|
_port = host.toInt(); // get port
|
||||||
hasPort = true;
|
hasPort = true;
|
||||||
} else {
|
} else {
|
||||||
index = index2;
|
_host = host;
|
||||||
_host = url.substring(0, index);
|
|
||||||
url.remove(0, index); // remove hostname
|
|
||||||
}
|
}
|
||||||
|
|
||||||
_url = url;
|
_url = url;
|
||||||
@ -141,6 +148,7 @@ void HTTPClient::begin(String url, String httpsFingerprint) {
|
|||||||
DEBUG_HTTPCLIENT("[HTTP-Client][begin] protocol: %s unknown?!\n", protocol.c_str());
|
DEBUG_HTTPCLIENT("[HTTP-Client][begin] protocol: %s unknown?!\n", protocol.c_str());
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
DEBUG_HTTPCLIENT("[HTTP-Client][begin] host: %s port: %d url: %s https: %d httpsFingerprint: %s\n", _host.c_str(), _port, _url.c_str(), _https, _httpsFingerprint.c_str());
|
DEBUG_HTTPCLIENT("[HTTP-Client][begin] host: %s port: %d url: %s https: %d httpsFingerprint: %s\n", _host.c_str(), _port, _url.c_str(), _https, _httpsFingerprint.c_str());
|
||||||
@ -235,6 +243,16 @@ void HTTPClient::setAuthorization(const char * user, const char * password) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* set the Authorizatio for the http request
|
||||||
|
* @param auth const char * base64
|
||||||
|
*/
|
||||||
|
void HTTPClient::setAuthorization(const char * auth) {
|
||||||
|
if(auth) {
|
||||||
|
_base64Authorization = auth;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* send a GET request
|
* send a GET request
|
||||||
* @return http code
|
* @return http code
|
||||||
|
@ -25,7 +25,7 @@
|
|||||||
#ifndef ESP8266HTTPClient_H_
|
#ifndef ESP8266HTTPClient_H_
|
||||||
#define ESP8266HTTPClient_H_
|
#define ESP8266HTTPClient_H_
|
||||||
|
|
||||||
#define DEBUG_HTTPCLIENT(...) Serial1.printf( __VA_ARGS__ )
|
//#define DEBUG_HTTPCLIENT(...) Serial1.printf( __VA_ARGS__ )
|
||||||
|
|
||||||
#ifndef DEBUG_HTTPCLIENT
|
#ifndef DEBUG_HTTPCLIENT
|
||||||
#define DEBUG_HTTPCLIENT(...)
|
#define DEBUG_HTTPCLIENT(...)
|
||||||
@ -122,6 +122,7 @@ class HTTPClient {
|
|||||||
void setReuse(bool reuse); /// keep-alive
|
void setReuse(bool reuse); /// keep-alive
|
||||||
void setUserAgent(const char * userAgent);
|
void setUserAgent(const char * userAgent);
|
||||||
void setAuthorization(const char * user, const char * password);
|
void setAuthorization(const char * user, const char * password);
|
||||||
|
void setAuthorization(const char * auth);
|
||||||
|
|
||||||
/// request handling
|
/// request handling
|
||||||
int GET();
|
int GET();
|
||||||
|
Reference in New Issue
Block a user