Provides http base used for client and server connections. More...

#include <HttpConnection.h>

Inheritance diagram for HttpConnection:
Collaboration diagram for HttpConnection:

Public Member Functions

 HttpConnection (http_parser_type type, bool autoDestruct=false)
 
 HttpConnection (tcp_pcb *connection, http_parser_type type)
 
virtual void reset ()
 
virtual void cleanup ()
 
virtual void setDefaultParser ()
 
virtual bool send (HttpRequest *request)
 
bool isActive ()
 
virtual HttpRequestgetRequest ()=0
 Returns pointer to the current request. More...
 
HttpResponsegetResponse ()
 Returns pointer to the current response. More...
 
IpAddress getRemoteIp () const
 
uint16_t getRemotePort () const
 
bool send (const char *data, uint16_t len, bool forceCloseAfterSent=false)
 
bool send (IDataSourceStream *source, bool forceCloseAfterSent=false)
 Sends data stream. More...
 
- Public Member Functions inherited from TcpClient
 TcpClient (bool autoDestruct)
 
 TcpClient (tcp_pcb *clientTcp, TcpClientDataDelegate clientReceive, TcpClientCompleteDelegate onCompleted)
 
 TcpClient (TcpClientCompleteDelegate onCompleted, TcpClientEventDelegate onReadyToSend, TcpClientDataDelegate onReceive=nullptr)
 
 TcpClient (TcpClientCompleteDelegate onCompleted, TcpClientDataDelegate onReceive=nullptr)
 
 TcpClient (TcpClientDataDelegate onReceive)
 
 ~TcpClient ()
 
bool connect (const String &server, int port, bool useSsl=false) override
 
bool connect (IpAddress addr, uint16_t port, bool useSsl=false) override
 
void close () override
 
void setReceiveDelegate (TcpClientDataDelegate receiveCb=nullptr)
 Set or clear the callback for received data. More...
 
void setCompleteDelegate (TcpClientCompleteDelegate completeCb=nullptr)
 Set or clear the callback for connection close. More...
 
bool send (const char *data, uint16_t len, bool forceCloseAfterSent=false)
 
bool sendString (const String &data, bool forceCloseAfterSent=false)
 
bool send (IDataSourceStream *source, bool forceCloseAfterSent=false)
 Sends data stream. More...
 
bool isProcessing ()
 
TcpClientState getConnectionState ()
 
void setCloseAfterSent (bool ignoreIncomingData=false)
 
void commit ()
 Tries to send the pending data immediately. More...
 
- Public Member Functions inherited from TcpConnection
 TcpConnection (bool autoDestruct)
 
 TcpConnection (tcp_pcb *connection, bool autoDestruct)
 
virtual ~TcpConnection ()
 
void setAutoSelfDestruct (bool state)
 
int writeString (const char *data, uint8_t apiflags=TCP_WRITE_FLAG_COPY)
 Writes string data directly to the TCP buffer. More...
 
int writeString (const String &data, uint8_t apiflags=TCP_WRITE_FLAG_COPY)
 Writes string data directly to the TCP buffer. More...
 
virtual int write (const char *data, int len, uint8_t apiflags=TCP_WRITE_FLAG_COPY)
 Base write operation. More...
 
int write (IDataSourceStream *stream)
 Writes stream data directly to the TCP buffer. More...
 
uint16_t getAvailableWriteSize ()
 
void flush ()
 
void setTimeOut (uint16_t waitTimeOut)
 
IpAddress getRemoteIp () const
 
uint16_t getRemotePort () const
 
void setDestroyedDelegate (TcpConnectionDestroyedDelegate destroyedDelegate)
 Sets a callback to be called when the object instance is destroyed. More...
 
void setSslInitHandler (Ssl::Session::InitDelegate handler)
 Set the SSL session initialisation callback. More...
 
bool setSslConnection (Ssl::Connection *connection)
 
Ssl::SessiongetSsl ()
 Get a pointer to the current SSL session object. More...
 
- Public Member Functions inherited from IpConnection
bool joinMulticastGroup (IpAddress localIp, IpAddress multicastIp)
 Uses IGMP to add a local network interface to multicast group. More...
 
bool joinMulticastGroup (IpAddress multicastIp)
 Uses IGMP to add all local network interfaces to multicast group. More...
 
bool leaveMulticastGroup (IpAddress localIp, IpAddress multicastIp)
 Uses IGMP to remove a local network interface from multicast group. More...
 
