mirror of
https://github.com/hrydgard/ppsspp.git
synced 2026-10-01 14:58:14 +00:00
Small HTTPClient cleanup
This commit is contained in:
1 parent
c797ac200c
commit
2c7d4c5613
2 files changed
+12
-10
No files matched your search
@@ -1,6 +1,7 @@
|
||||
#include <cmath>
|
||||
#include <cstdio>
|
||||
#include <cstdlib>
|
||||
#include <utility>
|
||||
|
||||
#include "Common/Net/HTTPClient.h"
|
||||
|
||||
@@ -75,7 +76,7 @@ bool Connection::Resolve(const char *host, int port, DNSType type) {
|
||||
}
|
||||
|
||||
std::string err;
|
||||
if (!net::DNSResolve(processedHostname.c_str(), port_str, &resolved_, err, type)) {
|
||||
if (!net::DNSResolve(processedHostname, port_str, &resolved_, err, type)) {
|
||||
WARN_LOG(Log::Net, "Failed to resolve host '%s': '%s' (%s)", host, err.c_str(), DNSTypeAsString(type));
|
||||
// Zero port so that future calls fail.
|
||||
port_ = 0;
|
||||
@@ -238,7 +239,7 @@ namespace http {
|
||||
constexpr const char *DEFAULT_USERAGENT = "PPSSPP";
|
||||
constexpr const char *HTTP_VERSION = "1.1";
|
||||
|
||||
Client::Client(net::ResolveFunc func) : Connection(func) {
|
||||
Client::Client(net::ResolveFunc func) : Connection(std::move(func)) {
|
||||
userAgent_ = DEFAULT_USERAGENT;
|
||||
httpVersion_ = HTTP_VERSION;
|
||||
}
|
||||
@@ -279,7 +280,7 @@ static bool DeChunk(Buffer *inbuffer, Buffer *outbuffer, int contentLength) {
|
||||
while (true) {
|
||||
std::string line;
|
||||
inbuffer->TakeLineCRLF(&line);
|
||||
if (!line.size())
|
||||
if (line.empty())
|
||||
return false;
|
||||
unsigned int chunkSize = 0;
|
||||
if (sscanf(line.c_str(), "%x", &chunkSize) != 1) {
|
||||
@@ -444,10 +445,10 @@ int Client::ReadResponseHeaders(net::Buffer *readbuf, std::vector<std::string> &
|
||||
if (!sz || sz < 0)
|
||||
break;
|
||||
VERBOSE_LOG(Log::HTTP, "Header line: %s", line.c_str());
|
||||
responseHeaders.emplace_back(line);
|
||||
responseHeaders.push_back(std::move(line));
|
||||
}
|
||||
|
||||
if (responseHeaders.size() == 0) {
|
||||
if (responseHeaders.empty()) {
|
||||
ERROR_LOG(Log::HTTP, "No HTTP response headers");
|
||||
return -1;
|
||||
}
|
||||
@@ -530,7 +531,7 @@ int Client::ReadResponseEntity(net::Buffer *readbuf, const std::vector<std::stri
|
||||
}
|
||||
|
||||
HTTPRequest::HTTPRequest(RequestMethod method, std::string_view url, std::string_view postData, std::string_view postMime, const Path &outfile, RequestFlags flags, net::ResolveFunc customResolve, std::string_view name)
|
||||
: Request(method, url, name, outfile, &cancelled_, flags), postData_(postData), postMime_(postMime), customResolve_(customResolve) {
|
||||
: Request(method, url, name, outfile, &cancelled_, flags), postData_(postData), postMime_(postMime), customResolve_(std::move(customResolve)) {
|
||||
}
|
||||
|
||||
HTTPRequest::~HTTPRequest() {
|
||||
|
||||
@@ -5,6 +5,7 @@
|
||||
#include <thread>
|
||||
#include <cstdint>
|
||||
#include <string>
|
||||
#include <utility>
|
||||
|
||||
#include "Common/File/Path.h"
|
||||
#include "Common/Net/NetBuffer.h"
|
||||
@@ -19,9 +20,9 @@ class Connection {
|
||||
public:
|
||||
virtual ~Connection();
|
||||
|
||||
explicit Connection(ResolveFunc func) : customResolve_(func) {}
|
||||
explicit Connection(ResolveFunc func) : customResolve_(std::move(func)) {}
|
||||
|
||||
// Inits the sockaddr_in.
|
||||
// Inits the addrinfo chain.
|
||||
bool Resolve(const char *host, int port, DNSType type = DNSType::ANY);
|
||||
|
||||
bool Connect(int maxTries = 2, double timeout = 20.0f, bool *cancelConnect = nullptr);
|
||||
@@ -55,9 +56,9 @@ bool GetHeaderValue(const std::vector<std::string> &responseHeaders, std::string
|
||||
|
||||
class RequestParams {
|
||||
public:
|
||||
RequestParams() {}
|
||||
RequestParams() = default;
|
||||
explicit RequestParams(const char *r) : resource(r) {}
|
||||
RequestParams(const std::string &r, const char *a) : resource(r), acceptMime(a) {}
|
||||
RequestParams(std::string r, const char *a) : resource(std::move(r)), acceptMime(a) {}
|
||||
|
||||
std::string resource;
|
||||
const char *acceptMime = "*/*";
|
||||
|
||||
Reference in new issue
Block a user