#include <HttpClientConnection.h>

Inheritance diagram for HttpClientConnection:
[legend]
Collaboration diagram for HttpClientConnection:
[legend]

Public Member Functions

 HttpClientConnection ()
 
 ~HttpClientConnection ()
 
bool connect (const String &host, int port, bool useSsl=false) override
 
bool send (HttpRequest *request) override
 
HttpRequestgetRequest () override
 Returns pointer to the current request. More...
 
void reset () override
 
virtual void setDefaultParser ()
 
bool send (const char *data, uint16_t len, bool forceCloseAfterSent=false)
 
bool isActive ()
 
HttpResponsegetResponse ()
 Returns pointer to the current response. More...
 
int getResponseCode () const
 
String getResponseHeader (const String &headerName, const String &defaultValue=nullptr) const
 
HttpHeadersgetResponseHeaders ()
 
DateTime getLastModifiedDate () const
 
DateTime getServerDate () const
 
String getResponseString ()
 
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 sendString (const String &data, bool forceCloseAfterSent=false)
 
bool isProcessing ()
 
TcpClientState getConnectionState ()
 
void setCloseAfterSent (bool ignoreIncomingData=false)
 
int writeString (const char *data, uint8_t apiflags=TCP_WRITE_FLAG_COPY)
 
int writeString (const String &data, uint8_t apiflags=TCP_WRITE_FLAG_COPY)
 
virtual int write (const char *data, int len, uint8_t apiflags=TCP_WRITE_FLAG_COPY)
 Base write operation. More...
 
int write (IDataSourceStream *stream)
 
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...
 

Protected Member Functions

int onMessageBegin (http_parser *parser) override
 Called when a new incoming data is beginning to come. More...
 
int onHeadersComplete (const HttpHeaders &headers) override
 Called when all headers are received. More...
 
int onBody (const char *at, size_t length) override
 Called when a piece of body data is received. More...
 
int onMessageComplete (http_parser *parser) override
 Called when the incoming data is complete. More...
 
void onReadyToSendData (TcpConnectionEvent sourceEvent) override
 
void cleanup () override
 
void sslInitSession (Ssl::Session &session) override
 Override in inherited classes to perform custom session initialisation. More...
 
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 onPath (const Url &uri)
 Called when the URL path is known. More...
 
virtual int onStatus (http_parser *parser)
 
virtual int onChunkHeader (http_parser *parser)
 
virtual int onChunkComplete (http_parser *parser)
 
virtual bool onProtocolUpgrade (http_parser *parser)
 Called when the HTTP protocol should be upgraded. More...
 
virtual bool onHttpError (http_errno error)
 Called when there was an error. More...
 
virtual bool onTcpReceive (TcpClient &client, char *data, int size)
 
void onError (err_t err) override
 
err_t onConnected (err_t err) override
 
err_t onReceive (pbuf *buf) override
 
err_t onSent (uint16_t len) override
 
virtual void onFinished (TcpClientState finishState)
 
void pushAsyncPart ()
 
void freeStreams ()
 
void setBuffer (ReadWriteStream *stream)
 
void initialize (tcp_pcb *pcb)
 
bool internalConnect (IpAddress addr, uint16_t port)
 
bool sslCreateSession ()
 
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
 
ReadWriteStreambuffer = nullptr
 Used internally to buffer arbitrary data via send() methods. More...
 
IDataSourceStreamstream = nullptr
 The currently active stream being sent. More...
 
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...
 

Constructor & Destructor Documentation

◆ HttpClientConnection()

HttpClientConnection::HttpClientConnection ( )
inline

◆ ~HttpClientConnection()

HttpClientConnection::~HttpClientConnection ( )
inline

Member Function Documentation

◆ cleanup()

void HttpClientConnection::cleanup ( )
overrideprotectedvirtual

Reimplemented from HttpConnection.

◆ close()

void TcpClient::close ( )
overridevirtualinherited

