| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
1 parent 0bcba91 commit 8012c8d
3 files changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -11,7 +11,7 @@ const char* HttpClient::kContentLengthPrefix = HTTP_HEADER_CONTENT_LENGTH ": "; | |||
| 11 | 11 | ||
| 12 | 12 | HttpClient::HttpClient(Client& aClient, const char* aServerName, uint16_t aServerPort) | |
| 13 | 13 | : iClient(&aClient), iServerName(aServerName), iServerAddress(), iServerPort(aServerPort), | |
| 14 | - iConnectionClose(true) | ||
| 14 | + iConnectionClose(true), iSendDefaultRequestHeaders(true) | ||
| 15 | 15 | { | |
| 16 | 16 | resetState(); | |
| 17 | 17 | } | |
@@ -23,7 +23,7 @@ HttpClient::HttpClient(Client& aClient, const String& aServerName, uint16_t aSer | |||
| 23 | 23 | ||
| 24 | 24 | HttpClient::HttpClient(Client& aClient, const IPAddress& aServerAddress, uint16_t aServerPort) | |
| 25 | 25 | : iClient(&aClient), iServerName(NULL), iServerAddress(aServerAddress), iServerPort(aServerPort), | |
| 26 | - iConnectionClose(true) | ||
| 26 | + iConnectionClose(true), iSendDefaultRequestHeaders(true) | ||
| 27 | 27 | { | |
| 28 | 28 | resetState(); | |
| 29 | 29 | } | |
@@ -49,6 +49,11 @@ void HttpClient::connectionKeepAlive() | |||
| 49 | 49 | iConnectionClose = false; | |
| 50 | 50 | } | |
| 51 | 51 | ||
| 52 | + void HttpClient::noDefaultRequestHeaders() | ||
| 53 | + { | ||
| 54 | + iSendDefaultRequestHeaders = false; | ||
| 55 | + } | ||
| 56 | + | ||
| 52 | 57 | void HttpClient::beginRequest() | |
| 53 | 58 | { | |
| 54 | 59 | iState = eRequestStarted; | |
@@ -120,20 +125,23 @@ int HttpClient::sendInitialHeaders(const char* aURLPath, const char* aHttpMethod | |||
| 120 | 125 | ||
| 121 | 126 | iClient->print(aURLPath); | |
| 122 | 127 | iClient->println(" HTTP/1.1"); | |
| 123 | - // The host header, if required | ||
| 124 | - if (iServerName) | ||
| 128 | + if (iSendDefaultRequestHeaders) | ||
| 125 | 129 | { | |
| 126 | - iClient->print("Host: "); | ||
| 127 | - iClient->print(iServerName); | ||
| 128 | - if (iServerPort != kHttpPort) | ||
| 130 | + // The host header, if required | ||
| 131 | + if (iServerName) | ||
| 129 | 132 | { | |
| 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(); | ||
| 132 | 141 | } | |
| 133 | - iClient->println(); | ||
| 142 | + // And user-agent string | ||
| 143 | + sendHeader(HTTP_HEADER_USER_AGENT, kUserAgent); | ||
| 134 | 144 | } | |
| 135 | - // And user-agent string | ||
| 136 | - sendHeader(HTTP_HEADER_USER_AGENT, kUserAgent); | ||
| 137 | 145 | ||
| 138 | 146 | if (iConnectionClose) | |
| 139 | 147 | { | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -52,6 +52,10 @@ class HttpClient : public Client | |||
| 52 | 52 | */ | |
| 53 | 53 | void connectionKeepAlive(); | |
| 54 | 54 | ||
| 55 | + /** Disables sending the default request headers (Host and User Agent) | ||
| 56 | + */ | ||
| 57 | + void noDefaultRequestHeaders(); | ||
| 58 | + | ||
| 55 | 59 | /** Start a more complex request. | |
| 56 | 60 | Use this when you need to send additional headers in the request, | |
| 57 | 61 | but you will also need to call endRequest() when you are finished. | |
@@ -293,6 +297,7 @@ class HttpClient : public Client | |||
| 293 | 297 | const char* iContentLengthPtr; | |
| 294 | 298 | uint32_t iHttpResponseTimeout; | |
| 295 | 299 | bool iConnectionClose; | |
| 300 | + bool iSendDefaultRequestHeaders; | ||
| 296 | 301 | String iHeaderLine; | |
| 297 | 302 | }; | |
| 298 | 303 | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -29,6 +29,7 @@ endOfBodyReached KEYWORD2 | |||
| 29 | 29 | completed KEYWORD2 | |
| 30 | 30 | contentLength KEYWORD2 | |
| 31 | 31 | connectionKeepAlive KEYWORD2 | |
| 32 | + noDefaultRequestHeaders KEYWORD2 | ||
| 32 | 33 | headerAvailable KEYWORD2 | |
| 33 | 34 | readHeaderName KEYWORD2 | |
| 34 | 35 | readHeaderValue KEYWORD2 | |
| Back | FazBrowse Home | New Git URL |
0 commit comments