HttpServer.h
Go to the documentation of this file.
1 /****
2  * Sming Framework Project - Open Source framework for high efficiency native ESP8266 development.
3  * Created 2015 by Skurydin Alexey
4  * http://github.com/SmingHub/Sming
5  * All files of the Sming Core are provided under the LGPL v3 license.
6  *
7  * HttpServer.h
8  *
9  * Modified: 2017 - Slavey Karadzhov <slav@attachix.com>
10  *
11  ****/
12 
19 #pragma once
20 
21 #include "TcpServer.h"
22 #include "WString.h"
23 #include "Http/HttpResourceTree.h"
25 #include "Http/HttpBodyParser.h"
26 
30  int minHeapSize = -1;
33  true;
34 };
35 
36 class HttpServer : public TcpServer
37 {
38 public:
40  {
41  settings.keepAliveSeconds = 2;
42  configure(settings);
43  }
44 
45  HttpServer(const HttpServerSettings& settings)
46  {
47  configure(settings);
48  }
49 
53  void configure(const HttpServerSettings& settings);
54 
64  void setBodyParser(const String& contentType, HttpBodyParserDelegate parser)
65  {
66  bodyParsers[contentType] = parser;
67  }
68 
75  {
76  bodyParsers[toString(mimeType)] = parser;
77  }
78 
79 public:
82 
83 protected:
84  TcpConnection* createClient(tcp_pcb* clientTcp) override;
85 
86 private:
87  HttpServerSettings settings;
88  BodyParsers bodyParsers;
89 };
90 
void setBodyParser(MimeType mimeType, HttpBodyParserDelegate parser)
Allows content-type specific parsing of the body based on content-type.
Definition: HttpServer.h:74
TcpConnection * createClient(tcp_pcb *clientTcp) override
int minHeapSize
min heap size that is required to accept connection, -1 means use server default
Definition: HttpServer.h:30
MimeType
Definition: WebConstants.h:53
Definition: HttpServer.h:27
The String class.
Definition: WString.h:136
HttpResourceTree paths
Maps paths to resources which deal with incoming requests.
Definition: HttpServer.h:81
Class to map URL paths to classes which handle them.
Definition: HttpResourceTree.h:26
uint16_t keepAliveSeconds
default seconds to keep the connection alive before closing it
Definition: HttpServer.h:29
std::enable_if< std::is_integral< T >::value, String >::type toString(T value)
Definition: BitSet.h:481
Definition: TcpServer.h:30
bool closeOnContentError
close the connection if a body parser or resource fails to parse the body content.
Definition: HttpServer.h:32
void configure(const HttpServerSettings &settings)
Allows changing the server configuration.
HttpServer()
Definition: HttpServer.h:39
bool useDefaultBodyParsers
if the default body parsers, as form-url-encoded, should be used
Definition: HttpServer.h:31
void setBodyParser(const String &contentType, HttpBodyParserDelegate parser)
Allows content-type specific parsing of the body based on content-type.
Definition: HttpServer.h:64
Definition: TcpConnection.h:39
Definition: HttpServer.h:36
uint16_t maxActiveConnections
maximum number of concurrent requests..
Definition: HttpServer.h:28
HttpServer(const HttpServerSettings &settings)
Definition: HttpServer.h:45