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
f7c9715d
Commit
f7c9715d
authored
Dec 08, 2018
by
ciody
Browse files
Options
Browse Files
Download
Plain Diff
Merge remote-tracking branch 'upstream/master'
parents
26d82184
516da229
Changes
5
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
63 additions
and
38 deletions
+63
-38
examples/custom_header.cc
examples/custom_header.cc
+1
-1
include/pistache/http_header.h
include/pistache/http_header.h
+28
-28
include/pistache/http_headers.h
include/pistache/http_headers.h
+1
-1
src/common/http_headers.cc
src/common/http_headers.cc
+6
-5
tests/headers_test.cc
tests/headers_test.cc
+27
-3
No files found.
examples/custom_header.cc
View file @
f7c9715d
...
@@ -49,7 +49,7 @@ public:
...
@@ -49,7 +49,7 @@ public:
min
=
std
::
stoi
(
minor
);
min
=
std
::
stoi
(
minor
);
}
}
void
write
(
std
::
ostream
&
os
)
const
{
void
write
(
std
::
ostream
&
os
)
const
override
{
os
<<
maj
;
os
<<
maj
;
os
<<
"."
<<
min
;
os
<<
"."
<<
min
;
}
}
...
...
include/pistache/http_header.h
View file @
f7c9715d
...
@@ -45,13 +45,13 @@ constexpr uint64_t hash(const char* str)
...
@@ -45,13 +45,13 @@ constexpr uint64_t hash(const char* str)
#ifdef SAFE_HEADER_CAST
#ifdef SAFE_HEADER_CAST
#define NAME(header_name) \
#define NAME(header_name) \
static constexpr uint64_t Hash = Pistache::Http::Header::detail::hash(header_name); \
static constexpr uint64_t Hash = Pistache::Http::Header::detail::hash(header_name); \
uint64_t hash() const { return Hash; } \
uint64_t hash() const
override
{ return Hash; } \
static constexpr const char *Name = header_name; \
static constexpr const char *Name = header_name; \
const char *name() const { return Name; }
const char *name() const
override
{ return Name; }
#else
#else
#define NAME(header_name) \
#define NAME(header_name) \
static constexpr const char *Name = header_name; \
static constexpr const char *Name = header_name; \
const char *name() const { return Name; }
const char *name() const
override
{ return Name; }
#endif
#endif
// 3.5 Content Codings
// 3.5 Content Codings
...
@@ -135,8 +135,8 @@ public:
...
@@ -135,8 +135,8 @@ public:
methods_
.
push_back
(
method
);
methods_
.
push_back
(
method
);
}
}
void
parseRaw
(
const
char
*
str
,
size_t
len
);
void
parseRaw
(
const
char
*
str
,
size_t
len
)
override
;
void
write
(
std
::
ostream
&
os
)
const
;
void
write
(
std
::
ostream
&
os
)
const
override
;
void
addMethod
(
Http
::
Method
method
);
void
addMethod
(
Http
::
Method
method
);
void
addMethods
(
std
::
initializer_list
<
Method
>
methods
);
void
addMethods
(
std
::
initializer_list
<
Method
>
methods
);
...
@@ -156,8 +156,8 @@ public:
...
@@ -156,8 +156,8 @@ public:
:
mediaRange_
()
:
mediaRange_
()
{
}
{
}
void
parseRaw
(
const
char
*
str
,
size_t
len
);
void
parseRaw
(
const
char
*
str
,
size_t
len
)
override
;
void
write
(
std
::
ostream
&
os
)
const
;
void
write
(
std
::
ostream
&
os
)
const
override
;
const
std
::
vector
<
Mime
::
MediaType
>
media
()
const
{
return
mediaRange_
;
}
const
std
::
vector
<
Mime
::
MediaType
>
media
()
const
{
return
mediaRange_
;
}
...
@@ -180,8 +180,8 @@ public:
...
@@ -180,8 +180,8 @@ public:
:
uri_
(
uri
)
:
uri_
(
uri
)
{
}
{
}
void
parse
(
const
std
::
string
&
data
);
void
parse
(
const
std
::
string
&
data
)
override
;
void
write
(
std
::
ostream
&
os
)
const
;
void
write
(
std
::
ostream
&
os
)
const
override
;
void
setUri
(
std
::
string
uri
)
{
void
setUri
(
std
::
string
uri
)
{
uri_
=
std
::
move
(
uri
);
uri_
=
std
::
move
(
uri
);
...
@@ -208,8 +208,8 @@ public:
...
@@ -208,8 +208,8 @@ public:
:
val_
(
val
)
:
val_
(
val
)
{
}
{
}
void
parse
(
const
std
::
string
&
data
);
void
parse
(
const
std
::
string
&
data
)
override
;
void
write
(
std
::
ostream
&
os
)
const
;
void
write
(
std
::
ostream
&
os
)
const
override
;
void
setUri
(
std
::
string
val
)
{
void
setUri
(
std
::
string
val
)
{
val_
=
std
::
move
(
val
);
val_
=
std
::
move
(
val
);
...
@@ -291,7 +291,7 @@ public:
...
@@ -291,7 +291,7 @@ public:
explicit
CacheControl
(
Http
::
CacheDirective
directive
);
explicit
CacheControl
(
Http
::
CacheDirective
directive
);
void
parseRaw
(
const
char
*
str
,
size_t
len
);
void
parseRaw
(
const
char
*
str
,
size_t
len
);
void
write
(
std
::
ostream
&
os
)
const
;
void
write
(
std
::
ostream
&
os
)
const
override
;
std
::
vector
<
Http
::
CacheDirective
>
directives
()
const
{
return
directives_
;
}
std
::
vector
<
Http
::
CacheDirective
>
directives
()
const
{
return
directives_
;
}
...
@@ -315,7 +315,7 @@ public:
...
@@ -315,7 +315,7 @@ public:
{
}
{
}
void
parseRaw
(
const
char
*
str
,
size_t
len
);
void
parseRaw
(
const
char
*
str
,
size_t
len
);
void
write
(
std
::
ostream
&
os
)
const
;
void
write
(
std
::
ostream
&
os
)
const
override
;
ConnectionControl
control
()
const
{
return
control_
;
}
ConnectionControl
control
()
const
{
return
control_
;
}
...
@@ -331,7 +331,7 @@ public:
...
@@ -331,7 +331,7 @@ public:
{
}
{
}
void
parseRaw
(
const
char
*
str
,
size_t
len
);
void
parseRaw
(
const
char
*
str
,
size_t
len
);
void
write
(
std
::
ostream
&
os
)
const
;
void
write
(
std
::
ostream
&
os
)
const
override
;
Encoding
encoding
()
const
{
Encoding
encoding
()
const
{
return
encoding_
;
return
encoding_
;
...
@@ -384,8 +384,8 @@ public:
...
@@ -384,8 +384,8 @@ public:
:
value_
(
val
)
:
value_
(
val
)
{
}
{
}
void
parse
(
const
std
::
string
&
data
);
void
parse
(
const
std
::
string
&
data
)
override
;
void
write
(
std
::
ostream
&
os
)
const
;
void
write
(
std
::
ostream
&
os
)
const
override
;
uint64_t
value
()
const
{
return
value_
;
}
uint64_t
value
()
const
{
return
value_
;
}
...
@@ -406,7 +406,7 @@ public:
...
@@ -406,7 +406,7 @@ public:
{
}
{
}
void
parseRaw
(
const
char
*
str
,
size_t
len
);
void
parseRaw
(
const
char
*
str
,
size_t
len
);
void
write
(
std
::
ostream
&
os
)
const
;
void
write
(
std
::
ostream
&
os
)
const
override
;
Mime
::
MediaType
mime
()
const
{
return
mime_
;
}
Mime
::
MediaType
mime
()
const
{
return
mime_
;
}
void
setMime
(
const
Mime
::
MediaType
&
mime
)
{
mime_
=
mime
;
}
void
setMime
(
const
Mime
::
MediaType
&
mime
)
{
mime_
=
mime
;
}
...
@@ -428,8 +428,8 @@ public:
...
@@ -428,8 +428,8 @@ public:
:
fullDate_
(
date
)
:
fullDate_
(
date
)
{
}
{
}
void
parse
(
const
std
::
string
&
str
)
;
void
parse
(
const
std
::
string
&
data
)
override
;
void
write
(
std
::
ostream
&
os
)
const
;
void
write
(
std
::
ostream
&
os
)
const
override
;
FullDate
fullDate
()
const
{
return
fullDate_
;
}
FullDate
fullDate
()
const
{
return
fullDate_
;
}
...
@@ -450,7 +450,7 @@ public:
...
@@ -450,7 +450,7 @@ public:
{
}
{
}
void
parseRaw
(
const
char
*
str
,
size_t
len
);
void
parseRaw
(
const
char
*
str
,
size_t
len
);
void
write
(
std
::
ostream
&
os
)
const
;
void
write
(
std
::
ostream
&
os
)
const
override
;
Http
::
Expectation
expectation
()
const
{
return
expectation_
;
}
Http
::
Expectation
expectation
()
const
{
return
expectation_
;
}
...
@@ -473,8 +473,8 @@ public:
...
@@ -473,8 +473,8 @@ public:
,
port_
(
port
)
,
port_
(
port
)
{
}
{
}
void
parse
(
const
std
::
string
&
data
);
void
parse
(
const
std
::
string
&
data
)
override
;
void
write
(
std
::
ostream
&
os
)
const
;
void
write
(
std
::
ostream
&
os
)
const
override
;
std
::
string
host
()
const
{
return
host_
;
}
std
::
string
host
()
const
{
return
host_
;
}
Port
port
()
const
{
return
port_
;
}
Port
port
()
const
{
return
port_
;
}
...
@@ -494,8 +494,8 @@ public:
...
@@ -494,8 +494,8 @@ public:
explicit
Location
(
const
std
::
string
&
location
);
explicit
Location
(
const
std
::
string
&
location
);
void
parse
(
const
std
::
string
&
data
);
void
parse
(
const
std
::
string
&
data
)
override
;
void
write
(
std
::
ostream
&
os
)
const
;
void
write
(
std
::
ostream
&
os
)
const
override
;
std
::
string
location
()
const
{
return
location_
;
}
std
::
string
location
()
const
{
return
location_
;
}
...
@@ -515,8 +515,8 @@ public:
...
@@ -515,8 +515,8 @@ public:
explicit
Server
(
const
std
::
string
&
token
);
explicit
Server
(
const
std
::
string
&
token
);
explicit
Server
(
const
char
*
token
);
explicit
Server
(
const
char
*
token
);
void
parse
(
const
std
::
string
&
data
);
void
parse
(
const
std
::
string
&
data
)
override
;
void
write
(
std
::
ostream
&
os
)
const
;
void
write
(
std
::
ostream
&
os
)
const
override
;
std
::
vector
<
std
::
string
>
tokens
()
const
{
return
tokens_
;
}
std
::
vector
<
std
::
string
>
tokens
()
const
{
return
tokens_
;
}
private:
private:
...
@@ -539,8 +539,8 @@ public:
...
@@ -539,8 +539,8 @@ public:
ua_
(
ua
)
ua_
(
ua
)
{
}
{
}
void
parse
(
const
std
::
string
&
data
);
void
parse
(
const
std
::
string
&
data
)
override
;
void
write
(
std
::
ostream
&
os
)
const
;
void
write
(
std
::
ostream
&
os
)
const
override
;
void
setAgent
(
std
::
string
ua
)
{
void
setAgent
(
std
::
string
ua
)
{
ua_
=
std
::
move
(
ua
);
ua_
=
std
::
move
(
ua
);
...
...
include/pistache/http_headers.h
View file @
f7c9715d
...
@@ -160,7 +160,7 @@ private:
...
@@ -160,7 +160,7 @@ private:
LowercaseHash
,
LowercaseHash
,
LowercaseEqual
>
;
LowercaseEqual
>
;
void
registerHeader
(
std
::
string
name
,
RegistryFunc
func
);
void
registerHeader
(
const
std
::
string
&
name
,
RegistryFunc
func
);
RegistryStorageType
registry
;
RegistryStorageType
registry
;
};
};
...
...
src/common/http_headers.cc
View file @
f7c9715d
...
@@ -4,12 +4,13 @@
...
@@ -4,12 +4,13 @@
Headers registry
Headers registry
*/
*/
#include <unordered_map>
#include <iterator>
#include <stdexcept>
#include <pistache/http_headers.h>
#include <pistache/http_headers.h>
#include <memory>
#include <stdexcept>
#include <unordered_map>
#include <vector>
namespace
Pistache
{
namespace
Pistache
{
namespace
Http
{
namespace
Http
{
namespace
Header
{
namespace
Header
{
...
@@ -52,7 +53,7 @@ Registry::~Registry()
...
@@ -52,7 +53,7 @@ Registry::~Registry()
{}
{}
void
void
Registry
::
registerHeader
(
std
::
string
name
,
Registry
::
RegistryFunc
func
)
Registry
::
registerHeader
(
const
std
::
string
&
name
,
Registry
::
RegistryFunc
func
)
{
{
auto
it
=
registry
.
find
(
name
);
auto
it
=
registry
.
find
(
name
);
if
(
it
!=
std
::
end
(
registry
))
{
if
(
it
!=
std
::
end
(
registry
))
{
...
...
tests/headers_test.cc
View file @
f7c9715d
#include "gtest/gtest.h"
#include <chrono>
#include <pistache/http_headers.h>
#include <pistache/http_headers.h>
#include <pistache/date.h>
#include <pistache/date.h>
#include "gtest/gtest.h"
#include <algorithm>
#include <chrono>
using
namespace
Pistache
::
Http
;
using
namespace
Pistache
::
Http
;
class
TestHeader
:
public
Header
::
Header
{
public:
NAME
(
"TestHeader"
);
void
write
(
std
::
ostream
&
os
)
const
override
{
os
<<
"TestHeader"
;
}
};
TEST
(
headers_test
,
accept
)
{
TEST
(
headers_test
,
accept
)
{
Header
::
Accept
a1
;
Header
::
Accept
a1
;
a1
.
parse
(
"audio/*; q=0.2"
);
a1
.
parse
(
"audio/*; q=0.2"
);
...
@@ -302,3 +313,16 @@ TEST(headers_test, access_control_allow_methods_test)
...
@@ -302,3 +313,16 @@ TEST(headers_test, access_control_allow_methods_test)
allowMethods
.
parse
(
"GET, POST, DELETE"
);
allowMethods
.
parse
(
"GET, POST, DELETE"
);
ASSERT_EQ
(
allowMethods
.
val
(),
"GET, POST, DELETE"
);
ASSERT_EQ
(
allowMethods
.
val
(),
"GET, POST, DELETE"
);
}
}
TEST
(
headers_test
,
add_new_header_test
)
{
const
std
::
string
headerName
=
"TestHeader"
;
ASSERT_FALSE
(
Header
::
Registry
::
instance
().
isRegistered
(
headerName
));
Header
::
Registry
::
instance
().
registerHeader
<
TestHeader
>
();
ASSERT_TRUE
(
Header
::
Registry
::
instance
().
isRegistered
(
headerName
));
const
auto
&
headersList
=
Header
::
Registry
::
instance
().
headersList
();
const
bool
isFound
=
std
::
find
(
headersList
.
begin
(),
headersList
.
end
(),
headerName
)
!=
headersList
.
end
();
ASSERT_TRUE
(
isFound
);
}
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