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
Add method SetAcceptEncoding for customized Accept-Encoding header (#683) #746
Conversation
leviliangtw
commented
May 17, 2022
- New class for managing header Accept-Encoding refers to proxies structure.cpp
- New method to set header Accept-Encoding
- New unit test to verify header Accept-Encoding
021210a
to
68d527b
Compare
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for looking into this.
cpr/accept_encoding.cpp
Outdated
|
||
AcceptEncoding::AcceptEncoding(const std::initializer_list<AcceptEncodingMethods>& methods) : methods_{methods} {} | ||
|
||
bool AcceptEncoding::isEmpty() const { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
All public methods have to start with an upper case letter.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would like to change its name to has
, just like the implementation in proxies.cpp:
bool Proxies::has(const std::string& protocol) const {
return hosts_.count(protocol) > 0;
}
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is also possible.
include/cpr/accept_encoding.h
Outdated
|
||
class AcceptEncoding { | ||
public: | ||
std::map<AcceptEncodingMethods, std::string> MethodsString { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Although I like the way you are solving this here, curl allows even more encodings: https://curl.se/libcurl/c/CURLOPT_ACCEPT_ENCODING.html
Since this is something that changes based on what is build into curl, in my eyes we need at least an additional option allowing the user to specify their own encoding via a string name.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sure, I will add an overload function for that to make it more flexible.
39f4a0e
to
e27999b
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This one goes into the right direction. Only a few things to sort out. Also please rebase your changes on master: https://gist.github.com/ravibhure/a7e0918ff4937c9ea1c456698dcd58aa
test/abstractServer.cpp
Outdated
@@ -105,7 +105,7 @@ std::string AbstractServer::Base64Decode(const std::string& in) { | |||
break; | |||
} | |||
// NOLINTNEXTLINE (cppcoreguidelines-avoid-magic-numbers) | |||
val = (val << 6) + T[c]; | |||
val = ((uint)val << (uint)6) + T[c]; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please don't use C-style casts
val = ((uint)val << (uint)6) + T[c]; | |
val = (static_cast<uint>(val) << static_cast<uint>(6)) + T[c]; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Got it!
include/cpr/accept_encoding.h
Outdated
|
||
class AcceptEncoding { | ||
public: | ||
std::map<AcceptEncodingMethods, std::string> MethodsStringMap { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can't this map be static
and const
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would investigate it and find a best practice for that
include/cpr/accept_encoding.h
Outdated
AcceptEncoding(const std::initializer_list<AcceptEncodingMethods>& methods); | ||
AcceptEncoding(const std::initializer_list<std::string>& methods); | ||
|
||
bool has() const; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I thought about it again and I prefer empty()
here as name.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sure!
49432fc
to
24cbfb7
Compare
msvc on Windows reports:
|
04b1cb8
to
1383954
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good now, thanks!
Please create a PR for a bit of documentation here: https://github.com/libcpr/docs
1383954
to
be9ece6
Compare
|
be9ece6
to
1295bba
Compare
I think I should not modify this file. |
Add method SetAcceptEncoding for customized Accept-Encoding header (libcpr#683)