23#ifdef LLVM_ENABLE_CURL
32 return A.Url ==
B.Url &&
A.Method ==
B.Method &&
33 A.FollowRedirects ==
B.FollowRedirects;
46#ifdef LLVM_ENABLE_CURL
52 curl_global_init(CURL_GLOBAL_ALL);
59 curl_global_cleanup();
65 if (
Timeout < std::chrono::milliseconds(0))
66 Timeout = std::chrono::milliseconds(0);
67 curl_easy_setopt(Curl, CURLOPT_TIMEOUT_MS,
Timeout.count());
73struct CurlHTTPRequest {
74 CurlHTTPRequest(HTTPResponseHandler &Handler) : Handler(Handler) {}
75 void storeError(
Error Err) {
76 ErrorState =
joinErrors(std::move(Err), std::move(ErrorState));
78 HTTPResponseHandler &Handler;
82static size_t curlWriteFunction(
char *Contents,
size_t Size,
size_t NMemb,
83 CurlHTTPRequest *CurlRequest) {
86 CurlRequest->Handler.handleBodyChunk(
StringRef(Contents,
Size))) {
87 CurlRequest->storeError(std::move(Err));
95 "Must call HTTPClient::initialize() at the beginning of main().");
98 Curl = curl_easy_init();
99 assert(Curl &&
"Curl could not be initialized");
101 curl_easy_setopt(Curl, CURLOPT_WRITEFUNCTION, curlWriteFunction);
103 curl_easy_setopt(Curl, CURLOPT_ACCEPT_ENCODING,
"");
112 "Unsupported CURL request method.");
114 SmallString<128> Url = Request.
Url;
115 curl_easy_setopt(Curl, CURLOPT_URL, Url.
c_str());
116 curl_easy_setopt(Curl, CURLOPT_FOLLOWLOCATION, Request.
FollowRedirects);
118 curl_slist *Headers =
nullptr;
119 for (
const std::string &Header : Request.
Headers)
120 Headers = curl_slist_append(Headers, Header.c_str());
121 curl_easy_setopt(Curl, CURLOPT_HTTPHEADER, Headers);
123 CurlHTTPRequest CurlRequest(Handler);
124 curl_easy_setopt(Curl, CURLOPT_WRITEDATA, &CurlRequest);
125 CURLcode CurlRes = curl_easy_perform(Curl);
126 curl_slist_free_all(Headers);
127 if (CurlRes != CURLE_OK)
128 return joinErrors(std::move(CurlRequest.ErrorState),
130 "curl_easy_perform() failed: %s\n",
131 curl_easy_strerror(CurlRes)));
132 return std::move(CurlRequest.ErrorState);
137 curl_easy_getinfo(Curl, CURLINFO_RESPONSE_CODE, &Code);
assert(UImm &&(UImm !=~static_cast< T >(0)) &&"Invalid immediate!")
This file implements a class to represent arbitrary precision integral constant values and operations...
static GCRegistry::Add< ErlangGC > A("erlang", "erlang-compatible garbage collector")
static GCRegistry::Add< OcamlGC > B("ocaml", "ocaml 3.10-compatible GC")
ManagedStatic< HTTPClientCleanup > Cleanup
This file contains the declarations of the HTTPClient library for issuing HTTP requests and handling ...
Lightweight error class with error context and mandatory checking.
static ErrorSuccess success()
Create a success value.
static bool isAvailable()
Returns true only if LLVM has been compiled with a working HTTPClient.
static bool IsInitialized
unsigned responseCode()
Returns the last received response code or zero if none.
static void initialize()
Must be called at the beginning of a program, while it is a single thread.
Error perform(const HTTPRequest &Request, HTTPResponseHandler &Handler)
Performs the Request, passing response data to the Handler.
void setTimeout(std::chrono::milliseconds Timeout)
Sets the timeout for the entire request, in milliseconds.
static void cleanup()
Must be called at the end of a program, while it is a single thread.
A handler for state updates occurring while an HTTPRequest is performed.
ManagedStatic - This transparently changes the behavior of global statics to be lazily constructed on...
StringRef - Represent a constant reference to a string, i.e.
#define llvm_unreachable(msg)
Marks that the current location is not supposed to be reachable.
NodeAddr< CodeNode * > Code
This is an optimization pass for GlobalISel generic memory operations.
Error createStringError(std::error_code EC, char const *Fmt, const Ts &... Vals)
Create formatted StringError object.
bool operator==(const AddressRangeValuePair &LHS, const AddressRangeValuePair &RHS)
Error joinErrors(Error E1, Error E2)
Concatenate errors.
@ Timeout
Reached timeout while waiting for the owner to release the lock.
A stateless description of an outbound HTTP request.
SmallVector< std::string, 0 > Headers
HTTPRequest(StringRef Url)