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
ef8a6a49
Commit
ef8a6a49
authored
Sep 09, 2015
by
Mathieu Stefani
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Experimenting with SSO-based string implementation
parent
79c71831
Changes
6
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
76 additions
and
45 deletions
+76
-45
main.cc
main.cc
+1
-1
src/http.cc
src/http.cc
+3
-2
src/http_header.cc
src/http_header.cc
+15
-7
src/http_header.h
src/http_header.h
+25
-4
src/http_headers.cc
src/http_headers.cc
+17
-16
src/http_headers.h
src/http_headers.h
+15
-15
No files found.
main.cc
View file @
ef8a6a49
...
@@ -15,7 +15,7 @@ class MyHandler : public Net::Http::Handler {
...
@@ -15,7 +15,7 @@ class MyHandler : public Net::Http::Handler {
using
namespace
Net
::
Http
;
using
namespace
Net
::
Http
;
Net
::
Http
::
Response
response
(
Net
::
Http
::
Code
::
Ok
,
"PONG"
);
Net
::
Http
::
Response
response
(
Net
::
Http
::
Code
::
Ok
,
"PONG"
);
#if
0
#if
1
response
.
headers
response
.
headers
.
add
(
make_header
<
Header
::
ContentEncoding
>
(
Header
::
Encoding
::
Gzip
))
.
add
(
make_header
<
Header
::
ContentEncoding
>
(
Header
::
Encoding
::
Gzip
))
.
add
(
make_header
<
Header
::
ContentType
>
(
MIME
(
Text
,
Plain
)));
.
add
(
make_header
<
Header
::
ContentType
>
(
MIME
(
Text
,
Plain
)));
...
...
src/http.cc
View file @
ef8a6a49
...
@@ -218,7 +218,7 @@ namespace Private {
...
@@ -218,7 +218,7 @@ namespace Private {
// Skip the ':'
// Skip the ':'
if
(
!
cursor
.
advance
(
1
))
return
State
::
Again
;
if
(
!
cursor
.
advance
(
1
))
return
State
::
Again
;
std
::
string
name
=
std
::
string
(
cursor
.
offset
(
start
),
cursor
.
diff
(
start
)
-
1
);
Header
::
string
name
=
Header
::
string
(
cursor
.
offset
(
start
),
cursor
.
diff
(
start
)
-
1
);
// Ignore spaces
// Ignore spaces
while
(
cursor
.
current
()
==
' '
)
while
(
cursor
.
current
()
==
' '
)
...
@@ -236,8 +236,9 @@ namespace Private {
...
@@ -236,8 +236,9 @@ namespace Private {
request
->
headers
.
add
(
std
::
move
(
header
));
request
->
headers
.
add
(
std
::
move
(
header
));
}
}
else
{
else
{
cout
<<
"La chouma c'est qui ce con "
<<
name
<<
endl
;
std
::
string
value
(
cursor
.
offset
(
start
),
cursor
.
diff
(
start
));
std
::
string
value
(
cursor
.
offset
(
start
),
cursor
.
diff
(
start
));
request
->
headers
.
addRaw
(
Header
::
Raw
(
std
::
move
(
name
),
std
::
move
(
value
)));
//
request->headers.addRaw(Header::Raw(std::move(name), std::move(value)));
}
}
// CRLF
// CRLF
...
...
src/http_header.cc
View file @
ef8a6a49
...
@@ -243,6 +243,13 @@ CacheControl::addDirectives(const std::vector<Http::CacheDirective>& directives)
...
@@ -243,6 +243,13 @@ CacheControl::addDirectives(const std::vector<Http::CacheDirective>& directives)
std
::
copy
(
std
::
begin
(
directives
),
std
::
end
(
directives
),
std
::
back_inserter
(
directives_
));
std
::
copy
(
std
::
begin
(
directives
),
std
::
end
(
directives
),
std
::
back_inserter
(
directives_
));
}
}
void
Connection
::
parseRaw
(
const
char
*
str
,
size_t
len
)
{
}
void
Connection
::
write
(
std
::
ostream
&
os
)
const
{
}
void
void
ContentLength
::
parse
(
const
std
::
string
&
data
)
{
ContentLength
::
parse
(
const
std
::
string
&
data
)
{
try
{
try
{
...
@@ -271,16 +278,17 @@ Date::write(std::ostream& os) const {
...
@@ -271,16 +278,17 @@ Date::write(std::ostream& os) const {
}
}
void
void
Host
::
parse
(
const
std
::
string
&
data
)
{
Host
::
parseRaw
(
const
char
*
str
,
size_t
size
)
auto
pos
=
data
.
find
(
':'
);
{
if
(
pos
!=
std
::
string
::
npos
)
{
const
char
*
pos
=
static_cast
<
const
char
*>
(
memchr
(
str
,
':'
,
size
));
std
::
string
h
=
data
.
substr
(
0
,
pos
);
if
(
pos
!=
nullptr
)
{
int16_t
p
=
std
::
stoi
(
data
.
substr
(
pos
+
1
));
string
h
=
string
(
str
,
pos
-
str
);
int16_t
p
=
80
;
host_
=
h
;
host_
=
std
::
move
(
h
)
;
port_
=
p
;
port_
=
p
;
}
else
{
}
else
{
host_
=
data
;
host_
=
string
(
str
,
size
)
;
port_
=
80
;
port_
=
80
;
}
}
}
}
...
...
src/http_header.h
View file @
ef8a6a49
...
@@ -6,6 +6,8 @@
...
@@ -6,6 +6,8 @@
#pragma once
#pragma once
#define USE_SSO_STRING
#include "mime.h"
#include "mime.h"
#include "net.h"
#include "net.h"
#include "http_defs.h"
#include "http_defs.h"
...
@@ -14,6 +16,9 @@
...
@@ -14,6 +16,9 @@
#include <memory>
#include <memory>
#include <ostream>
#include <ostream>
#include <vector>
#include <vector>
#ifdef USE_SSO_STRING
#include <ext/vstring.h>
#endif
#define SAFE_HEADER_CAST
#define SAFE_HEADER_CAST
...
@@ -23,6 +28,12 @@ namespace Http {
...
@@ -23,6 +28,12 @@ namespace Http {
namespace
Header
{
namespace
Header
{
#ifdef USE_SSO_STRING
typedef
__gnu_cxx
::
__vstring
string
;
#else
typedef
std
::
string
string
;
#endif
#ifdef SAFE_HEADER_CAST
#ifdef SAFE_HEADER_CAST
namespace
detail
{
namespace
detail
{
...
@@ -180,6 +191,16 @@ private:
...
@@ -180,6 +191,16 @@ private:
std
::
vector
<
Http
::
CacheDirective
>
directives_
;
std
::
vector
<
Http
::
CacheDirective
>
directives_
;
};
};
class
Connection
:
public
Header
{
public:
NAME
(
"Connection"
)
Connection
()
{
};
void
parseRaw
(
const
char
*
str
,
size_t
len
);
void
write
(
std
::
ostream
&
os
)
const
;
};
class
ContentEncoding
:
public
Header
{
class
ContentEncoding
:
public
Header
{
public:
public:
...
@@ -272,19 +293,19 @@ public:
...
@@ -272,19 +293,19 @@ public:
,
port_
(
-
1
)
,
port_
(
-
1
)
{
}
{
}
explicit
Host
(
const
st
d
::
st
ring
&
host
,
Net
::
Port
port
=
80
)
explicit
Host
(
const
string
&
host
,
Net
::
Port
port
=
80
)
:
host_
(
host
)
:
host_
(
host
)
,
port_
(
port
)
,
port_
(
port
)
{
}
{
}
void
parse
(
const
std
::
string
&
data
);
void
parse
Raw
(
const
char
*
str
,
size_t
size
);
void
write
(
std
::
ostream
&
os
)
const
;
void
write
(
std
::
ostream
&
os
)
const
;
st
d
::
st
ring
host
()
const
{
return
host_
;
}
string
host
()
const
{
return
host_
;
}
Net
::
Port
port
()
const
{
return
port_
;
}
Net
::
Port
port
()
const
{
return
port_
;
}
private:
private:
st
d
::
st
ring
host_
;
string
host_
;
Net
::
Port
port_
;
Net
::
Port
port_
;
};
};
...
...
src/http_headers.cc
View file @
ef8a6a49
...
@@ -29,13 +29,13 @@ namespace {
...
@@ -29,13 +29,13 @@ namespace {
return
tid
;
return
tid
;
}
}
std
::
unordered_map
<
st
d
::
st
ring
,
std
::
unique_ptr
<
AllocatorBase
>>
allocators
;
std
::
unordered_map
<
string
,
std
::
unique_ptr
<
AllocatorBase
>>
allocators
;
}
}
namespace
detail
{
namespace
detail
{
Header
*
Header
*
allocate_header
(
const
st
d
::
st
ring
&
name
)
{
allocate_header
(
const
string
&
name
)
{
auto
it
=
allocators
.
find
(
name
);
auto
it
=
allocators
.
find
(
name
);
if
(
it
==
std
::
end
(
allocators
))
{
if
(
it
==
std
::
end
(
allocators
))
{
throw
std
::
bad_alloc
();
throw
std
::
bad_alloc
();
...
@@ -54,6 +54,7 @@ header_delete::operator()(Header* header) {
...
@@ -54,6 +54,7 @@ header_delete::operator()(Header* header) {
RegisterHeader
(
Accept
);
RegisterHeader
(
Accept
);
RegisterHeader
(
CacheControl
);
RegisterHeader
(
CacheControl
);
RegisterHeader
(
Connection
);
RegisterHeader
(
ContentEncoding
);
RegisterHeader
(
ContentEncoding
);
RegisterHeader
(
ContentLength
);
RegisterHeader
(
ContentLength
);
RegisterHeader
(
ContentType
);
RegisterHeader
(
ContentType
);
...
@@ -63,14 +64,14 @@ RegisterHeader(Server);
...
@@ -63,14 +64,14 @@ RegisterHeader(Server);
RegisterHeader
(
UserAgent
);
RegisterHeader
(
UserAgent
);
void
void
Registry
::
registerHeader
(
st
d
::
st
ring
name
,
std
::
unique_ptr
<
AllocatorBase
>&&
alloc
)
Registry
::
registerHeader
(
string
name
,
std
::
unique_ptr
<
AllocatorBase
>&&
alloc
)
{
{
allocators
.
insert
(
std
::
make_pair
(
name
,
std
::
move
(
alloc
)));
allocators
.
insert
(
std
::
make_pair
(
name
,
std
::
move
(
alloc
)));
}
}
std
::
vector
<
st
d
::
st
ring
>
std
::
vector
<
string
>
Registry
::
headersList
()
{
Registry
::
headersList
()
{
std
::
vector
<
st
d
::
st
ring
>
names
;
std
::
vector
<
string
>
names
;
names
.
reserve
(
allocators
.
size
());
names
.
reserve
(
allocators
.
size
());
for
(
const
auto
&
header
:
allocators
)
{
for
(
const
auto
&
header
:
allocators
)
{
...
@@ -81,7 +82,7 @@ Registry::headersList() {
...
@@ -81,7 +82,7 @@ Registry::headersList() {
}
}
std
::
unique_ptr
<
Header
,
header_delete
>
std
::
unique_ptr
<
Header
,
header_delete
>
Registry
::
makeHeader
(
const
st
d
::
st
ring
&
name
)
{
Registry
::
makeHeader
(
const
string
&
name
)
{
auto
it
=
allocators
.
find
(
name
);
auto
it
=
allocators
.
find
(
name
);
if
(
it
==
std
::
end
(
allocators
))
{
if
(
it
==
std
::
end
(
allocators
))
{
throw
std
::
bad_alloc
();
throw
std
::
bad_alloc
();
...
@@ -91,7 +92,7 @@ Registry::makeHeader(const std::string& name) {
...
@@ -91,7 +92,7 @@ Registry::makeHeader(const std::string& name) {
}
}
bool
bool
Registry
::
isRegistered
(
const
st
d
::
st
ring
&
name
)
{
Registry
::
isRegistered
(
const
string
&
name
)
{
auto
it
=
allocators
.
find
(
name
);
auto
it
=
allocators
.
find
(
name
);
return
it
!=
std
::
end
(
allocators
);
return
it
!=
std
::
end
(
allocators
);
}
}
...
@@ -111,11 +112,11 @@ Collection::add(std::shared_ptr<Header>&& header) {
...
@@ -111,11 +112,11 @@ Collection::add(std::shared_ptr<Header>&& header) {
Collection
&
Collection
&
Collection
::
addRaw
(
const
Raw
&
raw
)
{
Collection
::
addRaw
(
const
Raw
&
raw
)
{
rawHeaders
.
insert
(
std
::
make_pair
(
raw
.
name
(),
raw
));
//
rawHeaders.insert(std::make_pair(raw.name(), raw));
}
}
std
::
shared_ptr
<
const
Header
>
std
::
shared_ptr
<
const
Header
>
Collection
::
get
(
const
st
d
::
st
ring
&
name
)
const
{
Collection
::
get
(
const
string
&
name
)
const
{
auto
header
=
getImpl
(
name
);
auto
header
=
getImpl
(
name
);
if
(
!
header
.
first
)
{
if
(
!
header
.
first
)
{
throw
std
::
runtime_error
(
"Could not find header"
);
throw
std
::
runtime_error
(
"Could not find header"
);
...
@@ -125,7 +126,7 @@ Collection::get(const std::string& name) const {
...
@@ -125,7 +126,7 @@ Collection::get(const std::string& name) const {
}
}
std
::
shared_ptr
<
Header
>
std
::
shared_ptr
<
Header
>
Collection
::
get
(
const
st
d
::
st
ring
&
name
)
{
Collection
::
get
(
const
string
&
name
)
{
auto
header
=
getImpl
(
name
);
auto
header
=
getImpl
(
name
);
if
(
!
header
.
first
)
{
if
(
!
header
.
first
)
{
throw
std
::
runtime_error
(
"Could not find header"
);
throw
std
::
runtime_error
(
"Could not find header"
);
...
@@ -135,7 +136,7 @@ Collection::get(const std::string& name) {
...
@@ -135,7 +136,7 @@ Collection::get(const std::string& name) {
}
}
Raw
Raw
Collection
::
getRaw
(
const
st
d
::
st
ring
&
name
)
const
{
Collection
::
getRaw
(
const
string
&
name
)
const
{
auto
it
=
rawHeaders
.
find
(
name
);
auto
it
=
rawHeaders
.
find
(
name
);
if
(
it
==
std
::
end
(
rawHeaders
))
{
if
(
it
==
std
::
end
(
rawHeaders
))
{
throw
std
::
runtime_error
(
"Could not find header"
);
throw
std
::
runtime_error
(
"Could not find header"
);
...
@@ -145,7 +146,7 @@ Collection::getRaw(const std::string& name) const {
...
@@ -145,7 +146,7 @@ Collection::getRaw(const std::string& name) const {
}
}
std
::
shared_ptr
<
const
Header
>
std
::
shared_ptr
<
const
Header
>
Collection
::
tryGet
(
const
st
d
::
st
ring
&
name
)
const
{
Collection
::
tryGet
(
const
string
&
name
)
const
{
auto
header
=
getImpl
(
name
);
auto
header
=
getImpl
(
name
);
if
(
!
header
.
first
)
return
nullptr
;
if
(
!
header
.
first
)
return
nullptr
;
...
@@ -153,7 +154,7 @@ Collection::tryGet(const std::string& name) const {
...
@@ -153,7 +154,7 @@ Collection::tryGet(const std::string& name) const {
}
}
std
::
shared_ptr
<
Header
>
std
::
shared_ptr
<
Header
>
Collection
::
tryGet
(
const
st
d
::
st
ring
&
name
)
{
Collection
::
tryGet
(
const
string
&
name
)
{
auto
header
=
getImpl
(
name
);
auto
header
=
getImpl
(
name
);
if
(
!
header
.
first
)
return
nullptr
;
if
(
!
header
.
first
)
return
nullptr
;
...
@@ -161,7 +162,7 @@ Collection::tryGet(const std::string& name) {
...
@@ -161,7 +162,7 @@ Collection::tryGet(const std::string& name) {
}
}
Optional
<
Raw
>
Optional
<
Raw
>
Collection
::
tryGetRaw
(
const
st
d
::
st
ring
&
name
)
const
{
Collection
::
tryGetRaw
(
const
string
&
name
)
const
{
auto
it
=
rawHeaders
.
find
(
name
);
auto
it
=
rawHeaders
.
find
(
name
);
if
(
it
==
std
::
end
(
rawHeaders
))
{
if
(
it
==
std
::
end
(
rawHeaders
))
{
return
None
();
return
None
();
...
@@ -171,7 +172,7 @@ Collection::tryGetRaw(const std::string& name) const {
...
@@ -171,7 +172,7 @@ Collection::tryGetRaw(const std::string& name) const {
}
}
bool
bool
Collection
::
has
(
const
st
d
::
st
ring
&
name
)
const
{
Collection
::
has
(
const
string
&
name
)
const
{
return
getImpl
(
name
).
first
;
return
getImpl
(
name
).
first
;
}
}
...
@@ -193,7 +194,7 @@ Collection::clear() {
...
@@ -193,7 +194,7 @@ Collection::clear() {
}
}
std
::
pair
<
bool
,
std
::
shared_ptr
<
Header
>>
std
::
pair
<
bool
,
std
::
shared_ptr
<
Header
>>
Collection
::
getImpl
(
const
st
d
::
st
ring
&
name
)
const
{
Collection
::
getImpl
(
const
string
&
name
)
const
{
auto
it
=
headers
.
find
(
name
);
auto
it
=
headers
.
find
(
name
);
if
(
it
==
std
::
end
(
headers
))
{
if
(
it
==
std
::
end
(
headers
))
{
return
std
::
make_pair
(
false
,
nullptr
);
return
std
::
make_pair
(
false
,
nullptr
);
...
...
src/http_headers.h
View file @
ef8a6a49
...
@@ -57,13 +57,13 @@ public:
...
@@ -57,13 +57,13 @@ public:
Collection
&
add
(
std
::
shared_ptr
<
Header
>&&
header
);
Collection
&
add
(
std
::
shared_ptr
<
Header
>&&
header
);
Collection
&
addRaw
(
const
Raw
&
raw
);
Collection
&
addRaw
(
const
Raw
&
raw
);
std
::
shared_ptr
<
const
Header
>
get
(
const
st
d
::
st
ring
&
name
)
const
;
std
::
shared_ptr
<
const
Header
>
get
(
const
string
&
name
)
const
;
std
::
shared_ptr
<
Header
>
get
(
const
st
d
::
st
ring
&
name
);
std
::
shared_ptr
<
Header
>
get
(
const
string
&
name
);
Raw
getRaw
(
const
st
d
::
st
ring
&
name
)
const
;
Raw
getRaw
(
const
string
&
name
)
const
;
std
::
shared_ptr
<
const
Header
>
tryGet
(
const
st
d
::
st
ring
&
name
)
const
;
std
::
shared_ptr
<
const
Header
>
tryGet
(
const
string
&
name
)
const
;
std
::
shared_ptr
<
Header
>
tryGet
(
const
st
d
::
st
ring
&
name
);
std
::
shared_ptr
<
Header
>
tryGet
(
const
string
&
name
);
Optional
<
Raw
>
tryGetRaw
(
const
st
d
::
st
ring
&
name
)
const
;
Optional
<
Raw
>
tryGetRaw
(
const
string
&
name
)
const
;
template
<
typename
H
>
template
<
typename
H
>
typename
std
::
enable_if
<
typename
std
::
enable_if
<
...
@@ -72,17 +72,17 @@ public:
...
@@ -72,17 +72,17 @@ public:
has
()
const
{
has
()
const
{
return
has
(
H
::
Name
);
return
has
(
H
::
Name
);
}
}
bool
has
(
const
st
d
::
st
ring
&
name
)
const
;
bool
has
(
const
string
&
name
)
const
;
std
::
vector
<
std
::
shared_ptr
<
Header
>>
list
()
const
;
std
::
vector
<
std
::
shared_ptr
<
Header
>>
list
()
const
;
void
clear
();
void
clear
();
private:
private:
std
::
pair
<
bool
,
std
::
shared_ptr
<
Header
>>
getImpl
(
const
st
d
::
st
ring
&
name
)
const
;
std
::
pair
<
bool
,
std
::
shared_ptr
<
Header
>>
getImpl
(
const
string
&
name
)
const
;
std
::
unordered_map
<
st
d
::
st
ring
,
std
::
shared_ptr
<
Header
>>
headers
;
std
::
unordered_map
<
string
,
std
::
shared_ptr
<
Header
>>
headers
;
std
::
unordered_map
<
st
d
::
st
ring
,
Raw
>
rawHeaders
;
std
::
unordered_map
<
string
,
Raw
>
rawHeaders
;
};
};
struct
header_delete
{
struct
header_delete
{
...
@@ -157,12 +157,12 @@ struct Registry {
...
@@ -157,12 +157,12 @@ struct Registry {
registerHeader
(
H
::
Name
,
std
::
move
(
alloc
));
registerHeader
(
H
::
Name
,
std
::
move
(
alloc
));
}
}
static
void
registerHeader
(
st
d
::
st
ring
name
,
std
::
unique_ptr
<
AllocatorBase
>&&
alloc
);
static
void
registerHeader
(
string
name
,
std
::
unique_ptr
<
AllocatorBase
>&&
alloc
);
static
std
::
vector
<
st
d
::
st
ring
>
headersList
();
static
std
::
vector
<
string
>
headersList
();
static
std
::
unique_ptr
<
Header
,
header_delete
>
makeHeader
(
const
st
d
::
st
ring
&
name
);
static
std
::
unique_ptr
<
Header
,
header_delete
>
makeHeader
(
const
string
&
name
);
static
bool
isRegistered
(
const
st
d
::
st
ring
&
name
);
static
bool
isRegistered
(
const
string
&
name
);
};
};
template
<
typename
H
>
template
<
typename
H
>
...
@@ -175,7 +175,7 @@ struct Registrar {
...
@@ -175,7 +175,7 @@ struct Registrar {
};
};
namespace
detail
{
namespace
detail
{
Header
*
allocate_header
(
const
st
d
::
st
ring
&
name
);
Header
*
allocate_header
(
const
string
&
name
);
}
}
/* Crazy macro machinery to generate a unique variable name
/* Crazy macro machinery to generate a unique variable name
...
...
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