@@ -11,7 +11,7 @@ const char* HttpClient::kContentLengthPrefix = HTTP_HEADER_CONTENT_LENGTH ": ";
1111
1212HttpClient::HttpClient (Client& aClient, const char * aServerName, uint16_t aServerPort)
1313 : iClient(&aClient), iServerName(aServerName), iServerAddress(), iServerPort(aServerPort),
14- iConnectionClose(true )
14+ iConnectionClose(true ), iSendDefaultRequestHeaders( true )
1515{
1616 resetState ();
1717}
@@ -23,7 +23,7 @@ HttpClient::HttpClient(Client& aClient, const String& aServerName, uint16_t aSer
2323
2424HttpClient::HttpClient (Client& aClient, const IPAddress& aServerAddress, uint16_t aServerPort)
2525 : iClient(&aClient), iServerName(NULL ), iServerAddress(aServerAddress), iServerPort(aServerPort),
26- iConnectionClose(true )
26+ iConnectionClose(true ), iSendDefaultRequestHeaders( true )
2727{
2828 resetState ();
2929}
@@ -49,6 +49,11 @@ void HttpClient::connectionKeepAlive()
4949 iConnectionClose = false ;
5050}
5151
52+ void HttpClient::noDefaultRequestHeaders ()
53+ {
54+ iSendDefaultRequestHeaders = false ;
55+ }
56+
5257void HttpClient::beginRequest ()
5358{
5459 iState = eRequestStarted;
@@ -120,20 +125,23 @@ int HttpClient::sendInitialHeaders(const char* aURLPath, const char* aHttpMethod
120125
121126 iClient->print (aURLPath);
122127 iClient->println (" HTTP/1.1" );
123- // The host header, if required
124- if (iServerName)
128+ if (iSendDefaultRequestHeaders)
125129 {
126- iClient->print (" Host: " );
127- iClient->print (iServerName);
128- if (iServerPort != kHttpPort )
130+ // The host header, if required
131+ if (iServerName)
129132 {
130- iClient->print (" :" );
131- iClient->print (iServerPort);
133+ iClient->print (" Host: " );
134+ iClient->print (iServerName);
135+ if (iServerPort != kHttpPort )
136+ {
137+ iClient->print (" :" );
138+ iClient->print (iServerPort);
139+ }
140+ iClient->println ();
132141 }
133- iClient->println ();
142+ // And user-agent string
143+ sendHeader (HTTP_HEADER_USER_AGENT, kUserAgent );
134144 }
135- // And user-agent string
136- sendHeader (HTTP_HEADER_USER_AGENT, kUserAgent );
137145
138146 if (iConnectionClose)
139147 {
0 commit comments