6#include "../Async/Async.h"
7#include "../AsyncStreams/AsyncRequestStreams.h"
8#include "../Foundation/Function.h"
9#include "../Foundation/StringSpan.h"
42 struct SC_COMPILER_EXPORT HttpHeaderOffset
52 bool headersEndReceived =
false;
53 bool parsedSuccessfully =
true;
58 static constexpr size_t MaxNumHeaders = 64;
60 HttpHeaderOffset headerOffsets[MaxNumHeaders];
61 size_t numHeaders = 0;
93 size_t responseHeadersCapacity = 0;
95 bool headersSent =
false;
105 struct SC_COMPILER_EXPORT
ID
107 size_t getIndex()
const {
return index; }
129 friend struct HttpConnectionsPool;
130 friend struct HttpAsyncServer;
132 State state = State::Inactive;
135 ReadableSocketStream readableSocketStream;
136 WritableSocketStream writableSocketStream;
138 SocketDescriptor socket;
159 return connections[connectionID.index];
175 size_t numConnections = 0;
unsigned int uint32_t
Platform independent (4) bytes unsigned int.
Definition PrimitiveTypes.h:38
Async destination abstraction where bytes can be written to.
Definition AsyncStreams.h:268
Async Http Server.
Definition HttpAsyncServer.h:20
Definition HttpConnection.h:106
Http connection abstraction holding both the incoming and outgoing messages in an HTTP transaction.
Definition HttpConnection.h:102
void reset()
Prepare this client for re-use, marking it as Inactive.
ID getConnectionID() const
The ID used to find this client in HttpConnectionsPool.
Definition HttpConnection.h:118
A pool of HttpConnection that can be active or inactive.
Definition HttpConnection.h:143
size_t getNumActiveConnections() const
Returns only the number of active connections.
Definition HttpConnection.h:151
HttpConnection & getConnectionAt(size_t idx)
Returns a connection in the [0, getNumTotalConnections] range.
Definition HttpConnection.h:163
Result init(Span< HttpConnection > connectionsStorage, Span< char > headersMemoryStorage)
Initializes the server with memory buffers for connections and headers.
bool activateNew(HttpConnection::ID &connectionID)
Finds an available connection (if any), activates it and returns its ID to use with getConnection(id)
HttpConnection & getConnection(HttpConnection::ID connectionID)
Returns a connection by ID.
Definition HttpConnection.h:157
size_t getNumTotalConnections() const
Returns the total number of connections (active + inactive)
Definition HttpConnection.h:154
Result close()
Closes the server, removing references to the memory buffers passed during init.
bool deactivate(HttpConnection::ID connectionID)
De-activates a connection previously returned by activateNew.
Incremental HTTP request or response parser.
Definition HttpParser.h:14
Token
One possible Token reported by the parser.
Definition HttpParser.h:39
Incoming message from the perspective of the participants of an HTTP transaction.
Definition HttpConnection.h:18
const HttpParser & getParser() const
Gets the associated HttpParser.
Definition HttpConnection.h:20
StringSpan getURL() const
Gets the request URL.
Definition HttpConnection.h:23
void reset()
Resets this object for it to be re-usable.
Outgoing message from the perspective of the participants of an HTTP transaction.
Definition HttpConnection.h:66
Result startResponse(int httpCode)
Starts the response with a http standard code (200 OK, 404 NOT FOUND etc.)
Result sendHeaders()
Start sending response headers, before sending any data.
Result addHeader(StringSpan headerName, StringSpan headerValue)
Writes an http header to this response.
Result end()
Finalizes the writable stream after sending all in progress writes.
void reset()
Resets this object for it to be re-usable.
AsyncWritableStream & getWritableStream()
Obtain writable stream for sending content back to connected client.
Definition HttpConnection.h:83
An ascii string used as boolean result. SC_TRY macro forwards errors to caller.
Definition Result.h:13
View over a contiguous sequence of items (pointer + size in elements).
Definition Span.h:29
An read-only view over a string (to avoid including Strings library when parsing is not needed).
Definition StringSpan.h:37