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
c4aa272d
Commit
c4aa272d
authored
5 years ago
by
Adrien Béraud
Browse files
Options
Downloads
Patches
Plain Diff
http/request: add constructor
parent
4ce78bdb
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
+2
-0
2 additions, 0 deletions
include/opendht/http.h
src/http.cpp
+16
-5
16 additions, 5 deletions
src/http.cpp
with
18 additions
and
5 deletions
include/opendht/http.h
+
2
−
0
View file @
c4aa272d
...
@@ -212,6 +212,7 @@ public:
...
@@ -212,6 +212,7 @@ public:
using
OnDataCb
=
std
::
function
<
void
(
const
char
*
at
,
size_t
length
)
>
;
using
OnDataCb
=
std
::
function
<
void
(
const
char
*
at
,
size_t
length
)
>
;
using
OnStateChangeCb
=
std
::
function
<
void
(
State
state
,
const
Response
&
response
)
>
;
using
OnStateChangeCb
=
std
::
function
<
void
(
State
state
,
const
Response
&
response
)
>
;
using
OnJsonCb
=
std
::
function
<
void
(
Json
::
Value
value
,
unsigned
int
status_code
)
>
;
using
OnJsonCb
=
std
::
function
<
void
(
Json
::
Value
value
,
unsigned
int
status_code
)
>
;
using
OnDoneCb
=
std
::
function
<
void
(
const
Response
&
response
)
>
;
// resolves implicitly
// resolves implicitly
Request
(
asio
::
io_context
&
ctx
,
const
std
::
string
&
url
,
const
Json
::
Value
&
json
,
OnJsonCb
jsoncb
,
Request
(
asio
::
io_context
&
ctx
,
const
std
::
string
&
url
,
const
Json
::
Value
&
json
,
OnJsonCb
jsoncb
,
...
@@ -219,6 +220,7 @@ public:
...
@@ -219,6 +220,7 @@ public:
Request
(
asio
::
io_context
&
ctx
,
const
std
::
string
&
url
,
std
::
shared_ptr
<
dht
::
Logger
>
logger
=
{});
Request
(
asio
::
io_context
&
ctx
,
const
std
::
string
&
url
,
std
::
shared_ptr
<
dht
::
Logger
>
logger
=
{});
Request
(
asio
::
io_context
&
ctx
,
const
std
::
string
&
host
,
const
std
::
string
&
service
,
Request
(
asio
::
io_context
&
ctx
,
const
std
::
string
&
host
,
const
std
::
string
&
service
,
const
bool
ssl
=
false
,
std
::
shared_ptr
<
dht
::
Logger
>
logger
=
{});
const
bool
ssl
=
false
,
std
::
shared_ptr
<
dht
::
Logger
>
logger
=
{});
Request
(
asio
::
io_context
&
ctx
,
const
std
::
string
&
url
,
OnDoneCb
onDone
,
std
::
shared_ptr
<
dht
::
Logger
>
logger
=
{});
// user defined resolver
// user defined resolver
Request
(
asio
::
io_context
&
ctx
,
std
::
shared_ptr
<
Resolver
>
resolver
,
sa_family_t
family
=
AF_UNSPEC
);
Request
(
asio
::
io_context
&
ctx
,
std
::
shared_ptr
<
Resolver
>
resolver
,
sa_family_t
family
=
AF_UNSPEC
);
...
...
This diff is collapsed.
Click to expand it.
src/http.cpp
+
16
−
5
View file @
c4aa272d
...
@@ -443,11 +443,13 @@ Request::Request(asio::io_context& ctx, const std::string& url, const Json::Valu
...
@@ -443,11 +443,13 @@ Request::Request(asio::io_context& ctx, const std::string& url, const Json::Valu
if
(
state
!=
Request
::
State
::
DONE
)
if
(
state
!=
Request
::
State
::
DONE
)
return
;
return
;
Json
::
Value
json
;
Json
::
Value
json
;
if
(
response
.
status_code
!=
0
)
{
std
::
string
err
;
std
::
string
err
;
Json
::
CharReaderBuilder
rbuilder
;
Json
::
CharReaderBuilder
rbuilder
;
auto
reader
=
std
::
unique_ptr
<
Json
::
CharReader
>
(
rbuilder
.
newCharReader
());
auto
reader
=
std
::
unique_ptr
<
Json
::
CharReader
>
(
rbuilder
.
newCharReader
());
if
(
!
reader
->
parse
(
response
.
body
.
data
(),
response
.
body
.
data
()
+
response
.
body
.
size
(),
&
json
,
&
err
)
and
logger_
)
if
(
!
reader
->
parse
(
response
.
body
.
data
(),
response
.
body
.
data
()
+
response
.
body
.
size
(),
&
json
,
&
err
)
and
logger_
)
logger_
->
e
(
"[http:request:%i] can't parse response to json"
,
id_
,
err
.
c_str
());
logger_
->
e
(
"[http:request:%i] can't parse response to json"
,
id_
,
err
.
c_str
());
}
if
(
jsoncb
)
if
(
jsoncb
)
jsoncb
(
json
,
response
.
status_code
);
jsoncb
(
json
,
response
.
status_code
);
});
});
...
@@ -460,6 +462,15 @@ Request::Request(asio::io_context& ctx, const std::string& url, std::shared_ptr<
...
@@ -460,6 +462,15 @@ Request::Request(asio::io_context& ctx, const std::string& url, std::shared_ptr<
init_default_headers
();
init_default_headers
();
}
}
Request
::
Request
(
asio
::
io_context
&
ctx
,
const
std
::
string
&
url
,
OnDoneCb
onDone
,
std
::
shared_ptr
<
dht
::
Logger
>
logger
)
:
logger_
(
logger
),
id_
(
Request
::
ids_
++
),
ctx_
(
ctx
),
resolver_
(
std
::
make_shared
<
Resolver
>
(
ctx
,
url
,
logger
))
{
add_on_state_change_callback
([
this
,
onDone
](
State
state
,
const
Response
&
response
){
if
(
state
==
Request
::
State
::
DONE
)
onDone
(
response
);
});
}
Request
::
Request
(
asio
::
io_context
&
ctx
,
const
std
::
string
&
host
,
const
std
::
string
&
service
,
Request
::
Request
(
asio
::
io_context
&
ctx
,
const
std
::
string
&
host
,
const
std
::
string
&
service
,
const
bool
ssl
,
std
::
shared_ptr
<
dht
::
Logger
>
logger
)
const
bool
ssl
,
std
::
shared_ptr
<
dht
::
Logger
>
logger
)
:
logger_
(
logger
),
id_
(
Request
::
ids_
++
),
ctx_
(
ctx
),
:
logger_
(
logger
),
id_
(
Request
::
ids_
++
),
ctx_
(
ctx
),
...
...
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