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
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
savoirfairelinux
opendht
Commits
5b87090c
Commit
5b87090c
authored
5 years ago
by
Adrien Béraud
Browse files
Options
Downloads
Patches
Plain Diff
http: use http_parser parsing logic
parent
fffee634
No related branches found
No related tags found
No related merge requests found
Changes
2
Expand all
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
include/opendht/http.h
+15
-19
15 additions, 19 deletions
include/opendht/http.h
src/http.cpp
+138
-290
138 additions, 290 deletions
src/http.cpp
with
153 additions
and
309 deletions
include/opendht/http.h
+
15
−
19
View file @
5b87090c
...
@@ -99,7 +99,7 @@ public:
...
@@ -99,7 +99,7 @@ public:
asio
::
streambuf
&
input
();
asio
::
streambuf
&
input
();
std
::
istream
&
data
()
{
return
istream_
;
}
std
::
istream
&
data
()
{
return
istream_
;
}
std
::
string
read_bytes
(
size_t
bytes
);
std
::
string
read_bytes
(
size_t
bytes
=
0
);
std
::
string
read_until
(
const
char
delim
);
std
::
string
read_until
(
const
char
delim
);
void
async_connect
(
std
::
vector
<
asio
::
ip
::
tcp
::
endpoint
>&&
endpoints
,
ConnectHandlerCb
);
void
async_connect
(
std
::
vector
<
asio
::
ip
::
tcp
::
endpoint
>&&
endpoints
,
ConnectHandlerCb
);
...
@@ -108,11 +108,20 @@ public:
...
@@ -108,11 +108,20 @@ public:
void
async_read_until
(
const
char
*
delim
,
BytesHandlerCb
cb
);
void
async_read_until
(
const
char
*
delim
,
BytesHandlerCb
cb
);
void
async_read_until
(
char
delim
,
BytesHandlerCb
cb
);
void
async_read_until
(
char
delim
,
BytesHandlerCb
cb
);
void
async_read
(
size_t
bytes
,
BytesHandlerCb
cb
);
void
async_read
(
size_t
bytes
,
BytesHandlerCb
cb
);
void
async_read_some
(
size_t
bytes
,
BytesHandlerCb
cb
);
void
timeout
(
const
std
::
chrono
::
seconds
timeout
,
HandlerCb
cb
=
{});
void
timeout
(
const
std
::
chrono
::
seconds
timeout
,
HandlerCb
cb
=
{});
void
close
();
void
close
();
private
:
private
:
template
<
typename
T
>
T
wrapCallabck
(
T
cb
)
const
{
return
[
t
=
shared_from_this
(),
cb
=
std
::
move
(
cb
)](
auto
...
params
)
{
cb
(
params
...);
};
}
unsigned
int
id_
;
unsigned
int
id_
;
static
std
::
atomic_uint
ids_
;
static
std
::
atomic_uint
ids_
;
...
@@ -232,7 +241,7 @@ public:
...
@@ -232,7 +241,7 @@ public:
~
Request
();
~
Request
();
unsigned
int
id
()
const
;
inline
unsigned
int
id
()
const
{
return
id_
;
}
;
void
set_connection
(
std
::
shared_ptr
<
Connection
>
connection
);
void
set_connection
(
std
::
shared_ptr
<
Connection
>
connection
);
std
::
shared_ptr
<
Connection
>
get_connection
()
const
;
std
::
shared_ptr
<
Connection
>
get_connection
()
const
;
inline
const
Url
&
get_url
()
const
{
inline
const
Url
&
get_url
()
const
{
...
@@ -272,15 +281,10 @@ private:
...
@@ -272,15 +281,10 @@ private:
using
OnCompleteCb
=
std
::
function
<
void
()
>
;
using
OnCompleteCb
=
std
::
function
<
void
()
>
;
struct
Callbacks
{
struct
Callbacks
{
Callbacks
(){}
OnStatusCb
on_status
;
OnStatusCb
on_status
;
OnDataCb
on_header_field
;
OnDataCb
on_header_field
;
OnDataCb
on_header_value
;
OnDataCb
on_header_value
;
OnDataCb
on_body
;
OnDataCb
on_body
;
OnCompleteCb
on_headers_complete
;
OnCompleteCb
on_message_complete
;
OnStateChangeCb
on_state_change
;
OnStateChangeCb
on_state_change
;
};
};
...
@@ -301,17 +305,11 @@ private:
...
@@ -301,17 +305,11 @@ private:
void
post
();
void
post
();
void
handle_request
(
const
asio
::
error_code
&
ec
);
void
handle_request
(
const
asio
::
error_code
&
ec
);
void
handle_response
(
const
asio
::
error_code
&
ec
,
size_t
bytes
);
void
handle_response_header
(
const
asio
::
error_code
&
ec
);
void
onHeadersComplete
();
void
onBody
(
const
char
*
at
,
size_t
length
);
void
handle_response_body
(
const
asio
::
error_code
&
ec
,
size_t
bytes
);
void
onComplete
();
/**
* Parse the request with http_parser.
* Return how many bytes were parsed.
* Note: we pass requerst.size()==0 to signal that EOF has been received.
*/
size_t
parse_request
(
const
std
::
string
&
request
);
std
::
shared_ptr
<
dht
::
Logger
>
logger_
;
std
::
shared_ptr
<
dht
::
Logger
>
logger_
;
...
@@ -320,7 +318,6 @@ private:
...
@@ -320,7 +318,6 @@ private:
restinio
::
http_connection_header_t
connection_type_
{
restinio
::
http_connection_header_t
::
close
};
restinio
::
http_connection_header_t
connection_type_
{
restinio
::
http_connection_header_t
::
close
};
std
::
string
body_
;
std
::
string
body_
;
std
::
mutex
cbs_mutex_
;
Callbacks
cbs_
;
Callbacks
cbs_
;
State
state_
;
State
state_
;
...
@@ -338,7 +335,6 @@ private:
...
@@ -338,7 +335,6 @@ private:
Response
response_
{};
Response
response_
{};
std
::
string
request_
;
std
::
string
request_
;
std
::
atomic
<
bool
>
message_complete_
{
false
};
std
::
atomic
<
bool
>
finishing_
{
false
};
std
::
atomic
<
bool
>
finishing_
{
false
};
std
::
unique_ptr
<
http_parser
>
parser_
;
std
::
unique_ptr
<
http_parser
>
parser_
;
std
::
unique_ptr
<
http_parser_settings
>
parser_s_
;
std
::
unique_ptr
<
http_parser_settings
>
parser_s_
;
...
...
This diff is collapsed.
Click to expand it.
src/http.cpp
+
138
−
290
View file @
5b87090c
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