When an HTTP request fails while it already received some data, the cached file stream is never committed. Destroying it in that state raises a fatal error, crashing the program (see #184728). This PR adds an `abort` method that should be called in this situation before destroying the stream. For the default implementation, only the output stream is closed. For the `CacheStream` in `llvm::localCache`, the temporary file is discarded as well. The test is based on David's reproducer. Since WinHttp seems to discard the content-length header, I switched to timing out the response instead. Fixes #184728. This is still a bug for the symstore locator in lldb, but I'll fix that in a followup. fix: disable test partial-response.test on system-windows
41 lines
1.2 KiB
C++
41 lines
1.2 KiB
C++
//===----------------------------------------------------------------------===//
|
|
//
|
|
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
|
|
// See https://llvm.org/LICENSE.txt for license information.
|
|
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
|
|
//
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
#include "llvm/HTTP/StreamedHTTPResponseHandler.h"
|
|
|
|
namespace llvm {
|
|
|
|
Error StreamedHTTPResponseHandler::handleBodyChunk(StringRef BodyChunk) {
|
|
if (!FileStream) {
|
|
unsigned Code = Client.responseCode();
|
|
if (Code && Code != 200)
|
|
return Error::success();
|
|
Expected<std::unique_ptr<CachedFileStream>> FileStreamOrError =
|
|
CreateStream();
|
|
if (!FileStreamOrError)
|
|
return FileStreamOrError.takeError();
|
|
FileStream = std::move(*FileStreamOrError);
|
|
}
|
|
*FileStream->OS << BodyChunk;
|
|
return Error::success();
|
|
}
|
|
|
|
Error StreamedHTTPResponseHandler::commit() {
|
|
if (FileStream)
|
|
return FileStream->commit();
|
|
return Error::success();
|
|
}
|
|
|
|
Error StreamedHTTPResponseHandler::abort() {
|
|
if (FileStream)
|
|
return FileStream->abort();
|
|
return Error::success();
|
|
}
|
|
|
|
} // namespace llvm
|