@@ -102,27 +102,34 @@ void HTTPClient::begin(String url, String httpsFingerprint) {
102
102
String protocol;
103
103
// check for : (http: or https:
104
104
int index = url.indexOf (' :' );
105
- int index2;
105
+ // int index2;
106
106
bool hasPort = false ;
107
107
if (index) {
108
108
protocol = url.substring (0 , index);
109
109
url.remove (0 , (index + 3 )); // remove http:// or https://
110
110
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
+ }
117
123
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
121
130
hasPort = true ;
122
131
} else {
123
- index = index2;
124
- _host = url.substring (0 , index);
125
- url.remove (0 , index); // remove hostname
132
+ _host = host;
126
133
}
127
134
128
135
_url = url;
@@ -141,6 +148,7 @@ void HTTPClient::begin(String url, String httpsFingerprint) {
141
148
DEBUG_HTTPCLIENT (" [HTTP-Client][begin] protocol: %s unknown?!\n " , protocol.c_str ());
142
149
return ;
143
150
}
151
+
144
152
}
145
153
146
154
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) {
235
243
}
236
244
}
237
245
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
+
238
256
/* *
239
257
* send a GET request
240
258
* @return http code
0 commit comments