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
72a06b14
Commit
72a06b14
authored
5 years ago
by
Adrien Béraud
Browse files
Options
Downloads
Patches
Plain Diff
http: add Request::set_auth
parent
e4dacc64
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
+8
-8
8 additions, 8 deletions
include/opendht/http.h
src/http.cpp
+15
-4
15 additions, 4 deletions
src/http.cpp
with
23 additions
and
12 deletions
include/opendht/http.h
+
8
−
8
View file @
72a06b14
...
@@ -21,10 +21,9 @@
...
@@ -21,10 +21,9 @@
#include
"def.h"
#include
"def.h"
#include
"infohash.h"
#include
"infohash.h"
#include
<asio.hpp>
#include
<asio/ssl/context.hpp>
#include
<asio/ssl.hpp>
#include
<restinio/http_headers.hpp>
#include
<restinio/message_builders.hpp>
#include
<restinio/all.hpp>
#include
<memory>
#include
<memory>
#include
<queue>
#include
<queue>
...
@@ -221,12 +220,13 @@ public:
...
@@ -221,12 +220,13 @@ public:
/**
/**
* Define the HTTP header/body as per https://tools.ietf.org/html/rfc7230.
* Define the HTTP header/body as per https://tools.ietf.org/html/rfc7230.
*/
*/
void
set_header
(
const
restinio
::
http_request_header_t
header
);
void
set_header
(
restinio
::
http_request_header_t
header
);
void
set_method
(
const
restinio
::
http_method_id_t
method
);
void
set_method
(
restinio
::
http_method_id_t
method
);
void
set_target
(
std
::
string
target
);
void
set_target
(
std
::
string
target
);
void
set_header_field
(
const
restinio
::
http_field_t
field
,
std
::
string
value
);
void
set_header_field
(
restinio
::
http_field_t
field
,
std
::
string
value
);
void
set_connection_type
(
const
restinio
::
http_connection_header_t
connection
);
void
set_connection_type
(
restinio
::
http_connection_header_t
connection
);
void
set_body
(
std
::
string
body
);
void
set_body
(
std
::
string
body
);
void
set_auth
(
const
std
::
string
&
username
,
const
std
::
string
&
password
);
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
);
...
...
This diff is collapsed.
Click to expand it.
src/http.cpp
+
15
−
4
View file @
72a06b14
...
@@ -474,13 +474,13 @@ Request::set_logger(std::shared_ptr<dht::Logger> logger)
...
@@ -474,13 +474,13 @@ Request::set_logger(std::shared_ptr<dht::Logger> logger)
}
}
void
void
Request
::
set_header
(
const
restinio
::
http_request_header_t
header
)
Request
::
set_header
(
restinio
::
http_request_header_t
header
)
{
{
header_
=
header
;
header_
=
header
;
}
}
void
void
Request
::
set_method
(
const
restinio
::
http_method_id_t
method
)
Request
::
set_method
(
restinio
::
http_method_id_t
method
)
{
{
header_
.
method
(
method
);
header_
.
method
(
method
);
}
}
...
@@ -492,13 +492,13 @@ Request::set_target(std::string target)
...
@@ -492,13 +492,13 @@ Request::set_target(std::string target)
}
}
void
void
Request
::
set_header_field
(
const
restinio
::
http_field_t
field
,
std
::
string
value
)
Request
::
set_header_field
(
restinio
::
http_field_t
field
,
std
::
string
value
)
{
{
headers_
[
field
]
=
std
::
move
(
value
);
headers_
[
field
]
=
std
::
move
(
value
);
}
}
void
void
Request
::
set_connection_type
(
const
restinio
::
http_connection_header_t
connection
)
Request
::
set_connection_type
(
restinio
::
http_connection_header_t
connection
)
{
{
connection_type_
=
connection
;
connection_type_
=
connection
;
}
}
...
@@ -509,6 +509,17 @@ Request::set_body(std::string body)
...
@@ -509,6 +509,17 @@ Request::set_body(std::string body)
body_
=
std
::
move
(
body
);
body_
=
std
::
move
(
body
);
}
}
void
Request
::
set_auth
(
const
std
::
string
&
username
,
const
std
::
string
&
password
)
{
std
::
vector
<
uint8_t
>
creds
;
creds
.
reserve
(
username
.
size
()
+
password
.
size
()
+
1
);
creds
.
insert
(
creds
.
end
(),
username
.
begin
(),
username
.
end
());
creds
.
emplace_back
(
':'
);
creds
.
insert
(
creds
.
end
(),
password
.
begin
(),
password
.
end
());
set_header_field
(
restinio
::
http_field_t
::
authorization
,
"Basic "
+
base64_encode
(
creds
));
}
void
void
Request
::
build
()
Request
::
build
()
{
{
...
...
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