You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

41 lines
930B

  1. #pragma once
  2. #include <map>
  3. #include <jansson.h>
  4. #include <common.hpp>
  5. namespace rack {
  6. /** Networking functions for HTTP requests, URLs, and downloads
  7. */
  8. namespace network {
  9. typedef std::map<std::string, std::string> CookieMap;
  10. enum Method {
  11. METHOD_GET,
  12. METHOD_POST,
  13. METHOD_PUT,
  14. METHOD_DELETE,
  15. };
  16. void init();
  17. /** Requests a JSON API URL over HTTP(S), using the data as the query (GET) or the body (POST, etc)
  18. Caller must json_decref().
  19. */
  20. json_t* requestJson(Method method, const std::string& url, json_t* dataJ, const CookieMap& cookies = {});
  21. /** Returns true if downloaded successfully */
  22. bool requestDownload(const std::string& url, const std::string& filename, float* progress, const CookieMap& cookies = {});
  23. /** URL-encodes `s` */
  24. std::string encodeUrl(const std::string& s);
  25. /** Gets the path portion of the URL. */
  26. std::string urlPath(const std::string& url);
  27. } // namespace network
  28. } // namespace rack