FastLED 3.10.8
Loading...
Searching...
No Matches
fetch_request.h
Go to the documentation of this file.
1#pragma once
2
3#include "fl/task/promise.h"
4#include "fl/net/http/fetch.h" // Includes response class // IWYU pragma: keep
5#include "fl/stl/string.h"
6#include "fl/stl/url.h"
7#include "fl/stl/int.h"
8#include "fl/stl/noexcept.h"
9#include "platforms/is_platform.h"
10
11// Forward declaration for hostent (platform-specific type)
12struct hostent;
13
14namespace fl {
15namespace net {
16namespace http {
17
18namespace detail {
28bool build_http_request(const RequestOptions& options, const fl::string& path,
29 const fl::string& host, fl::string* out) FL_NO_EXCEPT;
30} // namespace detail
31
40public:
49
55
58
64
66 bool is_done() const FL_NO_EXCEPT { return mState == COMPLETED || mState == FAILED; }
67
69 State get_state() const FL_NO_EXCEPT { return mState; }
70
71private:
74 RequestOptions mOptions; // method, headers and body to send
75
76 // Parsed URL
79 int mPort;
81
82 // Socket state
83#ifdef FL_IS_WIN
84 // Winsock's SOCKET is UINT_PTR. Holding it in an int truncated the handle
85 // on 64-bit Windows and made the `< 0` failure check always false.
86 using SocketHandle = fl::uptr;
87#else
88 using SocketHandle = int;
89#endif
91 ::hostent* mDnsResult; // Use global namespace to avoid conflict
92
93 // Send/receive buffers
96 size_t mBytesSent;
97
98 // Timeouts
100
101 // State handlers
106
107 // Completion helpers
109 void complete_error(const char* message) FL_NO_EXCEPT;
110
111 // Utilities
114};
115
116} // namespace http
117} // namespace net
118} // namespace fl
Fetch options builder (fluent interface)
Definition fetch.h:195
fl::task::Promise< Response > mPromise
void handle_dns_lookup() FL_NO_EXCEPT
void close_socket() FL_NO_EXCEPT
void update() FL_NO_EXCEPT
Pump the state machine (called by fl::task every update interval)
void handle_sending() FL_NO_EXCEPT
void handle_connecting() FL_NO_EXCEPT
Response parse_http_response(const fl::string &raw) FL_NO_EXCEPT
~FetchRequest() FL_NO_EXCEPT
Destructor - closes socket if still open.
State get_state() const FL_NO_EXCEPT
Get current state.
FetchRequest(const fl::string &url, const FetchOptions &opts, fl::task::Promise< Response > promise) FL_NO_EXCEPT
Construct a new fetch request.
void handle_receiving() FL_NO_EXCEPT
@ DNS_LOOKUP
Resolving hostname (brief blocking ~10-100ms)
@ RECEIVING
Receiving HTTP response (non-blocking)
@ SENDING
Sending HTTP request (non-blocking)
@ CONNECTING
Waiting for socket connection (non-blocking)
@ COMPLETED
Successfully completed.
bool is_done() const FL_NO_EXCEPT
Check if request is complete (success or failure)
void complete_error(const char *message) FL_NO_EXCEPT
void complete_success(const Response &resp) FL_NO_EXCEPT
HTTP response class (unified interface)
Definition fetch.h:78
Promise class that provides fluent .then() and .catch_() semantics This is a lightweight wrapper arou...
Definition promise.h:58
Definition url.h:15
Unified HTTP fetch API for FastLED (cross-platform)
bool build_http_request(const RequestOptions &options, const fl::string &path, const fl::string &host, fl::string *out) FL_NO_EXCEPT
The HTTP/1.1 request FetchRequest sends: options.method (GET when empty) on the request line,...
u8 u8 fract8 blur_amount FL_NO_EXCEPT
Definition blur.h:186
Base definition for an LED controller.
Definition crgb.hpp:179
Promise-based fluent API for FastLED - standalone async primitives.
Request options (matches JavaScript fetch RequestInit)
Definition fetch.h:184
Lightweight URL parser for embedded environments.