LLVM 17.0.0git
HTTPClient.h
Go to the documentation of this file.
1//===-- llvm/Support/HTTPClient.h - HTTP client library ---------*- C++ -*-===//
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/// This file contains the declarations of the HTTPClient library for issuing
11/// HTTP requests and handling the responses.
12///
13//===----------------------------------------------------------------------===//
14
15#ifndef LLVM_DEBUGINFOD_HTTPCLIENT_H
16#define LLVM_DEBUGINFOD_HTTPCLIENT_H
17
18#include "llvm/Support/Error.h"
20
21#include <chrono>
22
23namespace llvm {
24
25enum class HTTPMethod { GET };
26
27/// A stateless description of an outbound HTTP request.
32 bool FollowRedirects = true;
34};
35
36bool operator==(const HTTPRequest &A, const HTTPRequest &B);
37
38/// A handler for state updates occurring while an HTTPRequest is performed.
39/// Can trigger the client to abort the request by returning an Error from any
40/// of its methods.
42public:
43 /// Processes an additional chunk of bytes of the HTTP response body.
44 virtual Error handleBodyChunk(StringRef BodyChunk) = 0;
45
46protected:
48};
49
50/// A reusable client that can perform HTTPRequests through a network socket.
52#ifdef LLVM_ENABLE_CURL
53 void *Curl = nullptr;
54#endif
55
56public:
59
60 static bool IsInitialized;
61
62 /// Returns true only if LLVM has been compiled with a working HTTPClient.
63 static bool isAvailable();
64
65 /// Must be called at the beginning of a program, while it is a single thread.
66 static void initialize();
67
68 /// Must be called at the end of a program, while it is a single thread.
69 static void cleanup();
70
71 /// Sets the timeout for the entire request, in milliseconds. A zero or
72 /// negative value means the request never times out.
73 void setTimeout(std::chrono::milliseconds Timeout);
74
75 /// Performs the Request, passing response data to the Handler. Returns all
76 /// errors which occur during the request. Aborts if an error is returned by a
77 /// Handler method.
78 Error perform(const HTTPRequest &Request, HTTPResponseHandler &Handler);
79
80 /// Returns the last received response code or zero if none.
81 unsigned responseCode();
82};
83
84} // end namespace llvm
85
86#endif // LLVM_DEBUGINFOD_HTTPCLIENT_H
static GCRegistry::Add< OcamlGC > B("ocaml", "ocaml 3.10-compatible GC")
static GCRegistry::Add< ErlangGC > A("erlang", "erlang-compatible garbage collector")
Lightweight error class with error context and mandatory checking.
Definition: Error.h:156
A reusable client that can perform HTTPRequests through a network socket.
Definition: HTTPClient.h:51
static bool isAvailable()
Returns true only if LLVM has been compiled with a working HTTPClient.
Definition: HTTPClient.cpp:143
static bool IsInitialized
Definition: HTTPClient.h:60
unsigned responseCode()
Returns the last received response code or zero if none.
Definition: HTTPClient.cpp:156
static void initialize()
Must be called at the beginning of a program, while it is a single thread.
Definition: HTTPClient.cpp:145
Error perform(const HTTPRequest &Request, HTTPResponseHandler &Handler)
Performs the Request, passing response data to the Handler.
Definition: HTTPClient.cpp:151
void setTimeout(std::chrono::milliseconds Timeout)
Sets the timeout for the entire request, in milliseconds.
Definition: HTTPClient.cpp:149
static void cleanup()
Must be called at the end of a program, while it is a single thread.
Definition: HTTPClient.cpp:147
A handler for state updates occurring while an HTTPRequest is performed.
Definition: HTTPClient.h:41
virtual Error handleBodyChunk(StringRef BodyChunk)=0
Processes an additional chunk of bytes of the HTTP response body.
SmallString - A SmallString is just a SmallVector with methods and accessors that make it work better...
Definition: SmallString.h:26
This is a 'vector' (really, a variable-sized array), optimized for the case when the array is small.
Definition: SmallVector.h:1200
StringRef - Represent a constant reference to a string, i.e.
Definition: StringRef.h:50
This is an optimization pass for GlobalISel generic memory operations.
Definition: AddressRanges.h:18
bool operator==(const AddressRangeValuePair &LHS, const AddressRangeValuePair &RHS)
HTTPMethod
Definition: HTTPClient.h:25
A stateless description of an outbound HTTP request.
Definition: HTTPClient.h:28
SmallVector< std::string, 0 > Headers
Definition: HTTPClient.h:30
SmallString< 128 > Url
Definition: HTTPClient.h:29
HTTPMethod Method
Definition: HTTPClient.h:31