Skip to content

Commit 7aa1913

Browse files
committed
Allow HTTPS without certificate to use begin(url)
1 parent 4230aec commit 7aa1913

File tree

1 file changed

+9
-4
lines changed

1 file changed

+9
-4
lines changed

libraries/HTTPClient/src/HTTPClient.cpp

+9-4
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,10 @@ bool HTTPClient::begin(String url, const char* CAcert)
120120
*/
121121
bool HTTPClient::begin(String url)
122122
{
123+
124+
if (beginInternal(url, "https")) {
125+
return begin(url, (const char*)NULL);
126+
}
123127
_transportTraits.reset(nullptr);
124128
_port = 80;
125129
if (!beginInternal(url, "http")) {
@@ -143,6 +147,11 @@ bool HTTPClient::beginInternal(String url, const char* expectedProtocol)
143147
}
144148

145149
_protocol = url.substring(0, index);
150+
if (_protocol != expectedProtocol) {
151+
log_d("[HTTP-Client][begin] unexpected protocol: %s, expected %s", _protocol.c_str(), expectedProtocol);
152+
return false;
153+
}
154+
146155
url.remove(0, (index + 3)); // remove http:// or https://
147156

148157
index = url.indexOf('/');
@@ -168,10 +177,6 @@ bool HTTPClient::beginInternal(String url, const char* expectedProtocol)
168177
_host = host;
169178
}
170179
_uri = url;
171-
if (_protocol != expectedProtocol) {
172-
log_d("[HTTP-Client][begin] unexpected protocol: %s, expected %s", _protocol.c_str(), expectedProtocol);
173-
return false;
174-
}
175180
log_d("[HTTP-Client][begin] host: %s port: %d url: %s", _host.c_str(), _port, _uri.c_str());
176181
return true;
177182
}

0 commit comments

Comments
 (0)