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
Common: Add HttpRequest to simplify HTTP requests #5599
Conversation
Sounds like a good idea, but what you do think of making it more explicit by naming the methods |
Okay, changed the API to be more explicit. Now that you mention it, I think being more explicit is the way to go as it wouldn't be possible to POST without any payload otherwise. |
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.
LGTM, assuming it still works ;)
Source/Core/Common/HttpRequest.h
Outdated
}; | ||
Response Fetch(const std::string& url, Method method, const u8* payload, size_t size); | ||
|
||
std::unique_ptr<CURL, decltype(&curl_easy_cleanup)> m_curl{curl_easy_init(), curl_easy_cleanup}; |
This comment was marked as off-topic.
This comment was marked as off-topic.
Sorry, something went wrong.
This comment was marked as off-topic.
This comment was marked as off-topic.
Sorry, something went wrong.
This comment was marked as off-topic.
This comment was marked as off-topic.
Sorry, something went wrong.
Source/Core/Common/HttpRequest.cpp
Outdated
return m_curl != nullptr; | ||
} | ||
|
||
static size_t CurlCallback(u8* data, size_t size, size_t nmemb, std::vector<u8>* buffer) |
This comment was marked as off-topic.
This comment was marked as off-topic.
Sorry, something went wrong.
This comment was marked as off-topic.
This comment was marked as off-topic.
Sorry, something went wrong.
Too much boilerplate that is duplicated if we use curl directly. Let's add a simple wrapper class that hides the implementation details and just allows to simply make HTTP requests and get responses.
Added a way to send custom headers (which is required for NUS). |
Too much boilerplate that is duplicated if we use curl directly. I was implementing online updates and found that having to write 40+ lines everywhere we need to GET/POST is a bit too much, especially as the setup code is all very similiar and nearly duplicated.
This PR adds a simple wrapper class that hides the implementation details and allows to make HTTP requests and get the response very simply.