Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
opendht
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Iterations
Code
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Locked files
Deploy
Model registry
Analyze
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
GitLab community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
savoirfairelinux
opendht
Commits
20df5fe8
Commit
20df5fe8
authored
5 years ago
by
Adrien Béraud
Browse files
Options
Downloads
Patches
Plain Diff
http: cleanup
parent
5b4f4022
No related branches found
No related tags found
No related merge requests found
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
include/opendht/http.h
+5
-5
5 additions, 5 deletions
include/opendht/http.h
src/http.cpp
+12
-13
12 additions, 13 deletions
src/http.cpp
with
17 additions
and
18 deletions
include/opendht/http.h
+
5
−
5
View file @
20df5fe8
...
@@ -158,7 +158,7 @@ public:
...
@@ -158,7 +158,7 @@ public:
void
add_callback
(
ResolverCb
cb
);
void
add_callback
(
ResolverCb
cb
);
private
:
private
:
void
resolve
(
const
std
::
string
host
,
const
std
::
string
service
);
void
resolve
(
const
std
::
string
&
host
,
const
std
::
string
&
service
);
std
::
mutex
mutex_
;
std
::
mutex
mutex_
;
...
@@ -223,10 +223,10 @@ public:
...
@@ -223,10 +223,10 @@ public:
*/
*/
void
set_header
(
const
restinio
::
http_request_header_t
header
);
void
set_header
(
const
restinio
::
http_request_header_t
header
);
void
set_method
(
const
restinio
::
http_method_id_t
method
);
void
set_method
(
const
restinio
::
http_method_id_t
method
);
void
set_target
(
const
std
::
string
target
);
void
set_target
(
std
::
string
target
);
void
set_header_field
(
const
restinio
::
http_field_t
field
,
const
std
::
string
&
value
);
void
set_header_field
(
const
restinio
::
http_field_t
field
,
std
::
string
value
);
void
set_connection_type
(
const
restinio
::
http_connection_header_t
connection
);
void
set_connection_type
(
const
restinio
::
http_connection_header_t
connection
);
void
set_body
(
const
std
::
string
&
body
);
void
set_body
(
std
::
string
body
);
void
add_on_status_callback
(
OnStatusCb
cb
);
void
add_on_status_callback
(
OnStatusCb
cb
);
void
add_on_body_callback
(
OnDataCb
cb
);
void
add_on_body_callback
(
OnDataCb
cb
);
...
@@ -281,7 +281,7 @@ private:
...
@@ -281,7 +281,7 @@ private:
* Return how many bytes were parsed.
* Return how many bytes were parsed.
* Note: we pass requerst.size()==0 to signal that EOF has been received.
* Note: we pass requerst.size()==0 to signal that EOF has been received.
*/
*/
size_t
parse_request
(
const
std
::
string
request
);
size_t
parse_request
(
const
std
::
string
&
request
);
restinio
::
http_request_header_t
header_
;
restinio
::
http_request_header_t
header_
;
std
::
map
<
restinio
::
http_field_t
,
std
::
string
>
headers_
;
std
::
map
<
restinio
::
http_field_t
,
std
::
string
>
headers_
;
...
...
This diff is collapsed.
Click to expand it.
src/http.cpp
+
12
−
13
View file @
20df5fe8
...
@@ -356,7 +356,7 @@ Resolver::add_callback(ResolverCb cb)
...
@@ -356,7 +356,7 @@ Resolver::add_callback(ResolverCb cb)
}
}
void
void
Resolver
::
resolve
(
const
std
::
string
host
,
const
std
::
string
service
)
Resolver
::
resolve
(
const
std
::
string
&
host
,
const
std
::
string
&
service
)
{
{
asio
::
ip
::
tcp
::
resolver
::
query
query_
(
host
,
service
);
asio
::
ip
::
tcp
::
resolver
::
query
query_
(
host
,
service
);
...
@@ -486,15 +486,15 @@ Request::set_method(const restinio::http_method_id_t method)
...
@@ -486,15 +486,15 @@ Request::set_method(const restinio::http_method_id_t method)
}
}
void
void
Request
::
set_target
(
const
std
::
string
target
)
Request
::
set_target
(
std
::
string
target
)
{
{
header_
.
request_target
(
target
);
header_
.
request_target
(
std
::
move
(
target
)
)
;
}
}
void
void
Request
::
set_header_field
(
const
restinio
::
http_field_t
field
,
const
std
::
string
&
value
)
Request
::
set_header_field
(
const
restinio
::
http_field_t
field
,
std
::
string
value
)
{
{
headers_
[
field
]
=
value
;
headers_
[
field
]
=
std
::
move
(
value
)
;
}
}
void
void
...
@@ -504,9 +504,9 @@ Request::set_connection_type(const restinio::http_connection_header_t connection
...
@@ -504,9 +504,9 @@ Request::set_connection_type(const restinio::http_connection_header_t connection
}
}
void
void
Request
::
set_body
(
const
std
::
string
&
body
)
Request
::
set_body
(
std
::
string
body
)
{
{
body_
=
body
;
body_
=
std
::
move
(
body
)
;
}
}
void
void
...
@@ -600,7 +600,7 @@ Request::init_parser()
...
@@ -600,7 +600,7 @@ Request::init_parser()
};
};
auto
header_field
=
std
::
make_shared
<
std
::
string
>
(
""
);
auto
header_field
=
std
::
make_shared
<
std
::
string
>
(
""
);
auto
on_header_field_cb
=
cbs_
->
on_header_field
;
auto
on_header_field_cb
=
cbs_
->
on_header_field
;
cbs_
->
on_header_field
=
[
this
,
header_field
,
on_header_field_cb
](
const
char
*
at
,
size_t
length
){
cbs_
->
on_header_field
=
[
header_field
,
on_header_field_cb
](
const
char
*
at
,
size_t
length
)
{
header_field
->
erase
();
header_field
->
erase
();
auto
field
=
std
::
string
(
at
,
length
);
auto
field
=
std
::
string
(
at
,
length
);
header_field
->
append
(
field
);
header_field
->
append
(
field
);
...
@@ -617,8 +617,7 @@ Request::init_parser()
...
@@ -617,8 +617,7 @@ Request::init_parser()
notify_state_change
(
State
::
HEADER_RECEIVED
);
notify_state_change
(
State
::
HEADER_RECEIVED
);
};
};
auto
on_body_cb
=
cbs_
->
on_body
;
auto
on_body_cb
=
cbs_
->
on_body
;
cbs_
->
on_body
=
[
this
,
on_body_cb
](
const
char
*
at
,
size_t
length
){
cbs_
->
on_body
=
[
on_body_cb
](
const
char
*
at
,
size_t
length
)
{
auto
content
=
std
::
string
(
at
,
length
);
if
(
on_body_cb
)
if
(
on_body_cb
)
on_body_cb
(
at
,
length
);
on_body_cb
(
at
,
length
);
};
};
...
@@ -863,7 +862,7 @@ Request::handle_response_header(const asio::error_code& ec)
...
@@ -863,7 +862,7 @@ Request::handle_response_header(const asio::error_code& ec)
std
::
getline
(
is
,
response_
.
body
);
std
::
getline
(
is
,
response_
.
body
);
unsigned
int
content_length
=
atoi
(
content_length_it
->
second
.
c_str
());
unsigned
int
content_length
=
atoi
(
content_length_it
->
second
.
c_str
());
// full body already in the header
// full body already in the header
if
(
(
response_
.
body
.
size
()
+
1
)
==
(
content_length
)
)
{
if
(
response_
.
body
.
size
()
+
1
==
content_length
)
{
response_
.
body
.
append
(
"
\n
"
);
response_
.
body
.
append
(
"
\n
"
);
parse_request
(
response_
.
body
);
parse_request
(
response_
.
body
);
if
(
message_complete_
.
load
())
if
(
message_complete_
.
load
())
...
@@ -941,7 +940,7 @@ Request::handle_response_body(const asio::error_code& ec, const size_t bytes)
...
@@ -941,7 +940,7 @@ Request::handle_response_body(const asio::error_code& ec, const size_t bytes)
}
}
size_t
size_t
Request
::
parse_request
(
const
std
::
string
request
)
Request
::
parse_request
(
const
std
::
string
&
request
)
{
{
std
::
lock_guard
<
std
::
mutex
>
lock
(
cbs_mutex_
);
std
::
lock_guard
<
std
::
mutex
>
lock
(
cbs_mutex_
);
return
http_parser_execute
(
parser_
.
get
(),
parser_s_
.
get
(),
request
.
c_str
(),
request
.
size
());
return
http_parser_execute
(
parser_
.
get
(),
parser_s_
.
get
(),
request
.
c_str
(),
request
.
size
());
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment