Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commite772881

Browse files
committed
Adding trivial implementation of the dispatcher.
1 parent531f08f commite772881

File tree

3 files changed

+31
-3
lines changed

3 files changed

+31
-3
lines changed

‎http/src/CMakeLists.txt

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -128,5 +128,7 @@ set(CPP-NETLIB_CONSTANTS_SRCS constants.cpp)
128128
add_library(cppnetlib-constants${CPP-NETLIB_CONSTANTS_SRCS})
129129

130130
# Server implementation files.
131-
set(CPP-NETLIB_HTTP_SERVER_SRCShttp/server/session.cpphttp/server/simple_sessions.cpp)
131+
set(CPP-NETLIB_HTTP_SERVER_SRCS
132+
http/server/session.cpphttp/server/simple_sessions.cpp
133+
http/server/dynamic_dispatcher.cpp)
132134
add_library(cppnetlib-http-server${CPP-NETLIB_HTTP_SERVER_SRCS})

‎http/src/network/http/server/dynamic_dispatcher.hpprenamed to ‎http/src/http/server/dynamic_dispatcher.hpp

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,24 @@
77
#ifndef NETWORK_HTTP_SERVER_DYNAMIC_DISPATCHER_HPP_20130327
88
#defineNETWORK_HTTP_SERVER_DYNAMIC_DISPATCHER_HPP_20130327
99

10+
#include<http/server/session.hpp>
11+
#include<http/server/connection.hpp>
12+
#include<string>
13+
#include<functional>
14+
#include<memory>
15+
#include<unordered_map>
16+
1017
namespacenetwork {
1118
namespacehttp {
1219

13-
structdynamic_dispatcher{};
20+
structdynamic_dispatcher{
21+
voidregister_handler(boost::string_ref pattern, std::function<void(session&, std::shared_ptr<connection>)> handler);
22+
voiddispatch(boost::string_ref path, session& s, std::shared_ptr<connection> c);
23+
private:
24+
std::unordered_map<
25+
std::string,
26+
std::function<void(session &, std::shared_ptr<connection>)> > handlers_;
27+
};
1428

1529
}// namespace http
1630
}// namespace network

‎http/test/server_dynamic_dispatcher_test.cpp

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,23 @@
55
// http://www.boost.org/LICENSE_1_0.txt)
66

77
#include<gtest/gtest.h>
8-
#include<network/http/server/dynamic_dispatcher.hpp>
8+
#include<http/server/dynamic_dispatcher.hpp>
9+
#include<http/server/session.hpp>
10+
#include<http/server/connection.hpp>
911

1012
namespacehttp= ::network::http;
1113

1214
TEST(server_dynamic_dispatcher, constructor) {
1315
http::dynamic_dispatcher dispatcher;
1416
(void)dispatcher;
1517
}
18+
19+
TEST(server_dynamic_dispatcher, register_handler) {
20+
http::dynamic_dispatcher dispatcher;
21+
bool called =false;
22+
dispatcher.register_handler("/", [&called](http::session& s, std::shared_ptr<http::connection> c){ called =true; });
23+
http::session s;
24+
std::shared_ptr<http::connection> c;
25+
dispatcher.dispatch("/", s, c);
26+
EXPECT_EQ(true, called);
27+
}

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp