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
ddf9c22c
Commit
ddf9c22c
authored
Aug 31, 2015
by
Mathieu Stefani
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Started to add tests for header parsing
parent
1efd9e47
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
55 additions
and
4 deletions
+55
-4
src/http_header.cc
src/http_header.cc
+1
-1
src/http_header.h
src/http_header.h
+4
-3
tests/CMakeLists.txt
tests/CMakeLists.txt
+4
-0
tests/headers_test.cc
tests/headers_test.cc
+46
-0
No files found.
src/http_header.cc
View file @
ddf9c22c
...
...
@@ -74,7 +74,7 @@ Host::parse(const std::string& data) {
port_
=
p
;
}
else
{
host_
=
data
;
port_
=
-
1
;
port_
=
80
;
}
}
...
...
src/http_header.h
View file @
ddf9c22c
...
...
@@ -7,6 +7,7 @@
#pragma once
#include "mime.h"
#include "net.h"
#include <string>
#include <type_traits>
#include <memory>
...
...
@@ -138,7 +139,7 @@ public:
,
port_
(
-
1
)
{
}
explicit
Host
(
const
std
::
string
&
host
,
int16_t
port
=
-
1
)
explicit
Host
(
const
std
::
string
&
host
,
Net
::
Port
port
=
80
)
:
host_
(
host
)
,
port_
(
port
)
{
}
...
...
@@ -147,11 +148,11 @@ public:
void
write
(
std
::
ostream
&
os
)
const
;
std
::
string
host
()
const
{
return
host_
;
}
int16_
t
port
()
const
{
return
port_
;
}
Net
::
Por
t
port
()
const
{
return
port_
;
}
private:
std
::
string
host_
;
int16_
t
port_
;
Net
::
Por
t
port_
;
};
class
UserAgent
:
public
Header
{
...
...
tests/CMakeLists.txt
View file @
ddf9c22c
add_executable
(
run_mime_test mime_test.cc
)
target_link_libraries
(
run_mime_test gtest gtest_main net
)
add_test
(
mime_test run_mime_test
)
add_executable
(
run_headers_test headers_test.cc
)
target_link_libraries
(
run_headers_test gtest gtest_main net
)
add_test
(
headers_test run_headers_test
)
tests/headers_test.cc
0 → 100644
View file @
ddf9c22c
#include "gtest/gtest.h"
#include "http_headers.h"
using
namespace
Net
::
Http
;
TEST
(
headers_test
,
content_length
)
{
ContentLength
cl
;
cl
.
parse
(
"3495"
);
ASSERT_EQ
(
cl
.
value
(),
3495
);
}
TEST
(
headers_test
,
host
)
{
Host
host
;
host
.
parse
(
"www.w3.org"
);
ASSERT_EQ
(
host
.
host
(),
"www.w3.org"
);
ASSERT_EQ
(
host
.
port
(),
80
);
host
.
parse
(
"localhost:8080"
);
ASSERT_EQ
(
host
.
host
(),
"localhost"
);
ASSERT_EQ
(
host
.
port
(),
8080
);
}
TEST
(
headers_test
,
user_agent
)
{
UserAgent
ua
;
ua
.
parse
(
"CERN-LineMode/2.15 libwww/2.17b3"
);
ASSERT_EQ
(
ua
.
ua
(),
"CERN-LineMode/2.15 libwww/2.17b3"
);
}
TEST
(
headers_test
,
content_encoding
)
{
ContentEncoding
ce
;
ce
.
parse
(
"gzip"
);
ASSERT_EQ
(
ce
.
encoding
(),
Encoding
::
Gzip
);
}
TEST
(
headers_test
,
content_type
)
{
ContentType
ct
;
ct
.
parse
(
"text/html; charset=ISO-8859-4"
);
const
auto
&
mime
=
ct
.
mime
();
ASSERT_EQ
(
mime
,
MIME
(
Text
,
Html
));
ASSERT_EQ
(
mime
.
getParam
(
"charset"
).
getOrElse
(
""
),
"ISO-8859-4"
);
}
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