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
84da2c7d
Commit
84da2c7d
authored
Dec 25, 2018
by
hydratim
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Some minor changes and some more tests
parent
bda745dc
Changes
5
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
58 additions
and
6 deletions
+58
-6
src/common/http_header.cc
src/common/http_header.cc
+18
-1
src/common/net.cc
src/common/net.cc
+17
-4
tests/CMakeLists.txt
tests/CMakeLists.txt
+1
-1
tests/headers_test.cc
tests/headers_test.cc
+16
-0
tests/net_test.cc
tests/net_test.cc
+6
-0
No files found.
src/common/http_header.cc
View file @
84da2c7d
...
...
@@ -14,6 +14,7 @@
#include <pistache/common.h>
#include <pistache/http.h>
#include <pistache/stream.h>
#include <arpa/inet.h>
using
namespace
std
;
...
...
@@ -345,7 +346,15 @@ Host::parse(const std::string& data) {
unsigned
long
s_pos
=
data
.
find
(
'['
);
if
(
pos
!=
std
::
string
::
npos
&&
s_pos
!=
std
::
string
::
npos
)
{
//IPv6 address
host_
=
data
.
substr
(
s_pos
+
1
,
pos
-
1
);
host_
=
data
.
substr
(
s_pos
,
pos
+
1
);
try
{
in6_addr
addr6
;
char
buff6
[
INET6_ADDRSTRLEN
+
1
];
memcpy
(
buff6
,
host_
.
c_str
(),
INET6_ADDRSTRLEN
);
inet_pton
(
AF_INET6
,
buff6
,
&
(
addr6
.
s6_addr16
));
}
catch
(
std
::
runtime_error
)
{
throw
std
::
invalid_argument
(
"Invalid IPv6 address"
);
}
pos
++
;
}
else
{
//IPv4 address
...
...
@@ -358,6 +367,14 @@ Host::parse(const std::string& data) {
if
(
host_
==
"*"
)
{
host_
=
"0.0.0.0"
;
}
try
{
in_addr
addr
;
char
buff
[
INET_ADDRSTRLEN
+
1
];
memcpy
(
buff
,
host_
.
c_str
(),
INET_ADDRSTRLEN
);
inet_pton
(
AF_INET
,
buff
,
&
(
addr
));
}
catch
(
std
::
runtime_error
)
{
throw
std
::
invalid_argument
(
"Invalid IPv4 address"
);
}
}
char
*
end
;
const
std
::
string
portPart
=
data
.
substr
(
pos
+
1
);
...
...
src/common/net.cc
View file @
84da2c7d
...
...
@@ -172,9 +172,7 @@ Address::fromUnix(struct sockaddr* addr) {
assert
(
addr
);
return
Address
(
host
,
port
);
}
throw
Error
(
"Not an IP socket"
);
throw
Error
(
"Not an IP socket"
);
}
std
::
string
...
...
@@ -199,17 +197,32 @@ Address::init(const std::string& addr) {
if
(
pos
!=
std
::
string
::
npos
&&
s_pos
!=
std
::
string
::
npos
)
{
//IPv6 address
host_
=
addr
.
substr
(
s_pos
,
pos
+
1
);
try
{
in6_addr
addr6
;
char
buff6
[
INET6_ADDRSTRLEN
+
1
];
memcpy
(
buff6
,
host_
.
c_str
(),
INET6_ADDRSTRLEN
);
inet_pton
(
AF_INET6
,
buff6
,
&
(
addr6
.
s6_addr16
));
}
catch
(
std
::
runtime_error
)
{
throw
std
::
invalid_argument
(
"Invalid IPv6 address"
);
}
pos
++
;
}
else
{
//IPv4 address
pos
=
addr
.
find
(
':'
);
if
(
pos
==
std
::
string
::
npos
)
throw
std
::
invalid_argument
(
"Invalid address"
);
host_
=
addr
.
substr
(
0
,
pos
);
if
(
host_
==
"*"
)
{
host_
=
"0.0.0.0"
;
}
try
{
in_addr
addr
;
char
buff
[
INET_ADDRSTRLEN
+
1
];
memcpy
(
buff
,
host_
.
c_str
(),
INET6_ADDRSTRLEN
);
inet_pton
(
AF_INET
,
buff
,
&
(
addr
));
}
catch
(
std
::
runtime_error
)
{
throw
std
::
invalid_argument
(
"Invalid IPv4 address"
);
}
}
char
*
end
;
const
std
::
string
portPart
=
addr
.
substr
(
pos
+
1
);
...
...
tests/CMakeLists.txt
View file @
84da2c7d
...
...
@@ -3,7 +3,7 @@ function(pistache_test test_name)
set
(
TEST_SOURCE
${
test_name
}
.cc
)
add_executable
(
${
TEST_EXECUTABLE
}
${
TEST_SOURCE
}
)
target_link_libraries
(
${
TEST_EXECUTABLE
}
gtest gtest_main pistache curl
)
target_link_libraries
(
${
TEST_EXECUTABLE
}
gtest gtest_main pistache curl
pthread
)
add_test
(
${
test_name
}
${
TEST_EXECUTABLE
}
)
endfunction
()
...
...
tests/headers_test.cc
View file @
84da2c7d
...
...
@@ -246,6 +246,22 @@ TEST(headers_test, host) {
host
.
parse
(
"localhost:8080"
);
ASSERT_EQ
(
host
.
host
(),
"localhost"
);
ASSERT_EQ
(
host
.
port
(),
8080
);
/* Due to an error in GLIBC these tests don't fail as expected, further research needed */
// ASSERT_THROW( host.parse("256.256.256.256:8080");, std::invalid_argument);
// ASSERT_THROW( host.parse("1.0.0.256:8080");, std::invalid_argument);
host
.
parse
(
"[::1]:8080"
);
ASSERT_EQ
(
host
.
host
(),
"[::1]"
);
ASSERT_EQ
(
host
.
port
(),
8080
);
host
.
parse
(
"[2001:0DB8:AABB:CCDD:EEFF:0011:2233:4455]:8080"
);
ASSERT_EQ
(
host
.
host
(),
"[2001:0DB8:AABB:CCDD:EEFF:0011:2233:4455]"
);
ASSERT_EQ
(
host
.
port
(),
8080
);
/* Due to an error in GLIBC these tests don't fail as expected, further research needed */
// ASSERT_THROW( host.parse("[GGGG:GGGG:GGGG:GGGG:GGGG:GGGG:GGGG:GGGG]:8080");, std::invalid_argument);
// ASSERT_THROW( host.parse("[::GGGG]:8080");, std::invalid_argument);
}
TEST
(
headers_test
,
user_agent
)
{
...
...
tests/net_test.cc
View file @
84da2c7d
...
...
@@ -81,4 +81,10 @@ TEST(net_test, invalid_address)
ASSERT_THROW
(
Address
(
"127.0.0.1:9999999"
),
std
::
invalid_argument
);
ASSERT_THROW
(
Address
(
"127.0.0.1:"
),
std
::
invalid_argument
);
ASSERT_THROW
(
Address
(
"127.0.0.1:-10"
),
std
::
invalid_argument
);
/* Due to an error in GLIBC these tests don't fail as expected, further research needed */
// ASSERT_THROW(Address("[GGGG:GGGG:GGGG:GGGG:GGGG:GGGG:GGGG:GGGG]:8080");, std::invalid_argument);
// ASSERT_THROW(Address("[::GGGG]:8080");, std::invalid_argument);
// ASSERT_THROW(Address("256.256.256.256:8080");, std::invalid_argument);
// ASSERT_THROW(Address("1.0.0.256:8080");, std::invalid_argument);
}
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