(http server) read body request when the Content-Length is specified + set timeout to read the request to 30 seconds max by default, and make it configurable as a constructor parameter
This commit is contained in:
parent
b04e5c5529
commit
128bc0afa9
@ -2,6 +2,9 @@
|
|||||||
|
|
||||||
All changes to this project will be documented in this file.
|
All changes to this project will be documented in this file.
|
||||||
|
|
||||||
|
## [10.4.0] - 2020-09-12
|
||||||
|
|
||||||
|
(http server) read body request when the Content-Length is specified + set timeout to read the request to 30 seconds max by default, and make it configurable as a constructor parameter
|
||||||
|
|
||||||
## [10.3.5] - 2020-09-09
|
## [10.3.5] - 2020-09-09
|
||||||
|
|
||||||
|
@ -93,14 +93,12 @@ namespace ix
|
|||||||
}
|
}
|
||||||
|
|
||||||
std::tuple<bool, std::string, HttpRequestPtr> Http::parseRequest(
|
std::tuple<bool, std::string, HttpRequestPtr> Http::parseRequest(
|
||||||
std::unique_ptr<Socket>& socket)
|
std::unique_ptr<Socket>& socket, int timeoutSecs)
|
||||||
{
|
{
|
||||||
HttpRequestPtr httpRequest;
|
HttpRequestPtr httpRequest;
|
||||||
|
|
||||||
std::atomic<bool> requestInitCancellation(false);
|
std::atomic<bool> requestInitCancellation(false);
|
||||||
|
|
||||||
int timeoutSecs = 5; // FIXME
|
|
||||||
|
|
||||||
auto isCancellationRequested =
|
auto isCancellationRequested =
|
||||||
makeCancellationRequestWithTimeout(timeoutSecs, requestInitCancellation);
|
makeCancellationRequestWithTimeout(timeoutSecs, requestInitCancellation);
|
||||||
|
|
||||||
|
@ -118,7 +118,7 @@ namespace ix
|
|||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
static std::tuple<bool, std::string, HttpRequestPtr> parseRequest(
|
static std::tuple<bool, std::string, HttpRequestPtr> parseRequest(
|
||||||
std::unique_ptr<Socket>& socket);
|
std::unique_ptr<Socket>& socket, int timeoutSecs);
|
||||||
static bool sendResponse(HttpResponsePtr response, std::unique_ptr<Socket>& socket);
|
static bool sendResponse(HttpResponsePtr response, std::unique_ptr<Socket>& socket);
|
||||||
|
|
||||||
static std::pair<std::string, int> parseStatusLine(const std::string& line);
|
static std::pair<std::string, int> parseStatusLine(const std::string& line);
|
||||||
|
@ -92,10 +92,17 @@ namespace
|
|||||||
|
|
||||||
namespace ix
|
namespace ix
|
||||||
{
|
{
|
||||||
HttpServer::HttpServer(
|
const int HttpServer::kDefaultTimeoutSecs(30);
|
||||||
int port, const std::string& host, int backlog, size_t maxConnections, int addressFamily)
|
|
||||||
|
HttpServer::HttpServer(int port,
|
||||||
|
const std::string& host,
|
||||||
|
int backlog,
|
||||||
|
size_t maxConnections,
|
||||||
|
int addressFamily,
|
||||||
|
int timeoutSecs)
|
||||||
: SocketServer(port, host, backlog, maxConnections, addressFamily)
|
: SocketServer(port, host, backlog, maxConnections, addressFamily)
|
||||||
, _connectedClientsCount(0)
|
, _connectedClientsCount(0)
|
||||||
|
, _timeoutSecs(timeoutSecs)
|
||||||
{
|
{
|
||||||
setDefaultConnectionCallback();
|
setDefaultConnectionCallback();
|
||||||
}
|
}
|
||||||
@ -124,7 +131,7 @@ namespace ix
|
|||||||
{
|
{
|
||||||
_connectedClientsCount++;
|
_connectedClientsCount++;
|
||||||
|
|
||||||
auto ret = Http::parseRequest(socket);
|
auto ret = Http::parseRequest(socket, _timeoutSecs);
|
||||||
// FIXME: handle errors in parseRequest
|
// FIXME: handle errors in parseRequest
|
||||||
|
|
||||||
if (std::get<0>(ret))
|
if (std::get<0>(ret))
|
||||||
|
@ -29,7 +29,8 @@ namespace ix
|
|||||||
const std::string& host = SocketServer::kDefaultHost,
|
const std::string& host = SocketServer::kDefaultHost,
|
||||||
int backlog = SocketServer::kDefaultTcpBacklog,
|
int backlog = SocketServer::kDefaultTcpBacklog,
|
||||||
size_t maxConnections = SocketServer::kDefaultMaxConnections,
|
size_t maxConnections = SocketServer::kDefaultMaxConnections,
|
||||||
int addressFamily = SocketServer::kDefaultAddressFamily);
|
int addressFamily = SocketServer::kDefaultAddressFamily,
|
||||||
|
int timeoutSecs = HttpServer::kDefaultTimeoutSecs);
|
||||||
virtual ~HttpServer();
|
virtual ~HttpServer();
|
||||||
virtual void stop() final;
|
virtual void stop() final;
|
||||||
|
|
||||||
@ -42,6 +43,9 @@ namespace ix
|
|||||||
OnConnectionCallback _onConnectionCallback;
|
OnConnectionCallback _onConnectionCallback;
|
||||||
std::atomic<int> _connectedClientsCount;
|
std::atomic<int> _connectedClientsCount;
|
||||||
|
|
||||||
|
const static int kDefaultTimeoutSecs;
|
||||||
|
int _timeoutSecs;
|
||||||
|
|
||||||
// Methods
|
// Methods
|
||||||
virtual void handleConnection(std::unique_ptr<Socket>,
|
virtual void handleConnection(std::unique_ptr<Socket>,
|
||||||
std::shared_ptr<ConnectionState> connectionState) final;
|
std::shared_ptr<ConnectionState> connectionState) final;
|
||||||
|
@ -6,4 +6,4 @@
|
|||||||
|
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#define IX_WEBSOCKET_VERSION "10.3.5"
|
#define IX_WEBSOCKET_VERSION "10.4.0"
|
||||||
|
Loading…
Reference in New Issue
Block a user