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

Common: Add HttpRequest to simplify HTTP requests #5599

Merged
merged 4 commits into from Jun 14, 2017

Conversation

leoetlino
Copy link
Member

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.

@BhaaLseN
Copy link
Member

Sounds like a good idea, but what you do think of making it more explicit by naming the methods Get (without payload, because you can never have one) and Post (with payload, but potentially optional/empty if we want to support triggering REST services at some point where no payload is required...but -0 on that)?
Having a single Fetch method that guesses based on the presence/absence of a payload feels a little wonky (although it does do a decent job of hiding the actual technical detail; which is +/-0 whether we actually want that)

@leoetlino
Copy link
Member Author

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.

Copy link
Member

@BhaaLseN BhaaLseN left a 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 ;)

};
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.

This comment was marked as off-topic.

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.

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.
@leoetlino
Copy link
Member Author

Added a way to send custom headers (which is required for NUS).

@leoetlino leoetlino merged commit 36efcc9 into dolphin-emu:master Jun 14, 2017
@leoetlino leoetlino deleted the http-request branch June 14, 2017 09:13
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
3 participants