Unverified Commit ea22f2d1 authored by bbarbisch's avatar bbarbisch Committed by GitHub

fix endpoint initialization (#927)

if setHandler is called before init is called, the values for
maxRequestSize and maxResponseSize are not set correctly in the handler.
parent e4a9b227
......@@ -217,6 +217,11 @@ namespace Pistache
return transport;
});
if(handler_) {
handler_->setMaxRequestSize(options.maxRequestSize_);
handler_->setMaxResponseSize(options.maxResponseSize_);
}
options_ = options;
logger_ = options.logger_;
}
......
......@@ -43,6 +43,7 @@ pistache_test(reactor_test)
pistache_test(threadname_test)
pistache_test(log_api_test)
pistache_test(string_logger_test)
pistache_test(endpoint_initialization_test)
if (PISTACHE_USE_SSL)
......
#include <pistache/endpoint.h>
#include <pistache/router.h>
#include "gtest/gtest.h"
using namespace Pistache;
TEST(endpoint_initialization_test, initialize_options_before_handler) {
Rest::Router router;
auto handler = router.handler();
Address addr(Ipv4::any(), Port(0));
Http::Endpoint endpoint(addr);
size_t maxReqSize = 123;
size_t maxRespSize = 456;
auto opts = Http::Endpoint::options();
opts.threads(2);
opts.maxRequestSize(maxReqSize);
opts.maxResponseSize(maxRespSize);
endpoint.init(opts);
endpoint.setHandler(handler);
ASSERT_EQ(handler->getMaxRequestSize(), maxReqSize);
ASSERT_EQ(handler->getMaxResponseSize(), maxRespSize);
}
TEST(endpoint_initialization_test, initialize_handler_before_options) {
Rest::Router router;
auto handler = router.handler();
Address addr(Ipv4::any(), Port(0));
Http::Endpoint endpoint(addr);
size_t maxReqSize = 123;
size_t maxRespSize = 456;
auto opts = Http::Endpoint::options();
opts.threads(2);
opts.maxRequestSize(maxReqSize);
opts.maxResponseSize(maxRespSize);
endpoint.setHandler(handler);
endpoint.init(opts);
ASSERT_EQ(handler->getMaxRequestSize(), maxReqSize);
ASSERT_EQ(handler->getMaxResponseSize(), maxRespSize);
}
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment