http: Skip processing response body for void.

No need to decompress or copy between buffers.
This commit is contained in:
Unknown W. Brackets 2021-05-01 10:59:15 -07:00
parent 20443571bd
commit 1459c16fb8
4 changed files with 30 additions and 19 deletions

View File

@ -10,8 +10,15 @@
class Buffer {
public:
Buffer();
Buffer(Buffer &&) = default;
~Buffer();
static Buffer Void() {
Buffer buf;
buf.void_ = true;
return buf;
}
// Write max [length] bytes to the returned pointer.
// Any other operation on this Buffer invalidates the pointer.
char *Append(size_t length);
@ -65,10 +72,12 @@ public:
size_t size() const { return data_.size(); }
bool empty() const { return size() == 0; }
void clear() { data_.resize(0); }
bool IsVoid() { return void_; }
protected:
// TODO: Find a better internal representation, like a cord.
std::vector<char> data_;
bool void_ = false;
private:
DISALLOW_COPY_AND_ASSIGN(Buffer);

View File

@ -432,23 +432,25 @@ int Client::ReadResponseEntity(net::Buffer *readbuf, const std::vector<std::stri
}
// output now contains the rest of the reply. Dechunk it.
if (chunked) {
DeChunk(readbuf, output, contentLength, &progress->progress);
} else {
output->Append(*readbuf);
}
// If it's gzipped, we decompress it and put it back in the buffer.
if (gzip) {
std::string compressed, decompressed;
output->TakeAll(&compressed);
bool result = decompress_string(compressed, &decompressed);
if (!result) {
ERROR_LOG(IO, "Error decompressing using zlib");
progress->progress = 0.0f;
return -1;
if (!output->IsVoid()) {
if (chunked) {
DeChunk(readbuf, output, contentLength, &progress->progress);
} else {
output->Append(*readbuf);
}
// If it's gzipped, we decompress it and put it back in the buffer.
if (gzip) {
std::string compressed, decompressed;
output->TakeAll(&compressed);
bool result = decompress_string(compressed, &decompressed);
if (!result) {
ERROR_LOG(IO, "Error decompressing using zlib");
progress->progress = 0.0f;
return -1;
}
output->Append(decompressed);
}
output->Append(decompressed);
}
progress->progress = 1.0f;

View File

@ -262,11 +262,11 @@ namespace Reporting
{
http::Client http;
http::RequestProgress progress;
Buffer theVoid;
Buffer theVoid = Buffer::Void();
http.SetUserAgent(StringFromFormat("PPSSPP/%s", PPSSPP_GIT_VERSION));
if (output == NULL)
if (output == nullptr)
output = &theVoid;
const char *serverHost = ServerHostname();

View File

@ -64,7 +64,7 @@ static bool RegisterServer(int port) {
bool success = false;
http::Client http;
http::RequestProgress progress;
Buffer theVoid;
Buffer theVoid = Buffer::Void();
http.SetUserAgent(StringFromFormat("PPSSPP/%s", PPSSPP_GIT_VERSION));