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

Allow disabling the 'Accept-Encoding' header #926

Merged
merged 1 commit into from
Jul 9, 2023

Conversation

COM8
Copy link
Member

@COM8 COM8 commented Jul 2, 2023

Resolves #925

Adds a new value for AcceptEncoding: disabled. When a user passes this value to a AcceptEncoding object it will prevent curl from creating a Accept-Encoding.

It has the same behaviour as passing NULL to the curl option CURLOPT_ACCEPT_ENCODING.

When passing multiple values to AcceptEncoding including disabled, an exception of type std::invalid_argument get thrown when performing a request.

Examples

cpr::Session session;
session.SetUrl("https://example.com");
session.SetAcceptEncoding({AcceptEncodingMethods::disabled}); // Disable setting the `Accept-Encoding` headder
Response response = session.Get();
cpr::Session session;
session.SetUrl("https://example.com");
session.SetAcceptEncoding({"disabled"}); // Disable setting the `Accept-Encoding` headder
Response response = session.Get();
cpr::Session session;
session.SetUrl("https://example.com");
session.SetAcceptEncoding({AcceptEncodingMethods::disabled, AcceptEncodingMethods::deflate});
Response response = session.Get(); // An exception of type  `std::invalid_argument` will be thrown here since multiple values are passed to `AcceptEncoding` where one of them is `disabled`

@obelixzgz
Copy link

It's perfect.

@obelixzgz
Copy link

Thank you very much

@COM8
Copy link
Member Author

COM8 commented Jul 2, 2023

Perfect. Will finish up this PR next weekend and add docs for it.

@COM8
Copy link
Member Author

COM8 commented Jul 9, 2023

Docs: libcpr/docs#40

@COM8 COM8 merged commit 9524c34 into master Jul 9, 2023
COM8 added a commit that referenced this pull request Jul 9, 2023
…eader

Allow disabling the 'Accept-Encoding' header
@COM8 COM8 deleted the feature/disable_accept_encoding_header branch July 9, 2023 08:41
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

acceptEncoding must provide a way to disable content-encoding
2 participants