LLVM 23.0.0git
StreamedHTTPResponseHandler.h
Go to the documentation of this file.
1//===----------------------------------------------------------------------===//
2//
3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4// See https://llvm.org/LICENSE.txt for license information.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6//
7//===----------------------------------------------------------------------===//
8///
9/// \file
10/// An HTTPResponseHandler that streams the response body to a CachedFileStream.
11///
12//===----------------------------------------------------------------------===//
13
14#ifndef LLVM_SUPPORT_HTTP_STREAMEDHTTPRESPONSEHANDLER_H
15#define LLVM_SUPPORT_HTTP_STREAMEDHTTPRESPONSEHANDLER_H
16
18#include "llvm/Support/Error.h"
20#include <functional>
21#include <memory>
22
23namespace llvm {
24
25/// A handler which streams the returned data to a CachedFileStream. The cache
26/// file is only created if a 200 OK status is observed.
28 using CreateStreamFn =
29 std::function<Expected<std::unique_ptr<CachedFileStream>>()>;
30 CreateStreamFn CreateStream;
31 HTTPClient &Client;
32 std::unique_ptr<CachedFileStream> FileStream;
33
34public:
35 StreamedHTTPResponseHandler(CreateStreamFn CreateStream, HTTPClient &Client)
36 : CreateStream(std::move(CreateStream)), Client(Client) {}
37
38 /// Must be called exactly once after the writes have been completed
39 /// but before the StreamedHTTPResponseHandler object is destroyed.
40 Error commit();
41
42 virtual ~StreamedHTTPResponseHandler() = default;
43
44 Error handleBodyChunk(StringRef BodyChunk) override;
45};
46
47} // end namespace llvm
48
49#endif // LLVM_SUPPORT_HTTP_STREAMEDHTTPRESPONSEHANDLER_H
This file contains the declarations of the HTTPClient library for issuing HTTP requests and handling ...
Lightweight error class with error context and mandatory checking.
Definition Error.h:159
A reusable client that can perform HTTPRequests through a network socket.
Definition HTTPClient.h:53
A handler for state updates occurring while an HTTPRequest is performed.
Definition HTTPClient.h:43
virtual ~StreamedHTTPResponseHandler()=default
StreamedHTTPResponseHandler(CreateStreamFn CreateStream, HTTPClient &Client)
Error commit()
Must be called exactly once after the writes have been completed but before the StreamedHTTPResponseH...
Error handleBodyChunk(StringRef BodyChunk) override
Processes an additional chunk of bytes of the HTTP response body.
StringRef - Represent a constant reference to a string, i.e.
Definition StringRef.h:55
This is an optimization pass for GlobalISel generic memory operations.
OutputIt move(R &&Range, OutputIt Out)
Provide wrappers to std::move which take ranges instead of having to pass begin/end explicitly.
Definition STLExtras.h:1917
Implement std::hash so that hash_code can be used in STL containers.
Definition BitVector.h:870