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
85f91ae5
Commit
85f91ae5
authored
Aug 24, 2018
by
Jeppe Pihl
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
update to new master, ^Cd split date test
parent
7db786eb
Changes
9
Hide whitespace changes
Inline
Side-by-side
Showing
9 changed files
with
76 additions
and
48 deletions
+76
-48
examples/hello_server.cc
examples/hello_server.cc
+19
-14
include/pistache/async.h
include/pistache/async.h
+7
-4
include/pistache/http.h
include/pistache/http.h
+9
-4
include/pistache/peer.h
include/pistache/peer.h
+1
-1
include/pistache/reactor.h
include/pistache/reactor.h
+2
-0
include/pistache/string_view.h
include/pistache/string_view.h
+2
-2
src/server/router.cc
src/server/router.cc
+3
-3
tests/headers_test.cc
tests/headers_test.cc
+19
-6
tests/string_view_test.cc
tests/string_view_test.cc
+14
-14
No files found.
examples/hello_server.cc
View file @
85f91ae5
/*
/*
Mathieu Stefani, 13 février 2016
Example of an hello world server
*/
#include <pistache/endpoint.h>
#include "pistache/endpoint.h"
using
namespace
Pistache
;
class
HelloHandler
:
public
Http
::
Handler
{
class
HelloHandler
:
public
Pistache
::
Http
::
Handler
{
public:
HTTP_PROTOTYPE
(
HelloHandler
)
void
onRequest
(
const
Http
::
Request
&
request
,
Http
::
ResponseWriter
response
)
{
response
.
send
(
Http
::
Code
::
Ok
,
"Hello World"
);
void
onRequest
(
const
Pistache
::
Http
::
Request
&
request
,
Pistache
::
Http
::
ResponseWriter
response
)
{
(
void
)
request
;
response
.
send
(
Pistache
::
Http
::
Code
::
Ok
,
"Hello World
\n
"
);
}
};
int
main
()
{
Pistache
::
Address
addr
(
Pistache
::
Ipv4
::
any
(),
Pistache
::
Port
(
9080
));
auto
opts
=
Pistache
::
Http
::
Endpoint
::
options
()
.
threads
(
1
);
auto
opts
=
Pistache
::
Http
::
Endpoint
::
options
().
threads
(
1
);
Http
::
Endpoint
server
(
addr
);
Pistache
::
Http
::
Endpoint
server
(
addr
);
server
.
init
(
opts
);
server
.
setHandler
(
Http
::
make_handler
<
HelloHandler
>
());
server
.
serve
();
server
.
setHandler
(
Pistache
::
Http
::
make_handler
<
HelloHandler
>
());
std
::
cout
<<
"Starting server. Test with the following command: "
<<
"
\"
curl http://127.0.0.1:"
<<
addr
.
port
()
<<
"
\"\n
"
;
std
::
cout
<<
"Press Enter to Exit"
<<
'\n'
;
server
.
serveThreaded
();
std
::
cin
.
get
();
server
.
shutdown
();
}
include/pistache/async.h
View file @
85f91ae5
...
...
@@ -46,6 +46,7 @@ namespace Async {
class
BadAnyCast
:
public
std
::
bad_cast
{
public:
virtual
const
char
*
what
()
const
noexcept
{
return
"Bad any cast"
;
}
virtual
~
BadAnyCast
()
{
}
};
enum
class
State
{
...
...
@@ -163,6 +164,7 @@ namespace Async {
public:
virtual
void
resolve
(
const
std
::
shared_ptr
<
Core
>&
core
)
=
0
;
virtual
void
reject
(
const
std
::
shared_ptr
<
Core
>&
core
)
=
0
;
virtual
~
Request
()
{}
};
struct
Core
{
...
...
@@ -207,6 +209,7 @@ namespace Async {
state
=
State
::
Fulfilled
;
}
virtual
~
Core
()
{
}
};
template
<
typename
T
>
...
...
@@ -290,9 +293,11 @@ namespace Async {
virtual
void
doResolve
(
const
std
::
shared_ptr
<
CoreT
<
T
>>&
core
)
=
0
;
virtual
void
doReject
(
const
std
::
shared_ptr
<
CoreT
<
T
>>&
core
)
=
0
;
std
::
shared_ptr
<
Core
>
chain_
;
virtual
~
Continuable
()
{
}
size_t
resolveCount_
;
size_t
rejectCount_
;
std
::
shared_ptr
<
Core
>
chain_
;
};
namespace
impl
{
...
...
@@ -957,9 +962,7 @@ namespace Async {
Promise
(
Promise
<
T
>&&
other
)
=
default
;
Promise
&
operator
=
(
Promise
<
T
>&&
other
)
=
default
;
~
Promise
()
{
}
virtual
~
Promise
()
{
}
template
<
typename
U
>
static
...
...
include/pistache/http.h
View file @
85f91ae5
...
...
@@ -203,8 +203,8 @@ public:
Timeout
(
Timeout
&&
other
)
:
handler
(
other
.
handler
)
,
transport
(
other
.
transport
)
,
request
(
std
::
move
(
other
.
request
))
,
transport
(
other
.
transport
)
,
armed
(
other
.
armed
)
,
timerFd
(
other
.
timerFd
)
,
peer
(
std
::
move
(
other
.
peer
))
...
...
@@ -281,8 +281,8 @@ private:
void
onTimeout
(
uint64_t
numWakeup
);
Handler
*
handler
;
Tcp
::
Transport
*
transport
;
Request
request
;
Tcp
::
Transport
*
transport
;
bool
armed
;
Fd
timerFd
;
std
::
weak_ptr
<
Tcp
::
Peer
>
peer
;
...
...
@@ -547,7 +547,7 @@ public:
return
&
buf_
;
}
DynamicStreamBuf
*
rdbuf
(
[[
maybe_unused
]]
DynamicStreamBuf
*
other
)
{
DynamicStreamBuf
*
rdbuf
(
DynamicStreamBuf
*
other
)
{
UNUSED
(
other
)
throw
std
::
domain_error
(
"Unimplemented"
);
}
...
...
@@ -638,7 +638,8 @@ namespace Private {
State
apply
(
StreamCursor
&
cursor
);
};
struct
BodyStep
:
public
Step
{
class
BodyStep
:
public
Step
{
public:
BodyStep
(
Message
*
message_
)
:
Step
(
message_
)
,
chunk
(
message_
)
...
...
@@ -699,6 +700,8 @@ namespace Private {
bool
feed
(
const
char
*
data
,
size_t
len
);
virtual
void
reset
();
virtual
~
ParserBase
()
{
}
State
parse
();
ArrayStreamBuf
<
Const
::
MaxBuffer
>
buffer
;
...
...
@@ -784,6 +787,8 @@ public:
virtual
void
onTimeout
(
const
Request
&
request
,
ResponseWriter
response
);
virtual
~
Handler
()
{
}
private:
Private
::
Parser
<
Http
::
Request
>&
getParser
(
const
std
::
shared_ptr
<
Tcp
::
Peer
>&
peer
)
const
;
};
...
...
include/pistache/peer.h
View file @
85f91ae5
...
...
@@ -57,9 +57,9 @@ private:
void
associateTransport
(
Transport
*
transport
);
Transport
*
transport
()
const
;
Transport
*
transport_
;
Address
addr
;
Fd
fd_
;
Transport
*
transport_
;
std
::
string
hostname_
;
std
::
unordered_map
<
std
::
string
,
std
::
shared_ptr
<
void
>>
data_
;
...
...
include/pistache/reactor.h
View file @
85f91ae5
...
...
@@ -218,6 +218,8 @@ public:
return
key_
;
};
virtual
~
Handler
()
{
}
private:
Reactor
*
reactor_
;
Context
context_
;
...
...
include/pistache/string_view.h
View file @
85f91ae5
...
...
@@ -64,7 +64,7 @@ namespace std {
return
size_
;
}
constexpr
c
onst
c
har
operator
[](
size_type
pos
)
const
{
constexpr
char
operator
[](
size_type
pos
)
const
{
return
data_
[
pos
];
}
...
...
@@ -107,7 +107,7 @@ namespace std {
if
(
pos
>=
size_
)
{
pos
=
size_
-
v
.
size_
;
}
for
(;
pos
>=
0
&&
pos
!=
npos
;
pos
--
)
{
for
(;
pos
!=
npos
;
pos
--
)
{
string_view
compare
=
substr
(
pos
,
v
.
size_
);
if
(
v
==
compare
)
{
return
pos
;
...
...
src/server/router.cc
View file @
85f91ae5
/* router.cc
Mathieu Stefani, 05 janvier 2016
Rest routing implementation
*/
...
...
@@ -118,7 +118,7 @@ FragmentTreeNode::addRoute(const std::string_view &path,
const
auto
next
=
(
pos
==
std
::
string_view
::
npos
)
?
currPath
.
substr
(
1
)
:
currPath
.
substr
(
pos
);
// complete lower path
auto
mid
=
(
pos
==
std
::
string_view
::
npos
)
?
currPath
.
substr
(
1
)
:
currPath
.
substr
(
1
,
currPath
.
find
(
'/'
,
pos
)
-
1
);
// middle resource name
std
::
unordered_map
<
std
::
string_view
,
std
::
shared_ptr
<
FragmentTreeNode
>>
*
collection
;
std
::
unordered_map
<
std
::
string_view
,
std
::
shared_ptr
<
FragmentTreeNode
>>
*
collection
=
nullptr
;
const
auto
fragmentType
=
getFragmentType
(
mid
);
switch
(
fragmentType
)
{
case
FragmentType
:
:
Fixed
:
...
...
@@ -163,7 +163,7 @@ bool Pistache::Rest::FragmentTreeNode::removeRoute(const std::string_view &path)
const
auto
pos
=
currPath
.
find
(
'/'
,
1
);
const
auto
next
=
(
pos
==
std
::
string_view
::
npos
)
?
currPath
.
substr
(
1
)
:
currPath
.
substr
(
pos
);
// complete lower path
auto
mid
=
(
pos
==
std
::
string_view
::
npos
)
?
currPath
.
substr
(
1
)
:
currPath
.
substr
(
1
,
currPath
.
find
(
'/'
,
pos
)
-
1
);
// middle resource name
std
::
unordered_map
<
std
::
string_view
,
std
::
shared_ptr
<
FragmentTreeNode
>>
*
collection
;
std
::
unordered_map
<
std
::
string_view
,
std
::
shared_ptr
<
FragmentTreeNode
>>
*
collection
=
nullptr
;
auto
fragmentType
=
getFragmentType
(
mid
);
switch
(
fragmentType
)
{
...
...
tests/headers_test.cc
View file @
85f91ae5
...
...
@@ -197,30 +197,43 @@ TEST(headers_test, connection) {
}
TEST
(
headers_test
,
date_test
)
{
TEST
(
headers_test
,
date_test
_rfc_1123
)
{
using
namespace
std
::
chrono
;
FullDate
::
time_point
expected_time_point
=
date
::
sys_days
(
date
::
year
{
1994
}
/
11
/
6
)
+
hours
(
8
)
+
minutes
(
49
)
+
seconds
(
37
);
/* RFC-1123 */
/* RFC-1123 */
Header
::
Date
d1
;
d1
.
parse
(
"Sun, 06 Nov 1994 08:49:37 GMT"
);
auto
dd1
=
d1
.
fullDate
().
date
();
ASSERT_EQ
(
expected_time_point
,
dd1
);
}
TEST
(
headers_test
,
date_test_rfc_850
)
{
using
namespace
std
::
chrono
;
FullDate
::
time_point
expected_time_point
=
date
::
sys_days
(
date
::
year
{
1994
}
/
11
/
6
)
+
hours
(
8
)
+
minutes
(
49
)
+
seconds
(
37
);
/* RFC-850 */
Header
::
Date
d2
;
d2
.
parse
(
"Sunday, 06-Nov-94 08:49:37 GMT"
);
auto
dd2
=
d2
.
fullDate
().
date
();
ASSERT_EQ
(
dd2
,
expected_time_point
);
}
TEST
(
headers_test
,
date_test_asctime
)
{
using
namespace
std
::
chrono
;
FullDate
::
time_point
expected_time_point
=
date
::
sys_days
(
date
::
year
{
1994
}
/
11
/
6
)
+
hours
(
8
)
+
minutes
(
49
)
+
seconds
(
37
);
/* ANSI C's asctime format */
Header
::
Date
d3
;
d3
.
parse
(
"Sun Nov 6 08:49:37 1994"
);
auto
dd3
=
d3
.
fullDate
().
date
();
ASSERT_EQ
(
dd3
,
expected_time_point
);
}
TEST
(
headers_test
,
host
)
{
...
...
tests/string_view_test.cc
View file @
85f91ae5
...
...
@@ -19,18 +19,18 @@ TEST(string_view_test, find_test) {
std
::
string_view
orig
(
"test"
);
std
::
string_view
find
(
"est"
);
ASSERT_EQ
(
orig
.
find
(
find
),
1
);
ASSERT_EQ
(
orig
.
find
(
find
,
1
),
1
);
ASSERT_EQ
(
orig
.
find
(
find
),
1
U
);
ASSERT_EQ
(
orig
.
find
(
find
,
1
),
1
U
);
ASSERT_EQ
(
orig
.
find
(
find
,
2
),
std
::
size_t
(
-
1
));
ASSERT_EQ
(
orig
.
find
(
'e'
),
1
);
ASSERT_EQ
(
orig
.
find
(
'e'
,
1
),
1
);
ASSERT_EQ
(
orig
.
find
(
'e'
),
1
U
);
ASSERT_EQ
(
orig
.
find
(
'e'
,
1
),
1
U
);
ASSERT_EQ
(
orig
.
find
(
'e'
,
2
),
std
::
size_t
(
-
1
));
ASSERT_EQ
(
orig
.
find
(
'1'
),
std
::
size_t
(
-
1
));
ASSERT_EQ
(
orig
.
find
(
"est"
),
1
);
ASSERT_EQ
(
orig
.
find
(
"est"
,
1
),
1
);
ASSERT_EQ
(
orig
.
find
(
"est"
,
1
,
2
),
1
);
ASSERT_EQ
(
orig
.
find
(
"est"
),
1
U
);
ASSERT_EQ
(
orig
.
find
(
"est"
,
1
),
1
U
);
ASSERT_EQ
(
orig
.
find
(
"est"
,
1
,
2
),
1
U
);
ASSERT_EQ
(
orig
.
find
(
"set"
),
std
::
size_t
(
-
1
));
ASSERT_EQ
(
orig
.
find
(
"est"
,
2
),
std
::
size_t
(
-
1
));
ASSERT_EQ
(
orig
.
find
(
"est"
,
2
,
2
),
std
::
size_t
(
-
1
));
...
...
@@ -40,16 +40,16 @@ TEST(string_view_test, rfind_test) {
std
::
string_view
orig
(
"test"
);
std
::
string_view
find
(
"est"
);
ASSERT_EQ
(
orig
.
rfind
(
find
),
1
);
ASSERT_EQ
(
orig
.
rfind
(
find
,
1
),
1
);
ASSERT_EQ
(
orig
.
rfind
(
find
),
1
U
);
ASSERT_EQ
(
orig
.
rfind
(
find
,
1
),
1
U
);
ASSERT_EQ
(
orig
.
rfind
(
'e'
),
1
);
ASSERT_EQ
(
orig
.
rfind
(
'e'
,
1
),
1
);
ASSERT_EQ
(
orig
.
rfind
(
'e'
),
1
U
);
ASSERT_EQ
(
orig
.
rfind
(
'e'
,
1
),
1
U
);
ASSERT_EQ
(
orig
.
rfind
(
'q'
),
std
::
size_t
(
-
1
));
ASSERT_EQ
(
orig
.
rfind
(
"est"
),
1
);
ASSERT_EQ
(
orig
.
rfind
(
"est"
,
1
),
1
);
ASSERT_EQ
(
orig
.
rfind
(
"est"
,
1
,
2
),
1
);
ASSERT_EQ
(
orig
.
rfind
(
"est"
),
1
U
);
ASSERT_EQ
(
orig
.
rfind
(
"est"
,
1
),
1
U
);
ASSERT_EQ
(
orig
.
rfind
(
"est"
,
1
,
2
),
1
U
);
ASSERT_EQ
(
orig
.
rfind
(
"set"
),
std
::
size_t
(
-
1
));
}
...
...
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