28
28
#include < StreamString.h>
29
29
#include < base64.h>
30
30
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
-
80
31
/* *
81
32
* constructor
82
33
*/
83
34
HTTPClient::HTTPClient ()
84
35
: _client(nullptr ), _userAgent(F(" ESP8266HTTPClient" ))
85
36
{
86
- _tcpDeprecated.reset (nullptr );
87
37
}
88
38
89
39
/* *
@@ -117,12 +67,6 @@ void HTTPClient::clear()
117
67
* @return success bool
118
68
*/
119
69
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
-
126
70
_client = &client;
127
71
128
72
// check for : (http: or https:)
@@ -154,12 +98,6 @@ bool HTTPClient::begin(WiFiClient &client, const String& url) {
154
98
*/
155
99
bool HTTPClient::begin (WiFiClient &client, const String& host, uint16_t port, const String& uri, bool https)
156
100
{
157
- if (_tcpDeprecated) {
158
- DEBUG_HTTPCLIENT (" [HTTP-Client][begin] mix up of new and deprecated api\n " );
159
- _canReuse = false ;
160
- end ();
161
- }
162
-
163
101
_client = &client;
164
102
165
103
clear ();
@@ -171,52 +109,6 @@ bool HTTPClient::begin(WiFiClient &client, const String& host, uint16_t port, co
171
109
}
172
110
173
111
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
-
220
112
bool HTTPClient::beginInternal (const String& __url, const char * expectedProtocol)
221
113
{
222
114
String url (__url);
@@ -278,47 +170,6 @@ bool HTTPClient::beginInternal(const String& __url, const char* expectedProtocol
278
170
}
279
171
280
172
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
-
322
173
/* *
323
174
* end
324
175
* called after the payload is handled
@@ -353,10 +204,6 @@ void HTTPClient::disconnect(bool preserveClient)
353
204
_client = nullptr ;
354
205
}
355
206
}
356
- if (_tcpDeprecated) {
357
- _transportTraits.reset (nullptr );
358
- _tcpDeprecated.reset (nullptr );
359
- }
360
207
}
361
208
} else {
362
209
if (!preserveClient && _client) { // Also destroy _client if not connected()
@@ -460,15 +307,6 @@ bool HTTPClient::setURL(const String& url)
460
307
return beginInternal (url, nullptr );
461
308
}
462
309
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
- }
472
310
/* *
473
311
* set redirect follow mode. See `followRedirects_t` enum for avaliable modes.
474
312
* @param follow
@@ -1116,15 +954,6 @@ bool HTTPClient::connect(void)
1116
954
return true ;
1117
955
}
1118
956
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
-
1128
957
if (!_client) {
1129
958
DEBUG_HTTPCLIENT (" [HTTP-Client] connect: HTTPClient::begin was not called or returned error\n " );
1130
959
return false ;
@@ -1139,12 +968,6 @@ bool HTTPClient::connect(void)
1139
968
1140
969
DEBUG_HTTPCLIENT (" [HTTP-Client] connected to %s:%u\n " , _host.c_str (), _port);
1141
970
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
-
1148
971
#ifdef ESP8266
1149
972
_client->setNoDelay (true );
1150
973
#endif
0 commit comments