47 #ifndef _HTTP_SERVER_H_
48 #define _HTTP_SERVER_H_
54 #include <FlowScanner.h>
61 static const uint8_t HTTP_SERVER_STAGE_INIT = 0;
62 static const uint8_t HTTP_SERVER_STAGE_METHOD = 1;
63 static const uint8_t HTTP_SERVER_STAGE_QUERY_STRING = 2;
64 static const uint8_t HTTP_SERVER_STAGE_HEADERS = 3;
65 static const uint8_t HTTP_SERVER_STAGE_BODY = 4;
66 static const uint8_t HTTP_SERVER_STAGE_RESPONSE = 5;
67 static const uint8_t HTTP_SERVER_STAGE_RESPONSE_BODY = 6;
68 static const uint8_t HTTP_SERVER_STAGE_RESPONSE_END = 7;
88 FlowPattern requestPattern;
89 FlowPattern headerPattern;
92 void onReceive(uint16_t len,
const byte* data);
94 void onConnectRequest();
112 void listen(uint16_t port = 80);
113 void beginResponse(uint16_t statusCode,
const String& message =
"");
115 void writeHeader(
const String& headerName,
const String& headerValue);
116 void writeHeader_P(PGM_P headerName,
const String& headerValue);
123 virtual void onHeaderReceived(
const char* headerName,
const char* headerValue);
125 virtual void onRequest(
char* queryString);
#define HTTP_SERVER_HEADER_NAME_MAX_LENGTH
max buffer to hold a header name, e.g.
void writeHeader(const String &headerName, const String &headerValue)
Writes an HTTP header to the ongoing response stream.
void beginResponse(uint16_t statusCode, const String &message="")
Sends out the response line, e.g.
uint8_t httpMethod
Indicates what HTTP method was used in this request.
uint16_t contentLength
captured length of the incoming request, in bytes.
virtual void onBodyBegin()
Called when all HTTP headers have been received and the body of the request is about to arrive...
void listen()
Starts listening on the local port indicated by the localPort property.
void beginResponse_P(uint16_t statusCode, PGM_P message)
Sends out the response line, e.g.
virtual void onHeaderReceived(const char *headerName, const char *headerValue)
Called once for each header in the request, as they arrive.
void beginResponseBody()
Indicates to the client that all headers have been written and that the response body follows...
void writeContentTypeHeader(const String &contentType)
Convenient function to write the Content-Type header.
Implements the TCP protocol.
void writeContentTypeHeader_P(PGM_P contentType)
Convenient function to write the Content-Type header.
Provides an easy way to build a web server.
virtual void onRequestEnd()
Called after all the body has been received
virtual void onBodyReceived(uint16_t len, const byte *data)
Called once for each fragment of the body that is received.
void endResponse()
Ends the connection and finalizes the response.
virtual void onRequest(char *queryString)
Called immediately after the first line that contains the HTTP method and query string is received ...
#define HTTP_SERVER_HEADER_VALUE_MAX_LENGTH
max buffer to hold a header value, e.g.
void writeHeader_P(PGM_P headerName, const String &headerValue)
Writes an HTTP header to the ongoing response stream.
#define HTTP_SERVER_QUERY_STRING_MAX_LENGTH
max buffer to hold the entire query string, e.g.