31#ifndef ASYNC_HTTP_SERVER_CONNECTION_INCLUDED
32#define ASYNC_HTTP_SERVER_CONNECTION_INCLUDED
132 typedef std::map<std::string, std::string>
Headers;
158 method = std::move(other.method);
159 target = std::move(other.target);
162 headers = std::move(other.headers);
171 Response(
void) : m_code(0), m_send_content(false) {}
173 unsigned code(
void)
const {
return m_code; }
177 template <
typename T>
180 std::ostringstream os;
182 m_headers[key] = os.str();
185 const std::string&
content(
void)
const {
return m_content; }
191 setHeader(
"Content-length", m_content.size());
197 m_send_content = send_content;
210 std::string m_content;
228 uint16_t remote_port,
273 virtual bool write(
const char* buf,
int len);
280 sigc::signal<void, HttpServerConnection *, DisconnectReason>
disconnected;
338 STATE_DISCONNECTED, STATE_EXPECT_START_LINE, STATE_EXPECT_HEADER,
339 STATE_EXPECT_PAYLOAD, STATE_REQ_COMPLETE
350 void handleStartLine(
void);
351 void handleHeader(
void);
353 void disconnectCleanup(
void);
354 const char* codeToString(
unsigned code);
Contains a class for handling exiting TCP connections.
bool sendContent(void) const
void setCode(unsigned code)
void setContent(const std::string &content_type, const std::string &content)
const Headers & headers(void) const
unsigned code(void) const
const std::string & content(void) const
void setSendContent(bool send_content)
void setHeader(const std::string &key, T value)
A class representing a HTTP server side connection.
HttpServerConnection(int sock, const IpAddress &remote_addr, uint16_t remote_port, size_t recv_buf_len=DEFAULT_RECV_BUF_LEN)
Constructor.
virtual TcpConnection & operator=(TcpConnection &&other_base) override
Move assignmnt operator.
virtual bool write(const char *buf, int len)
Write data to the socket.
virtual void closeConnection(void) override
Disconnect from the remote peer.
sigc::signal< void, HttpServerConnection *, Request & > requestReceived
A signal that is emitted when a HTTP request has been received on the connection.
HttpServerConnection(size_t recv_buf_len=DEFAULT_RECV_BUF_LEN)
Constructor.
virtual ~HttpServerConnection(void)
Destructor.
void setChunked(void)
Send data with chunked transfer encoding.
virtual void emitDisconnected(DisconnectReason reason) override
Emit the disconnected signal.
virtual bool write(const Response &res)
Send a HTTP response.
virtual int onDataReceived(void *buf, int count) override
Called when data has been received on the connection.
std::map< std::string, std::string > Headers
virtual void onDisconnected(DisconnectReason reason) override
Called when a connection has been terminated.
sigc::signal< void, bool > sendBufferFull
sigc::signal< void, HttpServerConnection *, DisconnectReason > disconnected
A signal that is emitted when a connection has been terminated.
A class for representing an IP address in an OS independent way.
A class for handling exiting TCP connections.
static const int DEFAULT_RECV_BUF_LEN
The default size of the reception buffer.
DisconnectReason
Reason code for disconnects.
virtual void emitDisconnected(DisconnectReason reason)
Emit the disconnected signal.
virtual int write(const void *buf, int count)
Write data to the TCP connection.
Namespace for the asynchronous programming classes.
Request & operator=(Request &&other)