Reimplemented from TcpConnection.

◆ connect() [1/2]

bool HttpClientConnection::connect ( const String host,
int  port,
bool  useSsl = false 
)
overridevirtual

Reimplemented from TcpConnection.

◆ connect() [2/2]

bool TcpClient::connect ( IpAddress  addr,
uint16_t  port,
bool  useSsl = false 
)
overridevirtualinherited

Reimplemented from TcpConnection.

◆ flush()

void TcpConnection::flush ( )
inherited

◆ freeStreams()

void TcpClient::freeStreams ( )
protectedinherited

◆ getAvailableWriteSize()

uint16_t TcpConnection::getAvailableWriteSize ( )
inlineinherited

◆ getConnectionState()

TcpClientState TcpClient::getConnectionState ( )
inlineinherited

◆ getLastModifiedDate()

DateTime HttpConnection::getLastModifiedDate ( ) const
inlineinherited
Deprecated:
Use getResponse()->headers.getLastModifiedDate() instead

◆ getRemoteIp()

IpAddress TcpConnection::getRemoteIp ( ) const
inlineinherited

◆ getRemotePort()

uint16_t TcpConnection::getRemotePort ( ) const
inlineinherited

◆ getRequest()

HttpRequest* HttpClientConnection::getRequest ( )
inlineoverridevirtual

Returns pointer to the current request.

Return values
HttpRequest*

Implements HttpConnection.

◆ getResponse()

HttpResponse* HttpConnection::getResponse ( )
inlineinherited

Returns pointer to the current response.

Return values
HttpResponse*

◆ getResponseCode()

int HttpConnection::getResponseCode ( ) const
inlineinherited
Deprecated:
Use getResponse()->code instead

◆ getResponseHeader()

String HttpConnection::getResponseHeader ( const String headerName,
const String defaultValue = nullptr 
) const
inlineinherited
Deprecated:
Use getResponse()->headers[] instead

◆ getResponseHeaders()

HttpHeaders& HttpConnection::getResponseHeaders ( )
inlineinherited
Deprecated:
Use getResponse()->headers instead

◆ getResponseString()

String HttpConnection::getResponseString ( )
inlineinherited
Deprecated:
Use getResponse()->getBody() instead

◆ getServerDate()

DateTime HttpConnection::getServerDate ( ) const
inlineinherited
Deprecated:
Use getResponse()->headers.getServerDate() instead

◆ getSsl()

Ssl::Session* TcpConnection::getSsl ( )
inlineinherited

Get a pointer to the current SSL session object.

Note that this is typically used so we can query properties of an established session. If you need to change session parameters this must be done via setSslInitHandler.

◆ init()

virtual void HttpConnection::init ( http_parser_type  type)
protectedvirtualinherited

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

Parameters
type

◆ initialize()

void TcpConnection::initialize ( tcp_pcb *  pcb)
protectedinherited

◆ internalConnect()

bool TcpConnection::internalConnect ( IpAddress  addr,
uint16_t  port 
)
protectedinherited

◆ internalOnConnected()

err_t TcpConnection::internalOnConnected ( err_t  err)
protectedinherited

◆ internalOnDnsResponse()

void TcpConnection::internalOnDnsResponse ( const char *  name,
LWIP_IP_ADDR_T ipaddr,
int  port 
)
protectedinherited

◆ internalOnError()

void TcpConnection::internalOnError ( err_t  err)
protectedinherited

◆ internalOnPoll()

err_t TcpConnection::internalOnPoll ( )
protectedinherited

◆ internalOnReceive()

err_t TcpConnection::internalOnReceive ( pbuf *  p,
err_t  err 
)
protectedinherited

◆ internalOnSent()

err_t TcpConnection::internalOnSent ( uint16_t  len)
protectedinherited

◆ isActive()

bool HttpConnection::isActive ( )
inherited

◆ isProcessing()

bool TcpClient::isProcessing ( )
inlineinherited

