Kurlyk
Loading...
Searching...
No Matches
HttpRequestContext.hpp
Go to the documentation of this file.
1#pragma once
2#ifndef _KURLYK_HTTP_REQUEST_CONTEXT_HPP_INCLUDED
3#define _KURLYK_HTTP_REQUEST_CONTEXT_HPP_INCLUDED
4
7
8namespace kurlyk {
9
13 public:
14 using time_point_t = std::chrono::steady_clock::time_point;
15
16 std::unique_ptr<HttpRequest> request;
20 uint64_t in_flight_token = 0;
21 std::function<void()> on_complete;
22 std::atomic<bool> complete_called{false};
23
28 std::unique_ptr<HttpRequest> request_ptr,
30 : request(std::move(request_ptr)),
31 callback(std::move(callback)),
34 complete_called(false) {
35 }
36
37 HttpRequestContext() = default;
38
40 void complete() {
41 bool expected = false;
42 if (!complete_called.compare_exchange_strong(expected, true)) {
43 return;
44 }
45 if (on_complete) {
47 }
48 }
49 }; // HttpRequestContext
50
51} // namespace kurlyk
52
53#endif // _KURLYK_HTTP_REQUEST_CONTEXT_HPP_INCLUDED
void complete()
Invokes on_complete exactly once. Thread-safe and idempotent.
time_point_t start_time
Time when the request was initially created or last retried.
std::unique_ptr< HttpRequest > request
The HTTP request associated with this context.
std::atomic< bool > complete_called
True after on_complete has been invoked.
std::function< void()> on_complete
Callback invoked once when the request finishes (including retries).
long retry_attempt
Number of retry attempts made for this request.
std::chrono::steady_clock::time_point time_point_t
uint64_t in_flight_token
Token for sequential rate-limit tracking.
HttpResponseCallback callback
Callback function to be invoked when the request completes.
HttpRequestContext(std::unique_ptr< HttpRequest > request_ptr, HttpResponseCallback callback)
Constructs a HttpRequestContext with the specified request and callback.
Primary namespace for the Kurlyk library, encompassing initialization, request management,...
std::function< void(HttpResponsePtr response)> HttpResponseCallback
Callback invoked with an HTTP response.
Enables use of ClientError with std::error_code.