Skip to content

Commit f542175

Browse files
authored
httpclient: remove deprecated API (#7617)
1 parent 37ef41c commit f542175

File tree

2 files changed

+6
-189
lines changed

2 files changed

+6
-189
lines changed

libraries/ESP8266HTTPClient/src/ESP8266HTTPClient.cpp

-177
Original file line numberDiff line numberDiff line change
@@ -28,62 +28,12 @@
2828
#include <StreamString.h>
2929
#include <base64.h>
3030

31-
class TransportTraits
32-
{
33-
public:
34-
virtual ~TransportTraits()
35-
{
36-
}
37-
38-
virtual std::unique_ptr<WiFiClient> create()
39-
{
40-
return std::unique_ptr<WiFiClient>(new WiFiClient());
41-
}
42-
43-
virtual bool verify(WiFiClient& client, const char* host)
44-
{
45-
(void)client;
46-
(void)host;
47-
return true;
48-
}
49-
};
50-
51-
52-
class BearSSLTraits : public TransportTraits
53-
{
54-
public:
55-
BearSSLTraits(const uint8_t fingerprint[20])
56-
{
57-
memcpy(_fingerprint, fingerprint, sizeof(_fingerprint));
58-
}
59-
60-
std::unique_ptr<WiFiClient> create() override
61-
{
62-
BearSSL::WiFiClientSecure *client = new BearSSL::WiFiClientSecure();
63-
client->setFingerprint(_fingerprint);
64-
return std::unique_ptr<WiFiClient>(client);
65-
}
66-
67-
bool verify(WiFiClient& client, const char* host) override
68-
{
69-
// No-op. BearSSL will not connect if the fingerprint doesn't match.
70-
// So if you get to here you've already connected and it matched
71-
(void) client;
72-
(void) host;
73-
return true;
74-
}
75-
76-
protected:
77-
uint8_t _fingerprint[20];
78-
};
79-
8031
/**
8132
* constructor
8233
*/
8334
HTTPClient::HTTPClient()
8435
: _client(nullptr), _userAgent(F("ESP8266HTTPClient"))
8536
{
86-
_tcpDeprecated.reset(nullptr);
8737
}
8838

8939
/**
@@ -117,12 +67,6 @@ void HTTPClient::clear()
11767
* @return success bool
11868
*/
11969
bool HTTPClient::begin(WiFiClient &client, const String& url) {
120-
if(_tcpDeprecated) {
121-
DEBUG_HTTPCLIENT("[HTTP-Client][begin] mix up of new and deprecated api\n");
122-
_canReuse = false;
123-
end();
124-
}
125-
12670
_client = &client;
12771

12872
// check for : (http: or https:)
@@ -154,12 +98,6 @@ bool HTTPClient::begin(WiFiClient &client, const String& url) {
15498
*/
15599
bool HTTPClient::begin(WiFiClient &client, const String& host, uint16_t port, const String& uri, bool https)
156100
{
157-
if(_tcpDeprecated) {
158-
DEBUG_HTTPCLIENT("[HTTP-Client][begin] mix up of new and deprecated api\n");
159-
_canReuse = false;
160-
end();
161-
}
162-
163101
_client = &client;
164102

165103
clear();
@@ -171,52 +109,6 @@ bool HTTPClient::begin(WiFiClient &client, const String& host, uint16_t port, co
171109
}
172110

173111

174-
bool HTTPClient::begin(String url, const uint8_t httpsFingerprint[20])
175-
{
176-
if(_client && !_tcpDeprecated) {
177-
DEBUG_HTTPCLIENT("[HTTP-Client][begin] mix up of new and deprecated api\n");
178-
_canReuse = false;
179-
end();
180-
}
181-
182-
if (!beginInternal(url, "https")) {
183-
return false;
184-
}
185-
_transportTraits = TransportTraitsPtr(new (std::nothrow) BearSSLTraits(httpsFingerprint));
186-
if(!_transportTraits) {
187-
DEBUG_HTTPCLIENT("[HTTP-Client][begin] could not create transport traits\n");
188-
return false;
189-
}
190-
191-
DEBUG_HTTPCLIENT("[HTTP-Client][begin] BearSSL-httpsFingerprint:");
192-
for (size_t i=0; i < 20; i++) {
193-
DEBUG_HTTPCLIENT(" %02x", httpsFingerprint[i]);
194-
}
195-
DEBUG_HTTPCLIENT("\n");
196-
return true;
197-
}
198-
199-
200-
/**
201-
* parsing the url for all needed parameters
202-
* @param url String
203-
*/
204-
bool HTTPClient::begin(String url)
205-
{
206-
if(_client && !_tcpDeprecated) {
207-
DEBUG_HTTPCLIENT("[HTTP-Client][begin] mix up of new and deprecated api\n");
208-
_canReuse = false;
209-
end();
210-
}
211-
212-
if (!beginInternal(url, "http")) {
213-
return false;
214-
}
215-
_transportTraits = TransportTraitsPtr(new TransportTraits());
216-
return true;
217-
}
218-
219-
220112
bool HTTPClient::beginInternal(const String& __url, const char* expectedProtocol)
221113
{
222114
String url(__url);
@@ -278,47 +170,6 @@ bool HTTPClient::beginInternal(const String& __url, const char* expectedProtocol
278170
}
279171

280172

281-
bool HTTPClient::begin(String host, uint16_t port, String uri)
282-
{
283-
if(_client && !_tcpDeprecated) {
284-
DEBUG_HTTPCLIENT("[HTTP-Client][begin] mix up of new and deprecated api\n");
285-
_canReuse = false;
286-
end();
287-
}
288-
289-
clear();
290-
_host = host;
291-
_port = port;
292-
_uri = uri;
293-
_transportTraits = TransportTraitsPtr(new TransportTraits());
294-
DEBUG_HTTPCLIENT("[HTTP-Client][begin] host: %s port: %d uri: %s\n", host.c_str(), port, uri.c_str());
295-
return true;
296-
}
297-
298-
299-
bool HTTPClient::begin(String host, uint16_t port, String uri, const uint8_t httpsFingerprint[20])
300-
{
301-
if(_client && !_tcpDeprecated) {
302-
DEBUG_HTTPCLIENT("[HTTP-Client][begin] mix up of new and deprecated api\n");
303-
_canReuse = false;
304-
end();
305-
}
306-
307-
clear();
308-
_host = host;
309-
_port = port;
310-
_uri = uri;
311-
312-
_transportTraits = TransportTraitsPtr(new BearSSLTraits(httpsFingerprint));
313-
DEBUG_HTTPCLIENT("[HTTP-Client][begin] host: %s port: %d url: %s BearSSL-httpsFingerprint:", host.c_str(), port, uri.c_str());
314-
for (size_t i=0; i < 20; i++) {
315-
DEBUG_HTTPCLIENT(" %02x", httpsFingerprint[i]);
316-
}
317-
DEBUG_HTTPCLIENT("\n");
318-
return true;
319-
}
320-
321-
322173
/**
323174
* end
324175
* called after the payload is handled
@@ -353,10 +204,6 @@ void HTTPClient::disconnect(bool preserveClient)
353204
_client = nullptr;
354205
}
355206
}
356-
if(_tcpDeprecated) {
357-
_transportTraits.reset(nullptr);
358-
_tcpDeprecated.reset(nullptr);
359-
}
360207
}
361208
} else {
362209
if (!preserveClient && _client) { // Also destroy _client if not connected()
@@ -460,15 +307,6 @@ bool HTTPClient::setURL(const String& url)
460307
return beginInternal(url, nullptr);
461308
}
462309

463-
/**
464-
* set true to follow redirects.
465-
* @param follow
466-
* @deprecated
467-
*/
468-
void HTTPClient::setFollowRedirects(bool follow)
469-
{
470-
_followRedirects = follow ? HTTPC_STRICT_FOLLOW_REDIRECTS : HTTPC_DISABLE_FOLLOW_REDIRECTS;
471-
}
472310
/**
473311
* set redirect follow mode. See `followRedirects_t` enum for avaliable modes.
474312
* @param follow
@@ -1116,15 +954,6 @@ bool HTTPClient::connect(void)
1116954
return true;
1117955
}
1118956

1119-
if(!_client && _transportTraits) {
1120-
_tcpDeprecated = _transportTraits->create();
1121-
if(!_tcpDeprecated) {
1122-
DEBUG_HTTPCLIENT("[HTTP-Client] connect: could not create tcp\n");
1123-
return false;
1124-
}
1125-
_client = _tcpDeprecated.get();
1126-
}
1127-
1128957
if(!_client) {
1129958
DEBUG_HTTPCLIENT("[HTTP-Client] connect: HTTPClient::begin was not called or returned error\n");
1130959
return false;
@@ -1139,12 +968,6 @@ bool HTTPClient::connect(void)
1139968

1140969
DEBUG_HTTPCLIENT("[HTTP-Client] connected to %s:%u\n", _host.c_str(), _port);
1141970

1142-
if (_tcpDeprecated && !_transportTraits->verify(*_tcpDeprecated, _host.c_str())) {
1143-
DEBUG_HTTPCLIENT("[HTTP-Client] transport level verify failed\n");
1144-
_client->stop();
1145-
return false;
1146-
}
1147-
1148971
#ifdef ESP8266
1149972
_client->setNoDelay(true);
1150973
#endif

libraries/ESP8266HTTPClient/src/ESP8266HTTPClient.h

+6-12
Original file line numberDiff line numberDiff line change
@@ -163,14 +163,12 @@ class HTTPClient
163163
bool begin(WiFiClient &client, const String& url);
164164
bool begin(WiFiClient &client, const String& host, uint16_t port, const String& uri = "/", bool https = false);
165165

166-
// Plain HTTP connection, unencrypted
167-
bool begin(String url) __attribute__ ((deprecated));
168-
bool begin(String host, uint16_t port, String uri = "/") __attribute__ ((deprecated));
169-
// Use BearSSL for secure HTTPS connection
170-
bool begin(String url, const uint8_t httpsFingerprint[20]) __attribute__ ((deprecated));
171-
bool begin(String host, uint16_t port, String uri, const uint8_t httpsFingerprint[20]) __attribute__ ((deprecated));
172-
// deprecated, use the overload above instead
173-
bool begin(String host, uint16_t port, String uri, bool https, String httpsFingerprint) __attribute__ ((deprecated));
166+
// old API is now explicitely forbidden
167+
bool begin(String url) __attribute__ ((error("obsolete API, use ::begin(WiFiClient, url)")));
168+
bool begin(String host, uint16_t port, String uri = "/") __attribute__ ((error("obsolete API, use ::begin(WiFiClient, host, port, uri)")));
169+
bool begin(String url, const uint8_t httpsFingerprint[20]) __attribute__ ((error("obsolete API, use ::begin(WiFiClientSecure, ...)")));
170+
bool begin(String host, uint16_t port, String uri, const uint8_t httpsFingerprint[20]) __attribute__ ((error("obsolete API, use ::begin(WiFiClientSecure, ...)")));
171+
bool begin(String host, uint16_t port, String uri, bool https, String httpsFingerprint) __attribute__ ((error("obsolete API, use ::begin(WiFiClientSecure, ...)")));
174172

175173
void end(void);
176174

@@ -183,7 +181,6 @@ class HTTPClient
183181
void setTimeout(uint16_t timeout);
184182

185183
// Redirections
186-
void setFollowRedirects(bool follow) __attribute__ ((deprecated));
187184
void setFollowRedirects(followRedirects_t follow);
188185
void setRedirectLimit(uint16_t limit); // max redirects to follow for a single request
189186

@@ -237,9 +234,6 @@ class HTTPClient
237234
int handleHeaderResponse();
238235
int writeToStreamDataBlock(Stream * stream, int len);
239236

240-
241-
TransportTraitsPtr _transportTraits;
242-
std::unique_ptr<WiFiClient> _tcpDeprecated;
243237
WiFiClient* _client;
244238

245239
/// request handling

0 commit comments

Comments
 (0)