http: Skip processing response body for void.
No need to decompress or copy between buffers.
This commit is contained in:
parent
20443571bd
commit
1459c16fb8
4 changed files with 30 additions and 19 deletions
|
@ -10,8 +10,15 @@
|
||||||
class Buffer {
|
class Buffer {
|
||||||
public:
|
public:
|
||||||
Buffer();
|
Buffer();
|
||||||
|
Buffer(Buffer &&) = default;
|
||||||
~Buffer();
|
~Buffer();
|
||||||
|
|
||||||
|
static Buffer Void() {
|
||||||
|
Buffer buf;
|
||||||
|
buf.void_ = true;
|
||||||
|
return buf;
|
||||||
|
}
|
||||||
|
|
||||||
// Write max [length] bytes to the returned pointer.
|
// Write max [length] bytes to the returned pointer.
|
||||||
// Any other operation on this Buffer invalidates the pointer.
|
// Any other operation on this Buffer invalidates the pointer.
|
||||||
char *Append(size_t length);
|
char *Append(size_t length);
|
||||||
|
@ -65,10 +72,12 @@ public:
|
||||||
size_t size() const { return data_.size(); }
|
size_t size() const { return data_.size(); }
|
||||||
bool empty() const { return size() == 0; }
|
bool empty() const { return size() == 0; }
|
||||||
void clear() { data_.resize(0); }
|
void clear() { data_.resize(0); }
|
||||||
|
bool IsVoid() { return void_; }
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
// TODO: Find a better internal representation, like a cord.
|
// TODO: Find a better internal representation, like a cord.
|
||||||
std::vector<char> data_;
|
std::vector<char> data_;
|
||||||
|
bool void_ = false;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
DISALLOW_COPY_AND_ASSIGN(Buffer);
|
DISALLOW_COPY_AND_ASSIGN(Buffer);
|
||||||
|
|
|
@ -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.
|
// output now contains the rest of the reply. Dechunk it.
|
||||||
if (chunked) {
|
if (!output->IsVoid()) {
|
||||||
DeChunk(readbuf, output, contentLength, &progress->progress);
|
if (chunked) {
|
||||||
} else {
|
DeChunk(readbuf, output, contentLength, &progress->progress);
|
||||||
output->Append(*readbuf);
|
} else {
|
||||||
}
|
output->Append(*readbuf);
|
||||||
|
}
|
||||||
// If it's gzipped, we decompress it and put it back in the buffer.
|
|
||||||
if (gzip) {
|
// If it's gzipped, we decompress it and put it back in the buffer.
|
||||||
std::string compressed, decompressed;
|
if (gzip) {
|
||||||
output->TakeAll(&compressed);
|
std::string compressed, decompressed;
|
||||||
bool result = decompress_string(compressed, &decompressed);
|
output->TakeAll(&compressed);
|
||||||
if (!result) {
|
bool result = decompress_string(compressed, &decompressed);
|
||||||
ERROR_LOG(IO, "Error decompressing using zlib");
|
if (!result) {
|
||||||
progress->progress = 0.0f;
|
ERROR_LOG(IO, "Error decompressing using zlib");
|
||||||
return -1;
|
progress->progress = 0.0f;
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
output->Append(decompressed);
|
||||||
}
|
}
|
||||||
output->Append(decompressed);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
progress->progress = 1.0f;
|
progress->progress = 1.0f;
|
||||||
|
|
|
@ -262,11 +262,11 @@ namespace Reporting
|
||||||
{
|
{
|
||||||
http::Client http;
|
http::Client http;
|
||||||
http::RequestProgress progress;
|
http::RequestProgress progress;
|
||||||
Buffer theVoid;
|
Buffer theVoid = Buffer::Void();
|
||||||
|
|
||||||
http.SetUserAgent(StringFromFormat("PPSSPP/%s", PPSSPP_GIT_VERSION));
|
http.SetUserAgent(StringFromFormat("PPSSPP/%s", PPSSPP_GIT_VERSION));
|
||||||
|
|
||||||
if (output == NULL)
|
if (output == nullptr)
|
||||||
output = &theVoid;
|
output = &theVoid;
|
||||||
|
|
||||||
const char *serverHost = ServerHostname();
|
const char *serverHost = ServerHostname();
|
||||||
|
|
|
@ -64,7 +64,7 @@ static bool RegisterServer(int port) {
|
||||||
bool success = false;
|
bool success = false;
|
||||||
http::Client http;
|
http::Client http;
|
||||||
http::RequestProgress progress;
|
http::RequestProgress progress;
|
||||||
Buffer theVoid;
|
Buffer theVoid = Buffer::Void();
|
||||||
|
|
||||||
http.SetUserAgent(StringFromFormat("PPSSPP/%s", PPSSPP_GIT_VERSION));
|
http.SetUserAgent(StringFromFormat("PPSSPP/%s", PPSSPP_GIT_VERSION));
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue