Sane C++ Libraries
C++ Platform Abstraction Libraries
Loading...
Searching...
No Matches
HttpClient.h
1// Copyright (c) Stefano Cristiano
2// SPDX-License-Identifier: MIT
3#pragma once
4#include "../Async/Async.h"
5#include "../Containers/Vector.h"
6#include "../Socket/Socket.h"
7#include "../Strings/String.h"
8namespace SC
9{
11struct HttpClient;
12} // namespace SC
13
16
19
22{
28
30
32 [[nodiscard]] StringView getResponse() const;
33
34 Result setCustomDebugName(const StringView debugName) { return Result(customDebugName.assign(debugName)); }
35
36 private:
37 void onConnected(AsyncSocketConnect::Result& result);
38 void onAfterSend(AsyncSocketSend::Result& result);
39 void onAfterRead(AsyncSocketReceive::Result& result);
40
41 SmallBuffer<1024> content;
42
43 String customDebugName;
44
45 AsyncSocketConnect connectAsync;
46 AsyncSocketSend sendAsync;
47 AsyncSocketReceive receiveAsync;
48 SocketDescriptor clientSocket;
49 AsyncEventLoop* eventLoop = nullptr;
50};
Asynchronous I/O (files, sockets, timers, processes, fs events, threads wake-up) (see Async) AsyncEve...
Definition Async.h:1199
Helper holding CompletionData for a specific AsyncRequest-derived class.
Definition Async.h:288
Starts a socket connect operation, connecting to a remote endpoint.
Definition Async.h:490
Definition Async.h:610
Starts a socket receive operation, receiving bytes from a remote endpoint.
Definition Async.h:600
Starts a socket send operation, sending bytes to a remote endpoint.
Definition Async.h:524
Wraps function pointers, member functions and lambdas without ever allocating.
Definition Function.h:19
Http async client.
Definition HttpClient.h:22
Result get(AsyncEventLoop &loop, StringView url)
Setups this client to execute a GET request on the given url.
Delegate< HttpClient & > callback
The callback that is called after GET operation succeeded.
Definition HttpClient.h:29
StringView getResponse() const
Get the response StringView sent by the server.
An ascii string used as boolean result. SC_TRY macro forwards errors to caller.
Definition Result.h:12
A SC::Buffer with a dedicated custom inline buffer to avoid heap allocation.
Definition Buffer.h:38
Low-level OS socket handle.
Definition Socket.h:163
Non-owning view over a range of characters with UTF Encoding.
Definition StringView.h:46
A non-modifiable owning string with associated encoding.
Definition String.h:29
bool assign(StringSpan sv)
Assigns a StringView to this String, replacing existing contents.