mirror of
https://github.com/chromium/crashpad.git
synced 2025-03-09 14:06:33 +00:00
Implement unlengthed response read in HTTPTransport
Of course, as soon as I tried it against the real endpoint on Fuchsia, the server just spits out raw crash id as a string without specifying Content-Length. Bug: crashpad:196, crashpad:30 Change-Id: I22af87589a8801cdfece0a7b862e70e0e7097f1f Reviewed-on: https://chromium-review.googlesource.com/1024953 Commit-Queue: Scott Graham <scottmg@chromium.org> Reviewed-by: Joshua Peraza <jperaza@chromium.org>
This commit is contained in:
parent
63d331e57a
commit
5636102fb4
@ -30,22 +30,6 @@ namespace crashpad {
|
||||
|
||||
namespace {
|
||||
|
||||
// Reads from the current file position to EOF and returns as a string of bytes.
|
||||
bool ReadRestOfFileAsString(FileHandle handle, std::string* contents) {
|
||||
char buffer[4096];
|
||||
FileOperationResult rv;
|
||||
std::string local_contents;
|
||||
while ((rv = ReadFile(handle, buffer, sizeof(buffer))) > 0) {
|
||||
local_contents.append(buffer, rv);
|
||||
}
|
||||
if (rv < 0) {
|
||||
PLOG(ERROR) << "ReadFile";
|
||||
return false;
|
||||
}
|
||||
contents->swap(local_contents);
|
||||
return true;
|
||||
}
|
||||
|
||||
base::FilePath ReplaceFinalExtension(
|
||||
const base::FilePath& path,
|
||||
const base::FilePath::StringType extension) {
|
||||
@ -768,7 +752,7 @@ bool CrashReportDatabaseGeneric::ReadMetadata(const base::FilePath& path,
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!ReadRestOfFileAsString(handle.get(), &report->id)) {
|
||||
if (!LoggingReadToEOF(handle.get(), &report->id)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
|
@ -156,16 +156,11 @@ void CheckedReadFileAtEOF(FileHandle file) {
|
||||
}
|
||||
}
|
||||
|
||||
bool LoggingReadEntireFile(const base::FilePath& path, std::string* contents) {
|
||||
ScopedFileHandle handle(LoggingOpenFileForRead(path));
|
||||
if (!handle.is_valid()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
bool LoggingReadToEOF(FileHandle file, std::string* contents) {
|
||||
char buffer[4096];
|
||||
FileOperationResult rv;
|
||||
std::string local_contents;
|
||||
while ((rv = ReadFile(handle.get(), buffer, sizeof(buffer))) > 0) {
|
||||
while ((rv = ReadFile(file, buffer, sizeof(buffer))) > 0) {
|
||||
DCHECK_LE(static_cast<size_t>(rv), sizeof(buffer));
|
||||
local_contents.append(buffer, rv);
|
||||
}
|
||||
@ -177,6 +172,15 @@ bool LoggingReadEntireFile(const base::FilePath& path, std::string* contents) {
|
||||
return true;
|
||||
}
|
||||
|
||||
bool LoggingReadEntireFile(const base::FilePath& path, std::string* contents) {
|
||||
ScopedFileHandle handle(LoggingOpenFileForRead(path));
|
||||
if (!handle.is_valid()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return LoggingReadToEOF(handle.get(), contents);
|
||||
}
|
||||
|
||||
void CheckedCloseFile(FileHandle file) {
|
||||
CHECK(LoggingCloseFile(file));
|
||||
}
|
||||
|
@ -318,7 +318,13 @@ void CheckedWriteFile(FileHandle file, const void* buffer, size_t size);
|
||||
//! \sa ReadFile
|
||||
void CheckedReadFileAtEOF(FileHandle file);
|
||||
|
||||
//! brief Wraps LoggingOpenFileForRead() and ReadFile() reading the entire file
|
||||
//! \brief Wraps ReadFile() to read from the current file position to the end of
|
||||
//! the file into \a contents.
|
||||
//!
|
||||
//! \return `true` on success, or `false` with a message logged.
|
||||
bool LoggingReadToEOF(FileHandle file, std::string* contents);
|
||||
|
||||
//! \brief Wraps LoggingOpenFileForRead() and ReadFile() reading the entire file
|
||||
//! into \a contents.
|
||||
//!
|
||||
//! \return `true` on success, or `false` with a message logged.
|
||||
|
@ -367,14 +367,9 @@ bool ReadResponse(int sock, std::string* response_body) {
|
||||
if (it != response_headers.end() && it->second == "chunked") {
|
||||
chunked = true;
|
||||
}
|
||||
if (!chunked) {
|
||||
// TODO(scottmg): https://crashpad.chromium.org/bug/196. Doesn't happen
|
||||
// in practice, but is possible.
|
||||
LOG(ERROR) << "unimplemented non-chunked without Content-Length";
|
||||
return false;
|
||||
}
|
||||
|
||||
return ReadContentChunked(sock, response_body);
|
||||
return chunked ? ReadContentChunked(sock, response_body)
|
||||
: LoggingReadToEOF(sock, response_body);
|
||||
}
|
||||
|
||||
bool HTTPTransportSocket::ExecuteSynchronously(std::string* response_body) {
|
||||
|
Loading…
x
Reference in New Issue
Block a user