OSDN Git Service

Merge pull request #3569 from sikabane-works/release/3.0.0.88-alpha
[hengbandforosx/hengbandosx.git] / src / net / http-client.h
1 #pragma once
2
3 #include "system/angband.h"
4 #include <filesystem>
5 #include <functional>
6 #include <optional>
7 #include <string>
8
9 #if !defined(DISABLE_NET)
10
11 namespace http {
12
13 struct Response {
14     int status;
15     std::string body;
16 };
17
18 struct Progress {
19     size_t total; ///< 通信の総バイト数。0の場合は不明
20     size_t now; ///< 通信済みのバイト数
21 };
22
23 class HttpContentBase;
24 class Client {
25 public:
26     /*!
27      * @brief HTTP GET通信のコールバック関数の型
28      * @param progress 進捗状況。libcurlの仕様によりnow/totalが0で呼ばれることがあるのでそれを考慮すること
29      * @return 通信を継続する場合はtrue、中断する場合はfalseを返す
30      */
31     using GetRequestProgressHandler = std::function<bool(Progress)>;
32
33     std::optional<Response> get(const std::string &url, GetRequestProgressHandler progress_handler = {});
34     std::optional<Response> get(const std::string &url, const std::filesystem::path &path, GetRequestProgressHandler progress_handler = {});
35     std::optional<Response> post(const std::string &url, const std::string &post_data, const std::string &media_type);
36
37     std::optional<std::string> user_agent;
38 };
39
40 }
41
42 #endif