4#include "HttpConnection.h"
12template <
typename Base,
typename Derived>
15 static constexpr bool value = __is_base_of(Base, Derived);
21template <
int ReadQueue,
int WriteQueue,
int HeaderBytes,
int StreamBytes>
23 :
public HttpStaticConnection<ReadQueue, WriteQueue, HeaderBytes, StreamBytes, 8, HttpConnection>
34 Span<const char> pemCertificateChain;
35 Span<const char> pemPrivateKey;
36 Span<StringSpan> alpnProtocols;
55 typename =
typename TypeTraits::EnableIf<TypeTraits::IsBaseOf<HttpConnection, T>::value>::type>
56 Result
init(Span<T> clients)
58 return initInternal({clients.data(), clients.sizeInElements(),
sizeof(T)});
62 typename =
typename TypeTraits::EnableIf<TypeTraits::IsBaseOf<HttpConnection, T>::value>::type>
63 Result resize(Span<T> clients)
65 return resizeInternal({clients.data(), clients.sizeInElements(),
sizeof(T)});
99 [[nodiscard]]
bool isStarted()
const {
return state == State::Started; }
127 uint32_t maxHeaderSize = 8 * 1024;
138 State state = State::Stopped;
140 bool defaultKeepAlive =
true;
141 uint32_t maxRequestsPerConnection = 0;
143 void onNewClient(AsyncSocketAccept::Result& result);
144 void closeAsync(HttpConnection& requestClient);
145 void deactivateConnection(HttpConnection& requestClient);
146 void onStreamReceive(HttpConnection& client, AsyncBufferView::ID bufferID);
147 void onRequestBodyData(HttpConnection& client, AsyncBufferView::ID bufferID);
149 Result waitForStopToFinish();
150 Result initInternal(SpanWithStride<HttpConnection> connections);
151 Result resizeInternal(SpanWithStride<HttpConnection> connections);
153 AsyncEventLoop* eventLoop =
nullptr;
154 SocketDescriptor serverSocket;
155 AsyncSocketAccept asyncServerAccept;
157 struct EventDataListener;
158 struct EventBodyDataListener;
159 struct EventEndListener;
160 struct EventCloseListener;
Asynchronous I/O (files, sockets, timers, processes, fs events, threads wake-up) (see Async) AsyncEve...
Definition Async.h:1447
Adds compile-time configurable read and write queues to HttpConnection.
Definition HttpAsyncServer.h:24
TLS policy for future HttpAsyncServer HTTPS listeners.
Definition HttpAsyncServer.h:31
Async Http Server.
Definition HttpAsyncServer.h:52
Result start(AsyncEventLoop &loop, StringSpan address, uint16_t port)
Starts the http server on the given AsyncEventLoop, address and port.
void setTlsOptions(const HttpAsyncServerTlsOptions &options)
Sets TLS options used by future HTTPS listener integration.
Definition HttpAsyncServer.h:91
uint32_t getMaxRequestsPerConnection() const
Get the maximum requests per connection.
Definition HttpAsyncServer.h:122
Result stop()
Stops http server asynchronously pushing cancel and close requests to the event loop.
Result init(Span< T > clients)
Initializes the async server with all needed memory buffers.
Definition HttpAsyncServer.h:56
void clearTlsOptions()
Restores default plain HTTP listener options.
Definition HttpAsyncServer.h:94
bool getDefaultKeepAlive() const
Get the default keep-alive setting.
Definition HttpAsyncServer.h:115
void setDefaultKeepAlive(bool enabled)
Set default keep-alive behavior for all connections.
Definition HttpAsyncServer.h:112
Function< void(HttpConnection &)> onRequest
Called after enough data from a newly connected client has arrived, causing all headers to be parsed.
Definition HttpAsyncServer.h:104
Function< void(Result)> onError
Called on accept, parse, protocol, or streaming errors before the affected connection is closed.
Definition HttpAsyncServer.h:107
void setMaxRequestsPerConnection(uint32_t maxRequests)
Set maximum requests per keep-alive connection.
Definition HttpAsyncServer.h:119
bool isStarted() const
Returns true if the server has been started.
Definition HttpAsyncServer.h:99
void setMaxHeaderSize(uint32_t bytes)
Sets the maximum accepted request-header size in bytes.
Definition HttpAsyncServer.h:85
uint32_t getMaxHeaderSize() const
Gets the maximum accepted request-header size in bytes.
Definition HttpAsyncServer.h:88
Result close()
Closes the server, removing references to the memory buffers passed during init.
Http connection abstraction holding both the incoming and outgoing messages in an HTTP transaction.
Definition HttpConnection.h:490
A pool of HttpConnection that can be active or inactive.
Definition HttpConnection.h:589
Adds compile-time configurable read and write queues to any class subclassing HttpConnectionBase.
Definition HttpConnection.h:654
IsBaseOf evaluates to true if the type Base is a base class of Derived, false otherwise.
Definition HttpAsyncServer.h:14