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

Response.GetCertInfos() is not const #1073

Closed
askraskr opened this issue Jul 3, 2024 · 2 comments · Fixed by #1076
Closed

Response.GetCertInfos() is not const #1073

askraskr opened this issue Jul 3, 2024 · 2 comments · Fixed by #1076

Comments

@askraskr
Copy link

askraskr commented Jul 3, 2024

Description

Since Response.GetCertInfos() method is not const, we cannot use it with constant response objects.
for example, you we cannot pass a Response object to a function with the following signature:

nlohmann::json response_to_json(const cpr::Response &response)
{
   // .....
   for (size_t i{}; const auto &cert: response.GetCertInfos()) {
              // do something with cert
   }
   // .....
}

Example/How to Reproduce

nlohmann::json response_to_json(const cpr::Response &response)
{
   // .....
   for (size_t i{}; const auto &cert: response.GetCertInfos()) {
              // do something with cert
   }
   // .....
}

int main() 
{
        auto response = cpr::Get(cpr::Url("https://www.google.com"),
	                         cpr::UserAgent("Mozilla")
	);
        auto json = response_to_json(response);
}

Possible Fix

Since GetCertInfos() is not changing any data member of Response, it's better to make it const

namespace cpr {
///.... other stuff
class Response {
    ///.... other stuff
    std::vector<CertInfo> GetCertInfos() const;
    ///.... other stuff
};
} // namespace cpr

Where did you get it from?

Other (specify in "Additional Context/Your Environment")

Additional Context/Your Environment

  • OS: All
  • Version: Development
@COM8
Copy link
Member

COM8 commented Jul 4, 2024

@askraskr thanks for reporting. Fixed in #1076.
Can you please confirm it works now for you?

@askraskr
Copy link
Author

askraskr commented Jul 6, 2024

@COM8 Yes, it works.
thanks

@COM8 COM8 closed this as completed in #1076 Jul 9, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants