mirror of
https://github.com/sle118/squeezelite-esp32.git
synced 2025-12-09 21:17:18 +03:00
MacOS auth for Spotify
This commit is contained in:
@@ -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() {
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user