MacOS auth for Spotify

This commit is contained in:
philippe44
2023-07-25 19:08:30 -07:00
parent 8b764c0c2d
commit bdceb2d832
7 changed files with 106 additions and 51 deletions

View File

@@ -27,7 +27,7 @@ HTTPClient::Response::~Response() {
void HTTPClient::Response::rawRequest(const std::string& url,
const std::string& method,
const std::string& content,
const std::vector<uint8_t>& content,
Headers& headers) {
urlParser = bell::URLParser::parse(url);
@@ -50,6 +50,10 @@ void HTTPClient::Response::rawRequest(const std::string& url,
}
socketStream << reqEnd;
// Write request body
if (content.size() > 0) {
socketStream.write((const char*)content.data(), content.size());
}
socketStream.flush();
// Parse response
@@ -115,7 +119,13 @@ void HTTPClient::Response::readResponseHeaders() {
void HTTPClient::Response::get(const std::string& url, Headers headers) {
std::string method = "GET";
return this->rawRequest(url, method, "", headers);
return this->rawRequest(url, method, {}, headers);
}
void HTTPClient::Response::post(const std::string& url, Headers headers,
const std::vector<uint8_t>& body) {
std::string method = "POST";
return this->rawRequest(url, method, body, headers);
}
size_t HTTPClient::Response::contentLength() {

View File

@@ -55,8 +55,10 @@ class HTTPClient {
void connect(const std::string& url);
void rawRequest(const std::string& method, const std::string& url,
const std::string& content, Headers& headers);
const std::vector<uint8_t>& content, Headers& headers);
void get(const std::string& url, Headers headers = {});
void post(const std::string& url, Headers headers = {},
const std::vector<uint8_t>& body = {});
std::string_view body();
std::vector<uint8_t> bytes();
@@ -102,5 +104,14 @@ class HTTPClient {
response->get(url, headers);
return response;
}
static std::unique_ptr<Response> post(const std::string& url,
Headers headers = {},
const std::vector<uint8_t>& body = {}) {
auto response = std::make_unique<Response>();
response->connect(url);
response->post(url, headers, body);
return response;
}
};
} // namespace bell