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() {
4141 _reuse = false ;
4242 _https = false ;
4343
44+ _userAgent = " ESP8266httpClient" ;
45+
4446 _headerKeysCount = 0 ;
4547 _currentHeaders = NULL ;
4648
@@ -210,6 +212,15 @@ void httpClient::setReuse(bool reuse) {
210212 _reuse = reuse;
211213}
212214
215+ /* *
216+ * set User Agent
217+ * @param userAgent const char *
218+ */
219+ void httpClient::setUserAgent (const char * userAgent) {
220+ _userAgent = userAgent;
221+ }
222+
223+
213224/* *
214225 * send a GET request
215226 * @return http code
@@ -502,9 +513,10 @@ bool httpClient::sendHeader(const char * type) {
502513 if (!connected ()) {
503514 return false ;
504515 }
516+
505517 String header = String (type) + " " + _url + " HTTP/1.1\r\n "
506518 " Host: " + _host + " \r\n "
507- " User-Agent: ESP8266httpClient \r\n "
519+ " User-Agent: " + _userAgent + " \r\n "
508520 " Connection: " ;
509521
510522 if (_reuse) {
Original file line number Diff line number Diff line change 2525#ifndef ESP8266HTTPCLIENT_H_
2626#define ESP8266HTTPCLIENT_H_
2727
28- #define DEBUG_HTTPCLIENT (...) Serial1.printf( __VA_ARGS__ )
28+ // #define DEBUG_HTTPCLIENT(...) Serial1.printf( __VA_ARGS__ )
2929
3030#ifndef DEBUG_HTTPCLIENT
3131#define DEBUG_HTTPCLIENT (...)
@@ -59,6 +59,7 @@ class httpClient {
5959 bool connected (void );
6060
6161 void setReuse (bool reuse); // / keep-alive
62+ void setUserAgent (const char * userAgent);
6263
6364 // / request handling
6465 int GET ();
@@ -105,7 +106,8 @@ class httpClient {
105106 bool _https;
106107 String _httpsFingerprint;
107108
108- String _Headers;
109+ String _Headers;
110+ String _userAgent;
109111
110112 // / Response handling
111113 RequestArgument* _currentHeaders;
You can’t perform that action at this time.
0 commit comments