Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(http): Allow to set Accept-Encoding header #9863

Merged
merged 1 commit into from
Jun 17, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 11 additions & 3 deletions libraries/HTTPClient/src/HTTPClient.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -408,6 +408,14 @@ void HTTPClient::setUserAgent(const String &userAgent) {
_userAgent = userAgent;
}

/**
* set Accept Encoding Header
* @param acceptEncoding const char *
*/
void HTTPClient::setAcceptEncoding(const String &acceptEncoding) {
_acceptEncoding = acceptEncoding;
}

/**
* set the Authorizatio for the http request
* @param user const char *
Expand Down Expand Up @@ -969,8 +977,8 @@ String HTTPClient::errorToString(int error) {
*/
void HTTPClient::addHeader(const String &name, const String &value, bool first, bool replace) {
// not allow set of Header handled by code
if (!name.equalsIgnoreCase(F("Connection")) && !name.equalsIgnoreCase(F("User-Agent")) && !name.equalsIgnoreCase(F("Host"))
&& !(name.equalsIgnoreCase(F("Authorization")) && _base64Authorization.length())) {
if (!name.equalsIgnoreCase(F("Connection")) && !name.equalsIgnoreCase(F("User-Agent")) && !name.equalsIgnoreCase(F("Accept-Encoding"))
&& !name.equalsIgnoreCase(F("Host")) && !(name.equalsIgnoreCase(F("Authorization")) && _base64Authorization.length())) {

String headerLine = name;
headerLine += ": ";
Expand Down Expand Up @@ -1130,7 +1138,7 @@ bool HTTPClient::sendHeader(const char *type) {
header += "\r\n";

if (!_useHTTP10) {
header += F("Accept-Encoding: identity;q=1,chunked;q=0.1,*;q=0\r\n");
header += String(F("Accept-Encoding: ")) + _acceptEncoding + F("\r\n");
}

if (_base64Authorization.length()) {
Expand Down
2 changes: 2 additions & 0 deletions libraries/HTTPClient/src/HTTPClient.h
Original file line number Diff line number Diff line change
Expand Up @@ -194,6 +194,7 @@ class HTTPClient {

void setReuse(bool reuse); /// keep-alive
void setUserAgent(const String &userAgent);
void setAcceptEncoding(const String &acceptEncoding);
void setAuthorization(const char *user, const char *password);
void setAuthorization(const char *auth);
void setAuthorizationType(const char *authType);
Expand Down Expand Up @@ -285,6 +286,7 @@ class HTTPClient {
String _userAgent = "ESP32HTTPClient";
String _base64Authorization;
String _authorizationType = "Basic";
String _acceptEncoding = "identity;q=1,chunked;q=0.1,*;q=0";

/// Response handling
RequestArgument *_currentHeaders = nullptr;
Expand Down
Loading