@@ -54,12 +54,12 @@ httpClient::~httpClient() {
54
54
55
55
if (_tcps) {
56
56
_tcps->stop ();
57
- _tcps-> ~WiFiClientSecure () ;
57
+ delete _tcps;
58
58
_tcps = NULL ;
59
59
_tcp = NULL ;
60
60
} else if (_tcp) {
61
61
_tcp->stop ();
62
- _tcp-> ~WiFiClient () ;
62
+ delete _tcp;
63
63
_tcp = NULL ;
64
64
}
65
65
@@ -68,6 +68,78 @@ httpClient::~httpClient() {
68
68
}
69
69
}
70
70
71
+ /* *
72
+ * phasing the url for all needed informations
73
+ * @param url const char *
74
+ * @param httpsFingerprint const char *
75
+ */
76
+ void httpClient::begin (const char *url, const char * httpsFingerprint) {
77
+ begin (String (url), String (httpsFingerprint));
78
+ }
79
+
80
+ /* *
81
+ * phasing the url for all needed informations
82
+ * @param url String
83
+ * @param httpsFingerprint String
84
+ */
85
+ void httpClient::begin (String url, String httpsFingerprint) {
86
+
87
+ DEBUG_HTTPCLIENT (" [HTTP-Client][begin] url: %s\n " , url.c_str ());
88
+
89
+ _httpsFingerprint = httpsFingerprint;
90
+ _returnCode = 0 ;
91
+ _size = -1 ;
92
+
93
+ _Headers = " " ;
94
+
95
+ String protocol;
96
+ // check for : (http: or https:
97
+ int index = url.indexOf (' :' );
98
+ int index2;
99
+ bool hasPort = false ;
100
+ if (index ) {
101
+ protocol = url.substring (0 , index );
102
+ url.remove (0 , (index + 3 )); // remove http:// or https://
103
+
104
+ index = url.indexOf (' :' );
105
+ index2 = url.indexOf (' /' );
106
+
107
+ if (index >= 0 && ((index2 >= 0 && index < index2) || index2 == 0 )) { // do we have a port?
108
+ _host = url.substring (0 , index ); // hostname
109
+ url.remove (0 , (index + 1 )); // remove hostname + :
110
+
111
+ index = url.indexOf (' /' );
112
+ _port = url.substring (0 , index ).toInt (); // get port
113
+ url.remove (0 , index ); // remove port
114
+ hasPort = true ;
115
+ } else {
116
+ index = index2;
117
+ _host = url.substring (0 , index );
118
+ url.remove (0 , index ); // remove hostname
119
+ }
120
+
121
+ _url = url;
122
+
123
+ if (protocol.equalsIgnoreCase (" http" )) {
124
+ _https = false ;
125
+ if (!hasPort) {
126
+ _port = 80 ;
127
+ }
128
+ } else if (protocol.equalsIgnoreCase (" https" )) {
129
+ _https = true ;
130
+ if (!hasPort) {
131
+ _port = 443 ;
132
+ }
133
+ } else {
134
+ DEBUG_HTTPCLIENT (" [HTTP-Client][begin] protocol: %s unknown?!\n " , protocol.c_str ());
135
+ return ;
136
+ }
137
+ }
138
+
139
+ 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 ());
140
+
141
+ }
142
+
71
143
/* *
72
144
* begin
73
145
* @param host const char *
@@ -226,7 +298,6 @@ WiFiClient * httpClient::getStreamPtr(void) {
226
298
return NULL ;
227
299
}
228
300
229
- WiFiClient * getStreamPtr (void );
230
301
/* *
231
302
* write all message body / payload to Stream
232
303
* @param stream Stream *
@@ -378,7 +449,7 @@ bool httpClient::connect(void) {
378
449
if (_https) {
379
450
DEBUG_HTTPCLIENT (" [HTTP-Client] connect https...\n " );
380
451
if (_tcps) {
381
- _tcps-> ~WiFiClient () ;
452
+ delete _tcps;
382
453
_tcps = NULL ;
383
454
_tcp = NULL ;
384
455
}
@@ -387,18 +458,18 @@ bool httpClient::connect(void) {
387
458
} else {
388
459
DEBUG_HTTPCLIENT (" [HTTP-Client] connect http...\n " );
389
460
if (_tcp) {
390
- _tcp-> ~WiFiClient () ;
461
+ delete _tcp;
391
462
_tcp = NULL ;
392
463
}
393
464
_tcp = new WiFiClient ();
394
465
}
395
466
396
467
if (!_tcp->connect (_host.c_str (), _port)) {
397
- DEBUG_HTTPCLIENT (" [HTTP-Client] failed connect to %s:%u. \n " , _host.c_str (), _port);
468
+ DEBUG_HTTPCLIENT (" [HTTP-Client] failed connect to %s:%u\n " , _host.c_str (), _port);
398
469
return false ;
399
470
}
400
471
401
- DEBUG_HTTPCLIENT (" [HTTP-Client] connected to %s:%u. \n " , _host.c_str (), _port);
472
+ DEBUG_HTTPCLIENT (" [HTTP-Client] connected to %s:%u\n " , _host.c_str (), _port);
402
473
403
474
if (_https && _httpsFingerprint.length () > 0 ) {
404
475
if (_tcps->verify (_httpsFingerprint.c_str (), _host.c_str ())) {
0 commit comments