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 "../Foundation/StringSpan.h"
7#include "../Memory/String.h"
8#include "../Socket/Socket.h"
9namespace SC
10{
12struct HttpClient;
13} // namespace SC
14
17
20
23{
29
31
33 [[nodiscard]] StringSpan getResponse() const;
34
35 Result setCustomDebugName(const StringSpan debugName) { return Result(customDebugName.assign(debugName)); }
36
37 private:
38 void onConnected(AsyncSocketConnect::Result& result);
39 void onAfterSend(AsyncSocketSend::Result& result);
40 void onAfterRead(AsyncSocketReceive::Result& result);
41
42 SmallBuffer<1024> content;
43
44 String customDebugName;
45
46 AsyncSocketConnect connectAsync;
47 AsyncSocketSend sendAsync;
48 AsyncSocketReceive receiveAsync;
49 SocketDescriptor clientSocket;
50 AsyncEventLoop* eventLoop = nullptr;
51};
Asynchronous I/O (files, sockets, timers, processes, fs events, threads wake-up) (see Async) AsyncEve...
Definition Async.h:1198
Helper holding CompletionData for a specific AsyncRequest-derived class.
Definition Async.h:287
Starts a socket connect operation, connecting to a remote endpoint.
Definition Async.h:489
Definition Async.h:609
Starts a socket receive operation, receiving bytes from a remote endpoint.
Definition Async.h:599
Starts a socket send operation, sending bytes to a remote endpoint.
Definition Async.h:523
Wraps function pointers, member functions and lambdas without ever allocating.
Definition Function.h:19
Http async client.
Definition HttpClient.h:23
Delegate< HttpClient & > callback
The callback that is called after GET operation succeeded.
Definition HttpClient.h:30
Result get(AsyncEventLoop &loop, StringSpan url)
Setups this client to execute a GET request on the given url.
StringSpan getResponse() const
Get the response StringSpan 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:153
An read-only view over a string (to avoid including Strings library when parsing is not needed).
Definition StringSpan.h:37
A non-modifiable owning string with associated encoding.
Definition String.h:29
bool assign(StringSpan sv)
Assigns a StringSpan to this String, replacing existing contents.