[ Web Proxy ]
URL:
Viewing: https://raw.githubusercontent.com/byte-imagination/esp32_https_server/master/src/HTTPConnection.hpp [Back]  [Original]

#ifndef SRC_HTTPCONNECTION_HPP_
#define SRC_HTTPCONNECTION_HPP_

#include 

#include 
#include 
#include 
#include 

// Required for sockets
#include "lwip/netdb.h"
#undef read
#include "lwip/sockets.h"

#include "HTTPSServerConstants.hpp"
#include "ConnectionContext.hpp"

#include "HTTPHeaders.hpp"
#include "HTTPHeader.hpp"

#include "ResourceResolver.hpp"
#include "ResolvedResource.hpp"

#include "ResourceNode.hpp"
#include "HTTPRequest.hpp"
#include "HTTPResponse.hpp"

#include "WebsocketHandler.hpp"
#include "WebsocketNode.hpp"

namespace httpsserver {

class HTTPConnection : private ConnectionContext {
public:
	HTTPConnection(ResourceResolver * resResolver);
	virtual ~HTTPConnection();

	virtual int initialize(int serverSocketID, HTTPHeaders *defaultHeaders);
	virtual void closeConnection();
	virtual bool isSecure();

	void loop();
	bool isClosed();
	bool isError();

protected:
	friend class HTTPRequest;
	friend class HTTPResponse;
	friend class WebsocketInputStreambuf;

	virtual size_t writeBuffer(byte* buffer, size_t length);
	virtual size_t readBytesToBuffer(byte* buffer, size_t length);
	virtual bool canReadData();
	virtual size_t pendingByteCount();

	// Timestamp of the last transmission action
	unsigned long _lastTransmissionTS;

	// Timestamp of when the shutdown was started
	unsigned long _shutdownTS;

	// Internal state machine of the connection:
	//
	// O --- > STATE_UNDEFINED -- initialize() --> STATE_INITIAL -- get / http/1.1 --> STATE_REQUEST_FINISHED --.
	//                     |                          |                                       |                 |
	//                     |                          |                                       |                 | Host: ...\r\n
	// STATE_ERROR 

Web Proxy Viewer  |  New URL  |  Original Page