Files
OrcaSlicer-bambulab/xs/src/slic3r/Utils/Http.hpp
T

72 lines
1.6 KiB
C++
Raw Normal View History

2018-02-07 11:37:15 +01:00
#ifndef slic3r_Http_hpp_
#define slic3r_Http_hpp_
#include <memory>
#include <string>
#include <functional>
namespace Slic3r {
/// Represetns a Http request
class Http : public std::enable_shared_from_this<Http> {
private:
struct priv;
public:
2018-04-04 11:18:22 +02:00
struct Progress
{
size_t dltotal;
size_t dlnow;
size_t ultotal;
size_t ulnow;
Progress(size_t dltotal, size_t dlnow, size_t ultotal, size_t ulnow) :
dltotal(dltotal), dlnow(dlnow), ultotal(ultotal), ulnow(ulnow)
{}
};
2018-02-07 11:37:15 +01:00
typedef std::shared_ptr<Http> Ptr;
typedef std::function<void(std::string /* body */, unsigned /* http_status */)> CompleteFn;
typedef std::function<void(std::string /* body */, std::string /* error */, unsigned /* http_status */)> ErrorFn;
2018-04-04 11:18:22 +02:00
typedef std::function<void(Progress, bool& /* cancel */)> ProgressFn;
2018-02-07 11:37:15 +01:00
Http(Http &&other);
static Http get(std::string url);
static Http post(std::string url);
~Http();
Http(const Http &) = delete;
Http& operator=(const Http &) = delete;
Http& operator=(Http &&) = delete;
Http& size_limit(size_t sizeLimit);
Http& header(std::string name, const std::string &value);
Http& remove_header(std::string name);
Http& ca_file(const std::string &filename);
Http& form_add(const std::string &name, const std::string &contents);
Http& form_add_file(const std::string &name, const std::string &filename);
Http& on_complete(CompleteFn fn);
Http& on_error(ErrorFn fn);
2018-04-04 11:18:22 +02:00
Http& on_progress(ProgressFn fn);
2018-02-07 11:37:15 +01:00
Ptr perform();
void perform_sync();
2018-04-04 11:18:22 +02:00
void cancel();
2018-02-07 11:37:15 +01:00
2018-03-15 18:06:26 +01:00
static bool ca_file_supported();
2018-02-07 11:37:15 +01:00
private:
Http(const std::string &url);
std::unique_ptr<priv> p;
};
2018-04-04 11:18:22 +02:00
std::ostream& operator<<(std::ostream &, const Http::Progress &);
2018-02-07 11:37:15 +01:00
}
#endif