Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
OpenDAS
dlib
Commits
4cc14d26
Commit
4cc14d26
authored
Aug 07, 2013
by
Davis King
Browse files
Added Steven Van Ingelgem's patch to the HTTP server which makes
operations on HTTP headers case-insensitive.
parent
9fa2cc57
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
51 additions
and
21 deletions
+51
-21
dlib/server/server_http.cpp
dlib/server/server_http.cpp
+4
-4
dlib/server/server_http.h
dlib/server/server_http.h
+31
-6
dlib/server/server_http_abstract.h
dlib/server/server_http_abstract.h
+16
-11
No files found.
dlib/server/server_http.cpp
View file @
4cc14d26
...
...
@@ -175,7 +175,7 @@ namespace dlib
// Get the HTTP/1.1 - Ignore for now...
read_with_limit
(
in
,
incoming
.
protocol
);
key_value_map
&
incoming_headers
=
incoming
.
headers
;
key_value_map
_ci
&
incoming_headers
=
incoming
.
headers
;
key_value_map
&
cookies
=
incoming
.
cookies
;
std
::
string
&
path
=
incoming
.
path
;
std
::
string
&
content_type
=
incoming
.
content_type
;
...
...
@@ -333,11 +333,11 @@ namespace dlib
{
using
namespace
http_impl
;
key_value_map
&
new_cookies
=
outgoing
.
cookies
;
key_value_map
&
response_headers
=
outgoing
.
headers
;
key_value_map
_ci
&
response_headers
=
outgoing
.
headers
;
// only send this header if the user hasn't told us to send another kind
bool
has_content_type
=
false
,
has_location
=
false
;
for
(
key_value_map
::
const_iterator
ci
=
response_headers
.
begin
();
ci
!=
response_headers
.
end
();
++
ci
)
for
(
key_value_map
_ci
::
const_iterator
ci
=
response_headers
.
begin
();
ci
!=
response_headers
.
end
();
++
ci
)
{
if
(
!
has_content_type
&&
strings_equal_ignore_case
(
ci
->
first
,
"content-type"
)
)
{
...
...
@@ -364,7 +364,7 @@ namespace dlib
out
<<
"HTTP/1.0 "
<<
outgoing
.
http_return
<<
" "
<<
outgoing
.
http_return_status
<<
"
\r\n
"
;
// Set any new headers
for
(
key_value_map
::
const_iterator
ci
=
response_headers
.
begin
();
ci
!=
response_headers
.
end
();
++
ci
)
for
(
key_value_map
_ci
::
const_iterator
ci
=
response_headers
.
begin
();
ci
!=
response_headers
.
end
();
++
ci
)
{
out
<<
ci
->
first
<<
": "
<<
ci
->
second
<<
"
\r\n
"
;
}
...
...
dlib/server/server_http.h
View file @
4cc14d26
...
...
@@ -8,6 +8,7 @@
#include <iostream>
#include <sstream>
#include <string>
#include <cctype>
#include <map>
#include "../logger.h"
#include "../string.h"
...
...
@@ -39,15 +40,15 @@ namespace dlib
// ----------------------------------------------------------------------------------------
template
<
typename
Key
,
typename
Value
>
class
constmap
:
public
std
::
map
<
Key
,
Value
>
template
<
typename
Key
,
typename
Value
,
typename
Comparer
=
std
::
less
<
Key
>
>
class
constmap
:
public
std
::
map
<
Key
,
Value
,
Comparer
>
{
public:
const
Value
&
operator
[](
const
Key
&
k
)
const
{
static
const
Value
dummy
=
Value
();
typename
std
::
map
<
Key
,
Value
>::
const_iterator
ci
=
std
::
map
<
Key
,
Value
>::
find
(
k
);
typename
std
::
map
<
Key
,
Value
,
Comparer
>::
const_iterator
ci
=
std
::
map
<
Key
,
Value
,
Comparer
>::
find
(
k
);
if
(
ci
==
this
->
end
()
)
return
dummy
;
...
...
@@ -57,10 +58,34 @@ namespace dlib
Value
&
operator
[](
const
Key
&
k
)
{
return
std
::
map
<
Key
,
Value
>::
operator
[](
k
);
return
std
::
map
<
Key
,
Value
,
Comparer
>::
operator
[](
k
);
}
};
class
less_case_insensitive
{
public:
bool
operator
()(
const
std
::
string
&
a
,
const
std
::
string
&
b
)
const
{
long
i
=
0
;
while
(
i
<
a
.
size
()
&&
i
<
b
.
size
())
{
const
int
cha
=
std
::
tolower
(
a
[
i
]);
const
int
chb
=
std
::
tolower
(
b
[
i
]);
if
(
cha
<
chb
)
return
true
;
else
if
(
cha
>
chb
)
return
false
;
++
i
;
}
if
(
a
.
size
()
<
b
.
size
())
return
true
;
else
return
false
;
}
};
typedef
constmap
<
std
::
string
,
std
::
string
,
less_case_insensitive
>
key_value_map_ci
;
typedef
constmap
<
std
::
string
,
std
::
string
>
key_value_map
;
struct
incoming_things
...
...
@@ -86,7 +111,7 @@ namespace dlib
key_value_map
queries
;
key_value_map
cookies
;
key_value_map
headers
;
key_value_map
_ci
headers
;
std
::
string
foreign_ip
;
unsigned
short
foreign_port
;
...
...
@@ -99,7 +124,7 @@ namespace dlib
outgoing_things
()
:
http_return
(
200
),
http_return_status
(
"OK"
)
{
}
key_value_map
cookies
;
key_value_map
headers
;
key_value_map
_ci
headers
;
unsigned
short
http_return
;
std
::
string
http_return_status
;
};
...
...
dlib/server/server_http_abstract.h
View file @
4cc14d26
...
...
@@ -15,9 +15,10 @@ namespace dlib
template
<
typename
Key
,
typename
Value
typename
Value
,
typename
Comparer
=
std
::
less
<
Key
>
>
class
constmap
:
public
std
::
map
<
Key
,
Value
>
class
constmap
:
public
std
::
map
<
Key
,
Value
,
Comparer
>
{
/*!
WHAT THIS OBJECT REPRESENTS
...
...
@@ -56,6 +57,10 @@ namespace dlib
};
typedef
constmap
<
std
::
string
,
std
::
string
>
key_value_map
;
// This version of key_value_map treats the key string as being case-insensitive.
// For example, a key string of "Content-Type" would access the same element as a key
// of "content-type".
typedef
constmap
<
std
::
string
,
std
::
string
,
less_case_insensitive
>
key_value_map_ci
;
// -----------------------------------------------------------------------------------------
...
...
@@ -92,7 +97,7 @@ namespace dlib
key_value_map
queries
;
key_value_map
cookies
;
key_value_map
headers
;
key_value_map
_ci
headers
;
std
::
string
foreign_ip
;
unsigned
short
foreign_port
;
...
...
@@ -120,7 +125,7 @@ namespace dlib
!*/
key_value_map
cookies
;
key_value_map
headers
;
key_value_map
_ci
headers
;
unsigned
short
http_return
;
std
::
string
http_return_status
;
};
...
...
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