Skip to content

Commit 128bc0a

Browse files
committed
(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
1 parent b04e5c5 commit 128bc0a

File tree

6 files changed

+21
-9
lines changed

6 files changed

+21
-9
lines changed

docs/CHANGELOG.md

+3
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,9 @@
22

33
All changes to this project will be documented in this file.
44

5+
## [10.4.0] - 2020-09-12
6+
7+
(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
58

69
## [10.3.5] - 2020-09-09
710

ixwebsocket/IXHttp.cpp

+1-3
Original file line numberDiff line numberDiff line change
@@ -93,14 +93,12 @@ namespace ix
9393
}
9494

9595
std::tuple<bool, std::string, HttpRequestPtr> Http::parseRequest(
96-
std::unique_ptr<Socket>& socket)
96+
std::unique_ptr<Socket>& socket, int timeoutSecs)
9797
{
9898
HttpRequestPtr httpRequest;
9999

100100
std::atomic<bool> requestInitCancellation(false);
101101

102-
int timeoutSecs = 5; // FIXME
103-
104102
auto isCancellationRequested =
105103
makeCancellationRequestWithTimeout(timeoutSecs, requestInitCancellation);
106104

ixwebsocket/IXHttp.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,7 @@ namespace ix
118118
{
119119
public:
120120
static std::tuple<bool, std::string, HttpRequestPtr> parseRequest(
121-
std::unique_ptr<Socket>& socket);
121+
std::unique_ptr<Socket>& socket, int timeoutSecs);
122122
static bool sendResponse(HttpResponsePtr response, std::unique_ptr<Socket>& socket);
123123

124124
static std::pair<std::string, int> parseStatusLine(const std::string& line);

ixwebsocket/IXHttpServer.cpp

+10-3
Original file line numberDiff line numberDiff line change
@@ -92,10 +92,17 @@ namespace
9292

9393
namespace ix
9494
{
95-
HttpServer::HttpServer(
96-
int port, const std::string& host, int backlog, size_t maxConnections, int addressFamily)
95+
const int HttpServer::kDefaultTimeoutSecs(30);
96+
97+
HttpServer::HttpServer(int port,
98+
const std::string& host,
99+
int backlog,
100+
size_t maxConnections,
101+
int addressFamily,
102+
int timeoutSecs)
97103
: SocketServer(port, host, backlog, maxConnections, addressFamily)
98104
, _connectedClientsCount(0)
105+
, _timeoutSecs(timeoutSecs)
99106
{
100107
setDefaultConnectionCallback();
101108
}
@@ -124,7 +131,7 @@ namespace ix
124131
{
125132
_connectedClientsCount++;
126133

127-
auto ret = Http::parseRequest(socket);
134+
auto ret = Http::parseRequest(socket, _timeoutSecs);
128135
// FIXME: handle errors in parseRequest
129136

130137
if (std::get<0>(ret))

ixwebsocket/IXHttpServer.h

+5-1
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,8 @@ namespace ix
2929
const std::string& host = SocketServer::kDefaultHost,
3030
int backlog = SocketServer::kDefaultTcpBacklog,
3131
size_t maxConnections = SocketServer::kDefaultMaxConnections,
32-
int addressFamily = SocketServer::kDefaultAddressFamily);
32+
int addressFamily = SocketServer::kDefaultAddressFamily,
33+
int timeoutSecs = HttpServer::kDefaultTimeoutSecs);
3334
virtual ~HttpServer();
3435
virtual void stop() final;
3536

@@ -42,6 +43,9 @@ namespace ix
4243
OnConnectionCallback _onConnectionCallback;
4344
std::atomic<int> _connectedClientsCount;
4445

46+
const static int kDefaultTimeoutSecs;
47+
int _timeoutSecs;
48+
4549
// Methods
4650
virtual void handleConnection(std::unique_ptr<Socket>,
4751
std::shared_ptr<ConnectionState> connectionState) final;

ixwebsocket/IXWebSocketVersion.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,4 +6,4 @@
66

77
#pragma once
88

9-
#define IX_WEBSOCKET_VERSION "10.3.5"
9+
#define IX_WEBSOCKET_VERSION "10.4.0"

0 commit comments

Comments
 (0)