11#include " Fetch.h"
22#include < WiFiClientSecure.h>
33
4- // Fetch fetch;
5-
64Response fetch (const char * url, RequestOptions options) {
75 // Parsing URL.
86 Url parsedUrl = parseUrl (url);
@@ -14,10 +12,11 @@ Response fetch(const char* url, RequestOptions options) {
1412 // Set fingerprint if https.
1513 if (parsedUrl.scheme == " https" ) {
1614 #ifdef ESP8266
17- if (options.fingerprint == " " ) {
18- Serial.println (" [INFO] No fingerprint is provided. Using the INSECURE mode for connection!" );
15+ if (options.fingerprint == " " && options. caCert == " " ) {
16+ Serial.println (" [INFO] No fingerprint or caCert is provided. Using the INSECURE mode for connection!" );
1917 client.setInsecure ();
2018 }
19+ else if (options.caCert != " " ) client.setTrustAnchors (new X509List (options.caCert .c_str ()));
2120 else client.setFingerprint (options.fingerprint .c_str ());
2221 #elif defined(ESP32)
2322 if (options.caCert == " " ) {
@@ -31,7 +30,7 @@ Response fetch(const char* url, RequestOptions options) {
3130 // Connecting to server.
3231 while (!client.connect (parsedUrl.host .c_str (), parsedUrl.port )) {
3332 delay (1000 );
34- // Serial.print(".");
33+ Serial.print (" ." );
3534 }
3635
3736 // Forming request.
@@ -43,8 +42,8 @@ Response fetch(const char* url, RequestOptions options) {
4342 " Connection: " + options.headers .connection + " \r\n\r\n " +
4443 options.body + " \r\n\r\n " ;
4544
46- // Serial.println("Request is: ");
47- // Serial.println(request);
45+ Serial.println (" Request is: " );
46+ Serial.println (request);
4847
4948 // Sending request.
5049 client.print (request);
@@ -67,9 +66,9 @@ Response fetch(const char* url, RequestOptions options) {
6766 if (line == " \r " ) break ;
6867 }
6968
70- // Serial.println("-----HEADERS START-----");
71- // Serial.println(response.headers.text);
72- // Serial.println("-----HEADERS END-----");
69+ Serial.println (" -----HEADERS START-----" );
70+ Serial.println (response.headers .text );
71+ Serial.println (" -----HEADERS END-----" );
7372
7473 // Getting response body.
7574 while (client.available ()) {
@@ -108,9 +107,6 @@ String operator+(String str, Body body) {
108107 return str + body.text ();
109108}
110109
111- // Fetch::Fetch(const char* url, RequestOptions options) :
112- // _url(url), _options(options) {}
113-
114110Response::Response (): ok(false ), status(200 ), statusText(" OK" ),
115111 redirected(false ), type(" " ), headers(ResponseHeaders()), body(" " ) {}
116112
0 commit comments