bool leaveMulticastGroup (IpAddress multicastIp)
 Uses IGMP to remove all local network interfaces from multicast group. More...
 

Protected Member Functions

void resetHeaders ()
 Called after all headers have been received and processed. More...
 
virtual void init (http_parser_type type)
 Initializes the http parser for a specific type of HTTP message. More...
 
virtual int onMessageBegin (http_parser *parser)=0
 Called when a new incoming data is beginning to come. More...
 
virtual int onPath (const Url &uri)
 Called when the URL path is known. More...
 
virtual int onHeadersComplete (const HttpHeaders &headers)=0
 Called when all headers are received. More...
 
virtual int onStatus (http_parser *parser)
 
virtual int onChunkHeader (http_parser *parser)
 
virtual int onChunkComplete (http_parser *parser)
 
virtual int onBody (const char *at, size_t length)=0
 Called when a piece of body data is received. More...
 
virtual int onMessageComplete (http_parser *parser)=0
 Called when the incoming data is complete. More...
 
virtual bool onProtocolUpgrade (http_parser *parser)
 Called when the HTTP protocol should be upgraded. More...
 
virtual bool onHttpError (HttpError error)
 Called when there was an error. More...
 
virtual bool onTcpReceive (TcpClient &client, char *data, int size)
 
void onError (err_t err) override
 
- Protected Member Functions inherited from TcpClient
err_t onConnected (err_t err) override
 
err_t onReceive (pbuf *buf) override
 
err_t onSent (uint16_t len) override
 
void onError (err_t err) override
 
void onClosed () override
 Gets called when there is/was a tcp connection, the latter does not have to be established, that is closed due to error or normal disconnect. More...
 
void onReadyToSendData (TcpConnectionEvent sourceEvent) override
 
virtual void onFinished (TcpClientState finishState)
 
void pushAsyncPart ()
 
void freeStreams ()
 
- Protected Member Functions inherited from TcpConnection
void initialize (tcp_pcb *pcb)
 
bool internalConnect (IpAddress addr, uint16_t port)
 
bool sslCreateSession ()
 
virtual void sslInitSession (Ssl::Session &session)
 Override in inherited classes to perform custom session initialisation. More...
 
virtual err_t onPoll ()
 
void trySend (TcpConnectionEvent event)
 
err_t internalOnConnected (err_t err)
 
err_t internalOnReceive (pbuf *p, err_t err)
 
err_t internalOnSent (uint16_t len)
 
err_t internalOnPoll ()
 
void internalOnError (err_t err)
 
void internalOnDnsResponse (const char *name, LWIP_IP_ADDR_T *ipaddr, int port)
 

Protected Attributes

http_parser parser
 
HttpHeaderBuilder header
 Header construction. More...
 
HttpHeaders incomingHeaders
 Full set of incoming headers. More...
 
HttpConnectionState state = eHCS_Ready
 
HttpResponse response
 
- Protected Attributes inherited from TcpClient
IDataSourceStreamstream = nullptr
 The currently active stream being sent. More...
 
- Protected Attributes inherited from TcpConnection
tcp_pcb * tcp = nullptr
 
uint16_t sleep = 0
 
uint16_t timeOut = USHRT_MAX
 By default a TCP connection does not have a time out. More...
 
bool canSend = true
 
bool autoSelfDestruct = true
 
Ssl::Sessionssl = nullptr
 
Ssl::Session::InitDelegate sslInit
 
bool useSsl = false
 

Static Protected Attributes

static const http_parser_settings parserSettings
 Callback table for parser. More...
 

Detailed Description

Provides http base used for client and server connections.

Constructor & Destructor Documentation

◆ HttpConnection() [1/2]

HttpConnection::HttpConnection ( http_parser_type  type,
bool  autoDestruct = false 
)
inline

◆ HttpConnection() [2/2]

HttpConnection::HttpConnection ( tcp_pcb *  connection,
http_parser_type  type 
)
inline

Member Function Documentation

◆ cleanup()

virtual void HttpConnection::cleanup ( )
inlinevirtual

Reimplemented in HttpClientConnection.

◆ getRemoteIp()

IpAddress TcpConnection::getRemoteIp
inline

◆ getRemotePort()

uint16_t TcpConnection::getRemotePort
inline

◆ getRequest()

virtual HttpRequest* HttpConnection::getRequest ( )
pure virtual

Returns pointer to the current request.

Return values
HttpRequest*

