Pulp 1.88.0
Cross-platform audio plugin framework
Loading...
Searching...
No Matches
http.hpp
Go to the documentation of this file.
1#pragma once
2
3// HTTP client — wraps cpp-httplib without exposing it through the public API.
4
5#include <functional>
6#include <map>
7#include <string>
8#include <string_view>
9
10namespace pulp::runtime {
11
12using HttpHeaders = std::map<std::string, std::string>;
13using HttpChunkCallback = std::function<bool(std::string_view)>;
14
16 std::string url;
17 std::string method = "GET";
18 std::string body;
19 std::string content_type = "application/json";
22
23 // Returning false stops the transfer. Chunk boundaries do not imply protocol
24 // record boundaries. When set, response bytes are delivered here instead of
25 // being retained in HttpResponse::body.
27};
28
30 int status_code = 0;
31 std::string body;
33 std::string error;
34
35 bool ok() const {
36 return error.empty() && status_code >= 200 && status_code < 300;
37 }
38};
39
42
44HttpResponse http_get(std::string_view url,
45 int timeout_seconds = 30);
46
48HttpResponse http_post(std::string_view url,
49 std::string_view body,
50 std::string_view content_type = "application/json",
51 int timeout_seconds = 30);
52
54bool http_download(std::string_view url, std::string_view output_path,
55 int timeout_seconds = 60);
56
57} // namespace pulp::runtime
Definition generated_event_source.hpp:33
bool http_download(std::string_view url, std::string_view output_path, int timeout_seconds=60)
Download a file from a URL to a local path. Returns true on success.
HttpResponse http_post(std::string_view url, std::string_view body, std::string_view content_type="application/json", int timeout_seconds=30)
Perform an HTTP POST request with a body.
std::function< bool(std::string_view)> HttpChunkCallback
Definition http.hpp:13
HttpResponse http_request(const HttpRequest &request)
Perform an HTTP request. GET and POST are supported.
std::map< std::string, std::string > HttpHeaders
Definition http.hpp:12
HttpResponse http_get(std::string_view url, int timeout_seconds=30)
Perform an HTTP GET request.
Definition http.hpp:15
HttpChunkCallback on_chunk
Definition http.hpp:26
int timeout_seconds
Definition http.hpp:21
std::string url
Definition http.hpp:16
std::string content_type
Definition http.hpp:19
HttpHeaders headers
Definition http.hpp:20
std::string body
Definition http.hpp:18
std::string method
Definition http.hpp:17
Definition http.hpp:29
HttpHeaders headers
Definition http.hpp:32
std::string body
Definition http.hpp:31
bool ok() const
Definition http.hpp:35
int status_code
Definition http.hpp:30
std::string error
Definition http.hpp:33