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:
parent
0bcba913fd
commit
8012c8dace
@ -11,7 +11,7 @@ const char* HttpClient::kContentLengthPrefix = HTTP_HEADER_CONTENT_LENGTH ": ";
|
||||
|
||||
HttpClient::HttpClient(Client& aClient, const char* aServerName, uint16_t aServerPort)
|
||||
: iClient(&aClient), iServerName(aServerName), iServerAddress(), iServerPort(aServerPort),
|
||||
iConnectionClose(true)
|
||||
iConnectionClose(true), iSendDefaultRequestHeaders(true)
|
||||
{
|
||||
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)
|
||||
: iClient(&aClient), iServerName(NULL), iServerAddress(aServerAddress), iServerPort(aServerPort),
|
||||
iConnectionClose(true)
|
||||
iConnectionClose(true), iSendDefaultRequestHeaders(true)
|
||||
{
|
||||
resetState();
|
||||
}
|
||||
@ -49,6 +49,11 @@ void HttpClient::connectionKeepAlive()
|
||||
iConnectionClose = false;
|
||||
}
|
||||
|
||||
void HttpClient::noDefaultRequestHeaders()
|
||||
{
|
||||
iSendDefaultRequestHeaders = false;
|
||||
}
|
||||
|
||||
void HttpClient::beginRequest()
|
||||
{
|
||||
iState = eRequestStarted;
|
||||
@ -120,20 +125,23 @@ int HttpClient::sendInitialHeaders(const char* aURLPath, const char* aHttpMethod
|
||||
|
||||
iClient->print(aURLPath);
|
||||
iClient->println(" HTTP/1.1");
|
||||
// The host header, if required
|
||||
if (iServerName)
|
||||
if (iSendDefaultRequestHeaders)
|
||||
{
|
||||
iClient->print("Host: ");
|
||||
iClient->print(iServerName);
|
||||
if (iServerPort != kHttpPort)
|
||||
// The host header, if required
|
||||
if (iServerName)
|
||||
{
|
||||
iClient->print(":");
|
||||
iClient->print(iServerPort);
|
||||
iClient->print("Host: ");
|
||||
iClient->print(iServerName);
|
||||
if (iServerPort != kHttpPort)
|
||||
{
|
||||
iClient->print(":");
|
||||
iClient->print(iServerPort);
|
||||
}
|
||||
iClient->println();
|
||||
}
|
||||
iClient->println();
|
||||
// And user-agent string
|
||||
sendHeader(HTTP_HEADER_USER_AGENT, kUserAgent);
|
||||
}
|
||||
// And user-agent string
|
||||
sendHeader(HTTP_HEADER_USER_AGENT, kUserAgent);
|
||||
|
||||
if (iConnectionClose)
|
||||
{
|
||||
|
@ -52,6 +52,10 @@ public:
|
||||
*/
|
||||
void connectionKeepAlive();
|
||||
|
||||
/** Disables sending the default request headers (Host and User Agent)
|
||||
*/
|
||||
void noDefaultRequestHeaders();
|
||||
|
||||
/** Start a more complex 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.
|
||||
@ -293,6 +297,7 @@ protected:
|
||||
const char* iContentLengthPtr;
|
||||
uint32_t iHttpResponseTimeout;
|
||||
bool iConnectionClose;
|
||||
bool iSendDefaultRequestHeaders;
|
||||
String iHeaderLine;
|
||||
};
|
||||
|
||||
|
@ -29,6 +29,7 @@ endOfBodyReached KEYWORD2
|
||||
completed KEYWORD2
|
||||
contentLength KEYWORD2
|
||||
connectionKeepAlive KEYWORD2
|
||||
noDefaultRequestHeaders KEYWORD2
|
||||
headerAvailable KEYWORD2
|
||||
readHeaderName KEYWORD2
|
||||
readHeaderValue KEYWORD2
|
||||
|
Loading…
x
Reference in New Issue
Block a user