1
0
mirror of https://github.com/arduino-libraries/ArduinoHttpClient.git synced 2025-04-19 21:22:15 +03:00

Add noDefaultRequestHeaders API to turn off sending default headers

This commit is contained in:
Sandeep Mistry 2016-06-17 16:49:52 -04:00
parent 0bcba913fd
commit 8012c8dace
3 changed files with 26 additions and 12 deletions

View File

@ -11,7 +11,7 @@ const char* HttpClient::kContentLengthPrefix = HTTP_HEADER_CONTENT_LENGTH ": ";
HttpClient::HttpClient(Client& aClient, const char* aServerName, uint16_t aServerPort) HttpClient::HttpClient(Client& aClient, const char* aServerName, uint16_t aServerPort)
: iClient(&aClient), iServerName(aServerName), iServerAddress(), iServerPort(aServerPort), : iClient(&aClient), iServerName(aServerName), iServerAddress(), iServerPort(aServerPort),
iConnectionClose(true) iConnectionClose(true), iSendDefaultRequestHeaders(true)
{ {
resetState(); resetState();
} }
@ -23,7 +23,7 @@ HttpClient::HttpClient(Client& aClient, const String& aServerName, uint16_t aSer
HttpClient::HttpClient(Client& aClient, const IPAddress& aServerAddress, uint16_t aServerPort) HttpClient::HttpClient(Client& aClient, const IPAddress& aServerAddress, uint16_t aServerPort)
: iClient(&aClient), iServerName(NULL), iServerAddress(aServerAddress), iServerPort(aServerPort), : iClient(&aClient), iServerName(NULL), iServerAddress(aServerAddress), iServerPort(aServerPort),
iConnectionClose(true) iConnectionClose(true), iSendDefaultRequestHeaders(true)
{ {
resetState(); resetState();
} }
@ -49,6 +49,11 @@ void HttpClient::connectionKeepAlive()
iConnectionClose = false; iConnectionClose = false;
} }
void HttpClient::noDefaultRequestHeaders()
{
iSendDefaultRequestHeaders = false;
}
void HttpClient::beginRequest() void HttpClient::beginRequest()
{ {
iState = eRequestStarted; iState = eRequestStarted;
@ -120,6 +125,8 @@ int HttpClient::sendInitialHeaders(const char* aURLPath, const char* aHttpMethod
iClient->print(aURLPath); iClient->print(aURLPath);
iClient->println(" HTTP/1.1"); iClient->println(" HTTP/1.1");
if (iSendDefaultRequestHeaders)
{
// The host header, if required // The host header, if required
if (iServerName) if (iServerName)
{ {
@ -134,6 +141,7 @@ int HttpClient::sendInitialHeaders(const char* aURLPath, const char* aHttpMethod
} }
// And user-agent string // And user-agent string
sendHeader(HTTP_HEADER_USER_AGENT, kUserAgent); sendHeader(HTTP_HEADER_USER_AGENT, kUserAgent);
}
if (iConnectionClose) if (iConnectionClose)
{ {

View File

@ -52,6 +52,10 @@ public:
*/ */
void connectionKeepAlive(); void connectionKeepAlive();
/** Disables sending the default request headers (Host and User Agent)
*/
void noDefaultRequestHeaders();
/** Start a more complex request. /** Start a more complex request.
Use this when you need to send additional headers in the request, Use this when you need to send additional headers in the request,
but you will also need to call endRequest() when you are finished. but you will also need to call endRequest() when you are finished.
@ -293,6 +297,7 @@ protected:
const char* iContentLengthPtr; const char* iContentLengthPtr;
uint32_t iHttpResponseTimeout; uint32_t iHttpResponseTimeout;
bool iConnectionClose; bool iConnectionClose;
bool iSendDefaultRequestHeaders;
String iHeaderLine; String iHeaderLine;
}; };

View File

@ -29,6 +29,7 @@ endOfBodyReached KEYWORD2
completed KEYWORD2 completed KEYWORD2
contentLength KEYWORD2 contentLength KEYWORD2
connectionKeepAlive KEYWORD2 connectionKeepAlive KEYWORD2
noDefaultRequestHeaders KEYWORD2
headerAvailable KEYWORD2 headerAvailable KEYWORD2
readHeaderName KEYWORD2 readHeaderName KEYWORD2
readHeaderValue KEYWORD2 readHeaderValue KEYWORD2