11#include < Arduino.h>
22
33#include < WiFi.h>
4- #include < assert.h>
54#include < HTTPClient.h>
65
7- #define USE_SERIAL Serial
8-
96// Enable or disable collecting all headers
107#define COLLECT_ALL_HEADERS true
118
129void setup () {
1310
14- USE_SERIAL .begin (115200 );
11+ Serial .begin (115200 );
1512
16- USE_SERIAL .println ();
17- USE_SERIAL .println ();
18- USE_SERIAL .println ();
13+ Serial .println ();
14+ Serial .println ();
15+ Serial .println ();
1916
2017 for (uint8_t t = 4 ; t > 0 ; t--) {
21- USE_SERIAL .printf (" [SETUP] WAIT %d...\n " , t);
22- USE_SERIAL .flush ();
18+ Serial .printf (" [SETUP] WAIT %d...\n " , t);
19+ Serial .flush ();
2320 delay (1000 );
2421 }
2522
2623 WiFi.begin (" SSID" , " PASSWORD" );
2724
2825 while (WiFi.status () != WL_CONNECTED) {
2926 delay (500 );
30- USE_SERIAL .print (" ." );
27+ Serial .print (" ." );
3128 }
32- USE_SERIAL .println ();
33- USE_SERIAL .println (" Connected to WiFi: " + WiFi.SSID ());
29+ Serial .println ();
30+ Serial .println (" Connected to WiFi: " + WiFi.SSID ());
3431}
3532
3633void loop () {
3734
3835 HTTPClient http;
3936
40- USE_SERIAL .print (" [HTTP] Preparing HTTP request...\n " );
37+ Serial .print (" [HTTP] Preparing HTTP request...\n " );
4138 // This page will return the headers we want to test + some others
4239 http.begin (" https://httpbingo.org/response-headers?x-custom-header=value:42" );
4340
@@ -51,32 +48,32 @@ void loop() {
5148 http.collectHeaders (headerKeys, headerKeysCount);
5249#endif
5350
54- USE_SERIAL .print (" [HTTP] Sending HTTP GET request...\n " );
51+ Serial .print (" [HTTP] Sending HTTP GET request...\n " );
5552 // start connection and send HTTP header
5653 int httpCode = http.GET ();
5754
5855 // httpCode will be negative on error
5956 if (httpCode > 0 ) {
6057 // HTTP header has been send and Server response header has been handled
61- USE_SERIAL .printf (" [HTTP] GET response code: %d\n " , httpCode);
58+ Serial .printf (" [HTTP] GET response code: %d\n " , httpCode);
6259
63- USE_SERIAL .println (" [HTTP] Headers collected:" );
60+ Serial .println (" [HTTP] Headers collected:" );
6461 for (size_t i = 0 ; i < http.headers (); i++) {
65- USE_SERIAL .printf (" [HTTP] - '%s': '%s'\n " , http.headerName (i).c_str (), http.header (i).c_str ());
62+ Serial .printf (" [HTTP] - '%s': '%s'\n " , http.headerName (i).c_str (), http.header (i).c_str ());
6663 }
6764
68- USE_SERIAL .println (" [HTTP] Has header 'x-custom-header'? " + String (http.hasHeader (" x-custom-header" )) + " (expected true)" );
69- USE_SERIAL .printf (" [HTTP] x-custom-header: '%s' (expected 'value:42')\n " , http.header (" x-custom-header" ).c_str ());
70- USE_SERIAL .printf (" [HTTP] non-existing-header: '%s' (expected empty string)\n " , http.header (" non-existing-header" ).c_str ());
65+ Serial .println (" [HTTP] Has header 'x-custom-header'? " + String (http.hasHeader (" x-custom-header" )) + " (expected true)" );
66+ Serial .printf (" [HTTP] x-custom-header: '%s' (expected 'value:42')\n " , http.header (" x-custom-header" ).c_str ());
67+ Serial .printf (" [HTTP] non-existing-header: '%s' (expected empty string)\n " , http.header (" non-existing-header" ).c_str ());
7168
7269#if COLLECT_ALL_HEADERS
7370 // Server response with multiple headers, one of them is 'server'
74- USE_SERIAL .println (" [HTTP] Has header 'server'? " + String (http.hasHeader (" server" )) + " (expected true)" );
75- USE_SERIAL .printf (" [HTTP] server: '%s'\n " , http.header (" server" ).c_str ());
71+ Serial .println (" [HTTP] Has header 'server'? " + String (http.hasHeader (" server" )) + " (expected true)" );
72+ Serial .printf (" [HTTP] server: '%s'\n " , http.header (" server" ).c_str ());
7673#endif
7774
7875 } else {
79- USE_SERIAL .printf (" [HTTP] GET... failed, error: %s\n " , http.errorToString (httpCode).c_str ());
76+ Serial .printf (" [HTTP] GET... failed, error: %s\n " , http.errorToString (httpCode).c_str ());
8077 }
8178
8279 http.end ();
0 commit comments