Implemented in HttpServerConnection, and HttpClientConnection.

◆ getResponse()

HttpResponse* HttpConnection::getResponse ( )
inline

Returns pointer to the current response.

Return values
HttpResponse*

◆ init()

virtual void HttpConnection::init ( http_parser_type  type)
protectedvirtual

Initializes the http parser for a specific type of HTTP message.

Parameters
type

◆ isActive()

bool HttpConnection::isActive ( )

◆ onBody()

virtual int HttpConnection::onBody ( const char *  at,
size_t  length 
)
protectedpure virtual

Called when a piece of body data is received.

Parameters
atthe data
length
Return values
int0 on success, non-0 on error

Implemented in HttpServerConnection, and HttpClientConnection.

◆ onChunkComplete()

virtual int HttpConnection::onChunkComplete ( http_parser *  parser)
inlineprotectedvirtual

◆ onChunkHeader()

virtual int HttpConnection::onChunkHeader ( http_parser *  parser)
inlineprotectedvirtual

◆ onError()

void HttpConnection::onError ( err_t  err)
overrideprotectedvirtual

Reimplemented from TcpConnection.

◆ onHeadersComplete()

virtual int HttpConnection::onHeadersComplete ( const HttpHeaders headers)
protectedpure virtual

Called when all headers are received.

Parameters
headersThe processed headers
Return values
int0 on success, non-0 on error

Implemented in HttpServerConnection, and HttpClientConnection.

◆ onHttpError()

virtual bool HttpConnection::onHttpError ( HttpError  error)
protectedvirtual

Called when there was an error.

Parameters
error- the error code
Return values
bool- false if the problem is not recoverable, true otherwise

Reimplemented in HttpServerConnection.

◆ onMessageBegin()

virtual int HttpConnection::onMessageBegin ( http_parser *  parser)
protectedpure virtual

Called when a new incoming data is beginning to come.

Parameters
parser
Return values
int0 on success, non-0 on error

Implemented in HttpServerConnection, and HttpClientConnection.

◆ onMessageComplete()

virtual int HttpConnection::onMessageComplete ( http_parser *  parser)
protectedpure virtual

Called when the incoming data is complete.

Parameters
parser
Return values
int0 on success, non-0 on error

Implemented in HttpServerConnection, and HttpClientConnection.

◆ onPath()

virtual int HttpConnection::onPath ( const Url uri)
inlineprotectedvirtual

Called when the URL path is known.

Parameters
uri
Return values
int0 on success, non-0 on error

Reimplemented in HttpServerConnection.

◆ onProtocolUpgrade()

virtual bool HttpConnection::onProtocolUpgrade ( http_parser *  parser)
inlineprotectedvirtual

Called when the HTTP protocol should be upgraded.

Parameters
parser
Return values
booltrue on success

Reimplemented in HttpServerConnection.

◆ onStatus()

virtual int HttpConnection::onStatus ( http_parser *  parser)
inlineprotectedvirtual

◆ onTcpReceive()

virtual bool HttpConnection::onTcpReceive ( TcpClient client,
char *  data,
int  size 
)
protectedvirtual

◆ reset()

virtual void HttpConnection::reset ( )
inlinevirtual

Reimplemented in HttpClientConnection.

◆ resetHeaders()

void HttpConnection::resetHeaders ( )
protected

Called after all headers have been received and processed.

◆ send() [1/3]

bool TcpClient::send

◆ send() [2/3]

virtual bool HttpConnection::send ( HttpRequest request)
inlinevirtual

◆ send() [3/3]

bool TcpClient::send

Sends data stream.

Note
This function takes ownership of the stream pointer!
Parameters
sourcestream pointer
forceCloseAfterSent
Return values
booltrue when the stream can be used. When false the stream will be deleted.

◆ setDefaultParser()

virtual void HttpConnection::setDefaultParser ( )
virtual

Member Data Documentation

◆ header

HttpHeaderBuilder HttpConnection::header
protected

Header construction.

◆ incomingHeaders

HttpHeaders HttpConnection::incomingHeaders
protected

Full set of incoming headers.

◆ parser

http_parser HttpConnection::parser
protected

◆ parserSettings

const http_parser_settings HttpConnection::parserSettings
staticprotected

Callback table for parser.

◆ response

HttpResponse HttpConnection::response
protected

◆ state

HttpConnectionState HttpConnection::state = eHCS_Ready
protected

The documentation for this class was generated from the following file: