@@ -102,27 +102,34 @@ void HTTPClient::begin(String url, String httpsFingerprint) {
102102 String protocol;
103103 // check for : (http: or https:
104104 int index = url.indexOf (' :' );
105- int index2;
105+ // int index2;
106106 bool hasPort = false ;
107107 if (index) {
108108 protocol = url.substring (0 , index);
109109 url.remove (0 , (index + 3 )); // remove http:// or https://
110110
111- index = url.indexOf (' :' );
112- index2 = url.indexOf (' /' );
113-
114- if (index >= 0 && ((index2 >= 0 && index < index2) || index2 == 0 )) { // do we have a port?
115- _host = url.substring (0 , index); // hostname
116- url.remove (0 , (index + 1 )); // remove hostname + :
111+ index = url.indexOf (' /' );
112+ String host = url.substring (0 , index);
113+ url.remove (0 , index); // remove host part
114+
115+ // get Authorization
116+ index = host.indexOf (' @' );
117+ if (index >= 0 ) {
118+ // auth info
119+ String auth = host.substring (0 , index);
120+ host.remove (0 , index +1 ); // remove auth part including @
121+ _base64Authorization = base64::encode (auth);
122+ }
117123
118- index = url.indexOf (' /' );
119- _port = url.substring (0 , index).toInt (); // get port
120- url.remove (0 , index); // remove port
124+ // get port
125+ index = host.indexOf (' :' );
126+ if (index >= 0 ) {
127+ _host = host.substring (0 , index); // hostname
128+ host.remove (0 , (index + 1 )); // remove hostname + :
129+ _port = host.toInt (); // get port
121130 hasPort = true ;
122131 } else {
123- index = index2;
124- _host = url.substring (0 , index);
125- url.remove (0 , index); // remove hostname
132+ _host = host;
126133 }
127134
128135 _url = url;
@@ -141,6 +148,7 @@ void HTTPClient::begin(String url, String httpsFingerprint) {
141148 DEBUG_HTTPCLIENT (" [HTTP-Client][begin] protocol: %s unknown?!\n " , protocol.c_str ());
142149 return ;
143150 }
151+
144152 }
145153
146154 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) {
235243 }
236244}
237245
246+ /* *
247+ * set the Authorizatio for the http request
248+ * @param auth const char * base64
249+ */
250+ void HTTPClient::setAuthorization (const char * auth) {
251+ if (auth) {
252+ _base64Authorization = auth;
253+ }
254+ }
255+
238256/* *
239257 * send a GET request
240258 * @return http code
0 commit comments