1
0

Init commit

This commit is contained in:
2024-02-04 01:45:10 +08:00
commit b1ae55757a
12 changed files with 822 additions and 0 deletions

33
include/http.h Normal file
View File

@@ -0,0 +1,33 @@
/*
Copyright 2023 dragonflylee
*/
#pragma once
#include <string>
#include <vector>
#include <unordered_map>
#include <curl/curl.h>
class http {
public:
using Form = std::unordered_map<std::string, std::string>;
http(const std::string& useragent = "JKSV");
http(const http& other) = delete;
~http();
static std::string encode_form(const Form& form);
void set_headers(const std::vector<std::string>& headers);
int get(const std::string& url, std::ostream* out);
std::string put(const std::string& url, std::istream* data);
std::string post(const std::string& url, const std::string& data);
private:
static size_t easy_write_cb(char* ptr, size_t size, size_t nmemb, void* userdata);
static size_t easy_read_cb(char* ptr, size_t size, size_t nmemb, void* userdata);
int perform(std::ostream* body);
CURL* easy;
struct curl_slist* chunk;
};