File tree Expand file tree Collapse file tree 2 files changed +17
-3
lines changed
libraries/ESP8266httpClient/src Expand file tree Collapse file tree 2 files changed +17
-3
lines changed Original file line number Diff line number Diff line change @@ -41,6 +41,8 @@ httpClient::httpClient() {
41
41
_reuse = false ;
42
42
_https = false ;
43
43
44
+ _userAgent = " ESP8266httpClient" ;
45
+
44
46
_headerKeysCount = 0 ;
45
47
_currentHeaders = NULL ;
46
48
@@ -210,6 +212,15 @@ void httpClient::setReuse(bool reuse) {
210
212
_reuse = reuse;
211
213
}
212
214
215
+ /* *
216
+ * set User Agent
217
+ * @param userAgent const char *
218
+ */
219
+ void httpClient::setUserAgent (const char * userAgent) {
220
+ _userAgent = userAgent;
221
+ }
222
+
223
+
213
224
/* *
214
225
* send a GET request
215
226
* @return http code
@@ -502,9 +513,10 @@ bool httpClient::sendHeader(const char * type) {
502
513
if (!connected ()) {
503
514
return false ;
504
515
}
516
+
505
517
String header = String (type) + " " + _url + " HTTP/1.1\r\n "
506
518
" Host: " + _host + " \r\n "
507
- " User-Agent: ESP8266httpClient \r\n "
519
+ " User-Agent: " + _userAgent + " \r\n "
508
520
" Connection: " ;
509
521
510
522
if (_reuse) {
Original file line number Diff line number Diff line change 25
25
#ifndef ESP8266HTTPCLIENT_H_
26
26
#define ESP8266HTTPCLIENT_H_
27
27
28
- #define DEBUG_HTTPCLIENT (...) Serial1.printf( __VA_ARGS__ )
28
+ // #define DEBUG_HTTPCLIENT(...) Serial1.printf( __VA_ARGS__ )
29
29
30
30
#ifndef DEBUG_HTTPCLIENT
31
31
#define DEBUG_HTTPCLIENT (...)
@@ -59,6 +59,7 @@ class httpClient {
59
59
bool connected (void );
60
60
61
61
void setReuse (bool reuse); // / keep-alive
62
+ void setUserAgent (const char * userAgent);
62
63
63
64
// / request handling
64
65
int GET ();
@@ -105,7 +106,8 @@ class httpClient {
105
106
bool _https;
106
107
String _httpsFingerprint;
107
108
108
- String _Headers;
109
+ String _Headers;
110
+ String _userAgent;
109
111
110
112
// / Response handling
111
113
RequestArgument* _currentHeaders;
You can’t perform that action at this time.
0 commit comments