Zrythm v2.0.0-DEV
a highly automated and intuitive digital audio workstation
Loading...
Searching...
No Matches
networking.h
1// SPDX-FileCopyrightText: © 2021, 2023-2025 Alexandros Theodotou <alex@zrythm.org>
2// SPDX-License-Identifier: LicenseRef-ZrythmLicense
3
4#pragma once
5
6#include <filesystem>
7#include <functional>
8#include <future>
9#include <memory>
10#include <string>
11#include <variant>
12
13#include "utils/utf8_string.h"
14
19{
20
21class URL final
22{
23public:
24 class MultiPartMimeObject final
25 {
26 public:
27 MultiPartMimeObject (
28 std::string name,
29 std::filesystem::path filepath,
30 std::string mimetype);
31
32 friend class URL;
33
34 private:
35 std::string name_;
36 std::filesystem::path filepath_;
37 std::string mimetype_;
38 };
39
40public:
41 URL (const std::string &url);
42
43 ~URL ();
44
45 URL (const URL &) = delete;
46 URL &operator= (const URL &) = delete;
47 URL (URL &&) noexcept;
48 URL &operator= (URL &&) noexcept;
49
58 std::string get_page_contents (int timeout = 0);
59
69 const std::string &json_str,
70 int timeout,
71 std::initializer_list<MultiPartMimeObject> mime_objects);
72
73 using AsyncStringResult = std::variant<std::string, std::exception_ptr>;
74 using GetContentsAsyncCallback = std::function<void (AsyncStringResult)>;
75
76 std::future<void>
77 get_page_contents_async (int timeout_ms, GetContentsAsyncCallback callback);
78
79private:
80 class Impl;
81 std::unique_ptr<Impl> impl_;
82};
83
84}
std::string get_page_contents(int timeout=0)
Returns the contents of the page synchronously.
utils::Utf8String post_json_no_auth(const std::string &json_str, int timeout, std::initializer_list< MultiPartMimeObject > mime_objects)
Posts the given JSON to the URL without any authentication.
Networking utilities.
Definition networking.h:19
String utilities.