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
0ab17b40
Commit
0ab17b40
authored
Sep 02, 2015
by
Mathieu STEFANI
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Played with macros for a more convenient header registration system
parent
5cb7c67f
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
28 additions
and
13 deletions
+28
-13
src/http_headers.cc
src/http_headers.cc
+7
-13
src/http_headers.h
src/http_headers.h
+21
-0
No files found.
src/http_headers.cc
View file @
0ab17b40
...
@@ -20,6 +20,13 @@ namespace {
...
@@ -20,6 +20,13 @@ namespace {
std
::
unordered_map
<
std
::
string
,
Registry
::
RegistryFunc
>
registry
;
std
::
unordered_map
<
std
::
string
,
Registry
::
RegistryFunc
>
registry
;
}
}
RegisterHeader
(
Accept
);
RegisterHeader
(
ContentLength
);
RegisterHeader
(
ContentType
);
RegisterHeader
(
Host
);
RegisterHeader
(
ContentEncoding
);
RegisterHeader
(
UserAgent
);
void
void
Registry
::
registerHeader
(
std
::
string
name
,
Registry
::
RegistryFunc
func
)
Registry
::
registerHeader
(
std
::
string
name
,
Registry
::
RegistryFunc
func
)
{
{
...
@@ -133,19 +140,6 @@ Collection::getImpl(const std::string& name) const {
...
@@ -133,19 +140,6 @@ Collection::getImpl(const std::string& name) const {
return
std
::
make_pair
(
true
,
it
->
second
);
return
std
::
make_pair
(
true
,
it
->
second
);
}
}
namespace
{
struct
AtInit
{
AtInit
()
{
Registry
::
registerHeader
<
ContentLength
>
();
Registry
::
registerHeader
<
ContentType
>
();
Registry
::
registerHeader
<
Host
>
();
Registry
::
registerHeader
<
Accept
>
();
Registry
::
registerHeader
<
UserAgent
>
();
Registry
::
registerHeader
<
ContentEncoding
>
();
}
}
atInit
;
}
}
// namespace Header
}
// namespace Header
}
// namespace Http
}
// namespace Http
...
...
src/http_headers.h
View file @
0ab17b40
...
@@ -101,6 +101,27 @@ struct Registry {
...
@@ -101,6 +101,27 @@ struct Registry {
static
bool
isRegistered
(
const
std
::
string
&
name
);
static
bool
isRegistered
(
const
std
::
string
&
name
);
};
};
template
<
typename
H
>
struct
Registrar
{
static_assert
(
IsHeader
<
H
>::
value
,
"Registrar only works with header types"
);
Registrar
()
{
Registry
::
registerHeader
<
H
>
();
}
};
/* Crazy macro machinery to generate a unique variable name
* Don't touch it !
*/
#define CAT(a, b) CAT_I(a, b)
#define CAT_I(a, b) a ## b
#define UNIQUE_NAME(base) CAT(base, __LINE__)
#define RegisterHeader(Header) \
Registrar<Header> UNIQUE_NAME(CAT(CAT_I(__, Header), __))
}
// namespace Header
}
// namespace Header
}
// namespace Http
}
// namespace Http
...
...
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