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
090da49f
Commit
090da49f
authored
5 years ago
by
Adrien Béraud
Browse files
Options
Downloads
Patches
Plain Diff
http/Request: cleanup
parent
22594396
No related branches found
No related tags found
No related merge requests found
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
src/http.cpp
+21
-39
21 additions, 39 deletions
src/http.cpp
with
21 additions
and
39 deletions
src/http.cpp
+
21
−
39
View file @
090da49f
...
@@ -688,34 +688,28 @@ Request::init_parser()
...
@@ -688,34 +688,28 @@ Request::init_parser()
{
{
// user registered callbacks wrappers to store its data in the response
// user registered callbacks wrappers to store its data in the response
std
::
lock_guard
<
std
::
mutex
>
lock
(
cbs_mutex_
);
std
::
lock_guard
<
std
::
mutex
>
lock
(
cbs_mutex_
);
auto
on_status_cb
=
cbs_
.
on_status
;
cbs_
.
on_status
=
[
this
,
statusCb
=
std
::
move
(
cbs_
.
on_status
)](
unsigned
int
status_code
){
cbs_
.
on_status
=
[
this
,
on_status_cb
](
unsigned
int
status_code
){
response_
.
status_code
=
status_code
;
response_
.
status_code
=
status_code
;
if
(
on_
status
_c
b
)
if
(
status
C
b
)
on_
status
_c
b
(
status_code
);
status
C
b
(
status_code
);
};
};
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
;
cbs_
.
on_header_field
=
[
header_field
,
headerFieldCb
=
std
::
move
(
cbs_
.
on_header_field
)](
const
char
*
at
,
size_t
length
)
{
cbs_
.
on_header_field
=
[
header_field
,
on_header_field_cb
](
const
char
*
at
,
size_t
length
)
{
*
header_field
=
std
::
string
(
at
,
length
);
header_field
->
erase
();
if
(
headerFieldCb
)
auto
field
=
std
::
string
(
at
,
length
);
headerFieldCb
(
at
,
length
);
header_field
->
append
(
field
);
if
(
on_header_field_cb
)
on_header_field_cb
(
at
,
length
);
};
};
auto
on_header_value_cb
=
cbs_
.
on_header_value
;
cbs_
.
on_header_value
=
[
this
,
header_field
,
headerValueCb
=
std
::
move
(
cbs_
.
on_header_value
)](
const
char
*
at
,
size_t
length
)
{
cbs_
.
on_header_value
=
[
this
,
header_field
,
on_header_value_cb
](
const
char
*
at
,
size_t
length
)
{
response_
.
headers
[
*
header_field
]
=
std
::
string
(
at
,
length
);
response_
.
headers
[
*
header_field
]
=
std
::
string
(
at
,
length
);
if
(
on_
header
_v
alue
_c
b
)
if
(
header
V
alue
C
b
)
on_
header
_v
alue
_c
b
(
at
,
length
);
header
V
alue
C
b
(
at
,
length
);
};
};
cbs_
.
on_headers_complete
=
[
this
](){
cbs_
.
on_headers_complete
=
[
this
](){
notify_state_change
(
State
::
HEADER_RECEIVED
);
notify_state_change
(
State
::
HEADER_RECEIVED
);
};
};
auto
on_body_cb
=
cbs_
.
on_body
;
cbs_
.
on_body
=
[
bodyCb
=
std
::
move
(
cbs_
.
on_body
)](
const
char
*
at
,
size_t
length
)
{
cbs_
.
on_body
=
[
on_body_cb
](
const
char
*
at
,
size_t
length
)
{
if
(
bodyCb
)
if
(
on_body_cb
)
bodyCb
(
at
,
length
);
on_body_cb
(
at
,
length
);
};
};
cbs_
.
on_message_complete
=
[
this
](){
cbs_
.
on_message_complete
=
[
this
](){
if
(
logger_
)
if
(
logger_
)
...
@@ -725,39 +719,27 @@ Request::init_parser()
...
@@ -725,39 +719,27 @@ Request::init_parser()
}
}
// http_parser raw c callback (note: no context can be passed into them)
// http_parser raw c callback (note: no context can be passed into them)
parser_s_
->
on_status
=
[](
http_parser
*
parser
,
const
char
*
/*at*/
,
size_t
/*length*/
)
->
int
{
parser_s_
->
on_status
=
[](
http_parser
*
parser
,
const
char
*
/*at*/
,
size_t
/*length*/
)
->
int
{
auto
cbs
=
static_cast
<
Callbacks
*>
(
parser
->
data
);
static_cast
<
Callbacks
*>
(
parser
->
data
)
->
on_status
(
parser
->
status_code
);
if
(
cbs
->
on_status
)
cbs
->
on_status
(
parser
->
status_code
);
return
0
;
return
0
;
};
};
parser_s_
->
on_header_field
=
[](
http_parser
*
parser
,
const
char
*
at
,
size_t
length
)
->
int
{
parser_s_
->
on_header_field
=
[](
http_parser
*
parser
,
const
char
*
at
,
size_t
length
)
->
int
{
auto
cbs
=
static_cast
<
Callbacks
*>
(
parser
->
data
);
static_cast
<
Callbacks
*>
(
parser
->
data
)
->
on_header_field
(
at
,
length
);
if
(
cbs
->
on_header_field
)
cbs
->
on_header_field
(
at
,
length
);
return
0
;
return
0
;
};
};
parser_s_
->
on_header_value
=
[](
http_parser
*
parser
,
const
char
*
at
,
size_t
length
)
->
int
{
parser_s_
->
on_header_value
=
[](
http_parser
*
parser
,
const
char
*
at
,
size_t
length
)
->
int
{
auto
cbs
=
static_cast
<
Callbacks
*>
(
parser
->
data
);
static_cast
<
Callbacks
*>
(
parser
->
data
)
->
on_header_value
(
at
,
length
);
if
(
cbs
->
on_header_value
)
cbs
->
on_header_value
(
at
,
length
);
return
0
;
return
0
;
};
};
parser_s_
->
on_body
=
[](
http_parser
*
parser
,
const
char
*
at
,
size_t
length
)
->
int
{
parser_s_
->
on_body
=
[](
http_parser
*
parser
,
const
char
*
at
,
size_t
length
)
->
int
{
auto
cbs
=
static_cast
<
Callbacks
*>
(
parser
->
data
);
static_cast
<
Callbacks
*>
(
parser
->
data
)
->
on_body
(
at
,
length
);
if
(
cbs
->
on_body
)
cbs
->
on_body
(
at
,
length
);
return
0
;
return
0
;
};
};
parser_s_
->
on_headers_complete
=
[](
http_parser
*
parser
)
->
int
{
parser_s_
->
on_headers_complete
=
[](
http_parser
*
parser
)
->
int
{
auto
cbs
=
static_cast
<
Callbacks
*>
(
parser
->
data
);
static_cast
<
Callbacks
*>
(
parser
->
data
)
->
on_headers_complete
();
if
(
cbs
->
on_headers_complete
)
cbs
->
on_headers_complete
();
return
0
;
return
0
;
};
};
parser_s_
->
on_message_complete
=
[](
http_parser
*
parser
)
->
int
{
parser_s_
->
on_message_complete
=
[](
http_parser
*
parser
)
->
int
{
auto
cbs
=
static_cast
<
Callbacks
*>
(
parser
->
data
);
static_cast
<
Callbacks
*>
(
parser
->
data
)
->
on_message_complete
();
if
(
cbs
->
on_message_complete
)
cbs
->
on_message_complete
();
return
0
;
return
0
;
};
};
}
}
...
@@ -774,7 +756,7 @@ Request::connect(std::vector<asio::ip::tcp::endpoint>&& endpoints, HandlerCb cb)
...
@@ -774,7 +756,7 @@ Request::connect(std::vector<asio::ip::tcp::endpoint>&& endpoints, HandlerCb cb)
}
}
if
(
logger_
){
if
(
logger_
){
std
::
string
eps
=
""
;
std
::
string
eps
=
""
;
for
(
auto
&
endpoint
:
endpoints
)
for
(
const
auto
&
endpoint
:
endpoints
)
eps
.
append
(
endpoint
.
address
().
to_string
()
+
" "
);
eps
.
append
(
endpoint
.
address
().
to_string
()
+
" "
);
logger_
->
d
(
"[http:client] [request:%i] connect begin: %s"
,
id_
,
eps
.
c_str
());
logger_
->
d
(
"[http:client] [request:%i] connect begin: %s"
,
id_
,
eps
.
c_str
());
}
}
...
...
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