◆ onBody()

int HttpClientConnection::onBody ( const char *  at,
size_t  length 
)
overrideprotectedvirtual

Called when a piece of body data is received.

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

Implements HttpConnection.

◆ onChunkComplete()

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

◆ onChunkHeader()

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

◆ onConnected()

err_t TcpClient::onConnected ( err_t  err)
overrideprotectedvirtualinherited

Reimplemented from TcpConnection.

◆ onError()

void HttpConnection::onError ( err_t  err)
overrideprotectedvirtualinherited

Reimplemented from TcpConnection.

◆ onFinished()

virtual void TcpClient::onFinished ( TcpClientState  finishState)
protectedvirtualinherited

Reimplemented in MqttClient.

◆ onHeadersComplete()

int HttpClientConnection::onHeadersComplete ( const HttpHeaders headers)
overrideprotectedvirtual

Called when all headers are received.

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

Implements HttpConnection.

◆ onHttpError()

virtual bool HttpConnection::onHttpError ( http_errno  error)
protectedvirtualinherited

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()

int HttpClientConnection::onMessageBegin ( http_parser *  parser)
overrideprotectedvirtual

Called when a new incoming data is beginning to come.

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

Implements HttpConnection.

◆ onMessageComplete()

int HttpClientConnection::onMessageComplete ( http_parser *  parser)
overrideprotectedvirtual

Called when the incoming data is complete.

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

Implements HttpConnection.

◆ onPath()

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

Called when the URL path is known.

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

Reimplemented in HttpServerConnection.

◆ onPoll()

virtual err_t TcpConnection::onPoll ( )
protectedvirtualinherited

◆ onProtocolUpgrade()

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

Called when the HTTP protocol should be upgraded.

Parameters
parser
Return values
booltrue on success

Reimplemented in HttpServerConnection.

◆ onReadyToSendData()

void HttpClientConnection::onReadyToSendData ( TcpConnectionEvent  sourceEvent)
overrideprotectedvirtual

Reimplemented from TcpConnection.

◆ onReceive()

err_t TcpClient::onReceive ( pbuf *  buf)
overrideprotectedvirtualinherited

Reimplemented from TcpConnection.

◆ onSent()

err_t TcpClient::onSent ( uint16_t  len)
overrideprotectedvirtualinherited

Reimplemented from TcpConnection.

◆ onStatus()

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

◆ onTcpReceive()

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

◆ pushAsyncPart()

void TcpClient::pushAsyncPart ( )
protectedinherited

◆ reset()

void HttpClientConnection::reset ( )
overridevirtual

Reimplemented from HttpConnection.

◆ resetHeaders()

void HttpConnection::resetHeaders ( )
protectedinherited

Called after all headers have been received and processed.

◆ send() [1/2]

bool HttpClientConnection::send ( HttpRequest request)
overridevirtual

Reimplemented from HttpConnection.

◆ send() [2/2]

bool TcpClient::send ( const char *  data,
uint16_t  len,
bool  forceCloseAfterSent = false 
)
inherited

◆ sendString()

bool TcpClient::sendString ( const String data,
bool  forceCloseAfterSent = false 
)
inlineinherited

◆ setBuffer()

void TcpClient::setBuffer ( ReadWriteStream stream)
protectedinherited

◆ setCloseAfterSent()

void TcpClient::setCloseAfterSent ( bool  ignoreIncomingData = false)
inlineinherited

Schedules the connection to get closed after the data is sent

Parameters
ignoreIncomingDatawhen that flag is set the connection will start ignoring incoming data.

◆ setCompleteDelegate()

void TcpClient::setCompleteDelegate ( TcpClientCompleteDelegate  completeCb = nullptr)
inlineinherited

Set or clear the callback for connection close.

Parameters
completeCbcallback delegate or nullptr

◆ setDefaultParser()

virtual void HttpConnection::setDefaultParser ( )
virtualinherited

◆ setDestroyedDelegate()

void TcpConnection::setDestroyedDelegate ( TcpConnectionDestroyedDelegate  destroyedDelegate)
inlineinherited

Sets a callback to be called when the object instance is destroyed.

Parameters
destroyedDelegate

◆ setReceiveDelegate()

void TcpClient::setReceiveDelegate ( TcpClientDataDelegate  receiveCb = nullptr)
inlineinherited

Set or clear the callback for received data.

Parameters
receiveCbcallback delegate or nullptr

◆ setSslConnection()

bool TcpConnection::setSslConnection ( Ssl::Connection connection)
inlineinherited

◆ setSslInitHandler()

void TcpConnection::setSslInitHandler ( Ssl::Session::InitDelegate  handler)
inlineinherited

Set the SSL session initialisation callback.

Parameters
handler

◆ setTimeOut()

void TcpConnection::setTimeOut ( uint16_t  waitTimeOut)
inherited

◆ sslCreateSession()

bool TcpConnection::sslCreateSession ( )
protectedinherited

◆ sslInitSession()

void HttpClientConnection::sslInitSession ( Ssl::Session session)
inlineoverrideprotectedvirtual

Override in inherited classes to perform custom session initialisation.

Called when TCP connection is established before initiating handshake.

Reimplemented from TcpConnection.

◆ trySend()

void TcpConnection::trySend ( TcpConnectionEvent  event)
inlineprotectedinherited

◆ write() [1/2]

virtual int TcpConnection::write ( const char *  data,
int  len,
uint8_t  apiflags = TCP_WRITE_FLAG_COPY 
)
virtualinherited

Base write operation.

Parameters
data
len
apiflagsTCP_WRITE_FLAG_COPY, TCP_WRITE_FLAG_MORE
Return values
int-1 on error

Reimplemented in FtpDataStream.

◆ write() [2/2]

int TcpConnection::write ( IDataSourceStream stream)
inherited

◆ writeString() [1/2]

int TcpConnection::writeString ( const char *  data,
uint8_t  apiflags = TCP_WRITE_FLAG_COPY 
)
inlineinherited

◆ writeString() [2/2]

int TcpConnection::writeString ( const String data,
uint8_t  apiflags = TCP_WRITE_FLAG_COPY 
)
inlineinherited

Member Data Documentation

◆ autoSelfDestruct

bool TcpConnection::autoSelfDestruct = true
protectedinherited

◆ buffer

ReadWriteStream* TcpClient::buffer = nullptr
protectedinherited

Used internally to buffer arbitrary data via send() methods.

◆ canSend

bool TcpConnection::canSend = true
protectedinherited

◆ header

HttpHeaderBuilder HttpConnection::header
protectedinherited

Header construction.

◆ incomingHeaders

HttpHeaders HttpConnection::incomingHeaders
protectedinherited

Full set of incoming headers.

◆ parser

http_parser HttpConnection::parser
protectedinherited

◆ parserSettings

const http_parser_settings HttpConnection::parserSettings
staticprotectedinherited

Callback table for parser.

◆ response

HttpResponse HttpConnection::response
protectedinherited

◆ sleep

uint16_t TcpConnection::sleep = 0
protectedinherited

◆ ssl

Ssl::Session* TcpConnection::ssl = nullptr
protectedinherited

◆ sslInit

Ssl::Session::InitDelegate TcpConnection::sslInit
protectedinherited

◆ state

HttpConnectionState HttpConnection::state = eHCS_Ready
protectedinherited

◆ stream

IDataSourceStream* TcpClient::stream = nullptr
protectedinherited

The currently active stream being sent.

◆ tcp

tcp_pcb* TcpConnection::tcp = nullptr
protectedinherited

◆ timeOut

uint16_t TcpConnection::timeOut = USHRT_MAX
protectedinherited

By default a TCP connection does not have a time out.

◆ useSsl

bool TcpConnection::useSsl = false
protectedinherited

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