Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
P
pistache
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Libraries
pistache
Commits
8d66752c
Commit
8d66752c
authored
Sep 24, 2018
by
Pablo
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
add rest async minimal test
parent
e4c43797
Changes
3
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
2397 additions
and
0 deletions
+2397
-0
tests/CMakeLists.txt
tests/CMakeLists.txt
+1
-0
tests/httplib.h
tests/httplib.h
+2318
-0
tests/rest_server_test.cc
tests/rest_server_test.cc
+78
-0
No files found.
tests/CMakeLists.txt
View file @
8d66752c
...
@@ -20,3 +20,4 @@ pistache_test(http_client_test)
...
@@ -20,3 +20,4 @@ pistache_test(http_client_test)
pistache_test
(
net_test
)
pistache_test
(
net_test
)
pistache_test
(
listener_test
)
pistache_test
(
listener_test
)
pistache_test
(
payload_test
)
pistache_test
(
payload_test
)
pistache_test
(
rest_server_test
)
tests/httplib.h
0 → 100644
View file @
8d66752c
This diff is collapsed.
Click to expand it.
tests/rest_server_test.cc
0 → 100644
View file @
8d66752c
/*
Mathieu Stefani, 07 février 2016
Example of a REST endpoint with routing
*/
#include "gtest/gtest.h"
#include <pistache/http.h>
#include <pistache/router.h>
#include <pistache/endpoint.h>
#include "httplib.h"
using
namespace
std
;
using
namespace
Pistache
;
class
StatsEndpoint
{
public:
StatsEndpoint
(
Address
addr
)
:
httpEndpoint
(
std
::
make_shared
<
Http
::
Endpoint
>
(
addr
))
{
}
void
init
(
size_t
thr
=
2
)
{
auto
opts
=
Http
::
Endpoint
::
options
()
.
threads
(
thr
)
.
flags
(
Tcp
::
Options
::
InstallSignalHandler
);
httpEndpoint
->
init
(
opts
);
setupRoutes
();
}
void
start
()
{
httpEndpoint
->
setHandler
(
router
.
handler
());
httpEndpoint
->
serveThreaded
();
}
void
shutdown
()
{
httpEndpoint
->
shutdown
();
}
private:
void
setupRoutes
()
{
using
namespace
Rest
;
Routes
::
Get
(
router
,
"/read/function1"
,
Routes
::
bind
(
&
StatsEndpoint
::
doAuth
,
this
));
}
void
doAuth
(
const
Rest
::
Request
&
request
,
Http
::
ResponseWriter
response
)
{
std
::
thread
worker
([](
Http
::
ResponseWriter
writer
)
{
writer
.
send
(
Http
::
Code
::
Ok
,
"1"
);
},
std
::
move
(
response
));
worker
.
detach
();
}
std
::
shared_ptr
<
Http
::
Endpoint
>
httpEndpoint
;
Rest
::
Router
router
;
};
TEST
(
rest_server_test
,
basic_test
)
{
Port
port
(
9090
);
int
thr
=
1
;
Address
addr
(
Ipv4
::
any
(),
port
);
StatsEndpoint
stats
(
addr
);
stats
.
init
(
thr
);
stats
.
start
();
cout
<<
"Cores = "
<<
hardware_concurrency
()
<<
endl
;
cout
<<
"Using "
<<
thr
<<
" threads"
<<
endl
;
httplib
::
Client
client
(
"localhost"
,
9090
);
auto
res
=
client
.
Get
(
"/read/function1"
);
ASSERT_EQ
(
res
->
status
,
200
);
ASSERT_EQ
(
res
->
body
,
"1"
);
stats
.
shutdown
();
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment