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
7270c353
Commit
7270c353
authored
5 years ago
by
Seva
Browse files
Options
Downloads
Patches
Plain Diff
http: handle expect 100-continue
expose raw request & ignore more self-signed
parent
63afc8c2
Branches
Branches containing commit
Tags
Tags containing commit
No related merge requests found
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
include/opendht/http.h
+3
-0
3 additions, 0 deletions
include/opendht/http.h
src/http.cpp
+27
-12
27 additions, 12 deletions
src/http.cpp
with
30 additions
and
12 deletions
include/opendht/http.h
+
3
−
0
View file @
7270c353
...
...
@@ -221,6 +221,9 @@ public:
inline
const
Url
&
get_url
()
const
{
return
resolver_
->
get_url
();
};
inline
std
::
string
&
to_string
()
{
return
request_
;
}
void
set_certificate
(
std
::
shared_ptr
<
dht
::
crypto
::
Certificate
>
certificate
);
void
set_logger
(
std
::
shared_ptr
<
dht
::
Logger
>
logger
);
...
...
This diff is collapsed.
Click to expand it.
src/http.cpp
+
27
−
12
View file @
7270c353
...
...
@@ -173,7 +173,8 @@ Connection::set_endpoint(const asio::ip::tcp::endpoint& endpoint, const asio::ss
auto
verifier
=
asio
::
ssl
::
rfc2818_verification
(
hostname
);
bool
verified
=
verifier
(
preverified
,
ctx
);
auto
verify_ec
=
X509_STORE_CTX_get_error
(
ctx
.
native_handle
());
if
(
verify_ec
==
X509_V_ERR_SELF_SIGNED_CERT_IN_CHAIN
/*19*/
)
if
(
verify_ec
==
X509_V_ERR_DEPTH_ZERO_SELF_SIGNED_CERT
/*18*/
||
verify_ec
==
X509_V_ERR_SELF_SIGNED_CERT_IN_CHAIN
/*19*/
)
verified
=
true
;
return
verified
;
}
...
...
@@ -231,10 +232,13 @@ Connection::async_handshake(HandlerCb cb)
if
(
ec
==
asio
::
error
::
operation_aborted
)
return
;
auto
verify_ec
=
SSL_get_verify_result
(
ssl_socket_
->
asio_ssl_stream
().
native_handle
());
if
(
verify_ec
==
X509_V_ERR_SELF_SIGNED_CERT_IN_CHAIN
/*19*/
and
logger_
)
if
(
logger_
){
if
(
verify_ec
==
X509_V_ERR_DEPTH_ZERO_SELF_SIGNED_CERT
/*18*/
||
verify_ec
==
X509_V_ERR_SELF_SIGNED_CERT_IN_CHAIN
/*19*/
)
logger_
->
d
(
"[http:client] [connection:%i] allow self-signed certificate in handshake"
,
id_
);
else
if
(
verify_ec
!=
X509_V_OK
and
logger_
)
else
if
(
verify_ec
!=
X509_V_OK
)
logger_
->
e
(
"[http:client] [connection:%i] verify handshake error: %i"
,
id_
,
verify_ec
);
}
if
(
cb
)
cb
(
ec
);
});
...
...
@@ -520,14 +524,18 @@ void
Request
::
build
()
{
std
::
stringstream
request
;
bool
append_body
=
true
;
// first header
request
<<
header_
.
method
().
c_str
()
<<
" "
<<
header_
.
request_target
()
<<
" "
<<
"HTTP/"
<<
header_
.
http_major
()
<<
"."
<<
header_
.
http_minor
()
<<
"
\r\n
"
;
// other headers
for
(
auto
header
:
headers_
)
for
(
auto
header
:
headers_
)
{
request
<<
restinio
::
field_to_string
(
header
.
first
)
<<
": "
<<
header
.
second
<<
"
\r\n
"
;
if
(
header
.
first
==
restinio
::
http_field_t
::
expect
and
header
.
second
==
"100-continue"
)
append_body
=
false
;
}
// last connection header
std
::
string
conn_str
=
""
;
...
...
@@ -546,13 +554,11 @@ Request::build()
request
<<
"Connection: "
<<
conn_str
<<
"
\r\n
"
;
// body & content-length
if
(
!
body_
.
empty
())
{
if
(
!
body_
.
empty
())
request
<<
"Content-Length: "
<<
body_
.
size
()
<<
"
\r\n\r\n
"
;
request
<<
body_
;
}
// last delim
request
<<
"
\r\n
"
;
if
(
append_body
)
request
<<
body_
<<
"
\r\n
"
;
request_
=
request
.
str
();
}
...
...
@@ -713,6 +719,7 @@ Request::connect(std::vector<asio::ip::tcp::endpoint>&& endpoints, HandlerCb cb)
if
(
certificate_
)
conn_
->
set_endpoint
(
endpoint
,
asio
::
ssl
::
verify_peer
|
asio
::
ssl
::
verify_fail_if_no_peer_cert
);
if
(
conn_
and
conn_
->
is_open
()
and
conn_
->
is_ssl
()){
conn_
->
async_handshake
([
this
,
cb
](
const
asio
::
error_code
&
ec
){
if
(
ec
==
asio
::
error
::
operation_aborted
)
...
...
@@ -851,9 +858,17 @@ Request::handle_response_header(const asio::error_code& ec)
headers
.
append
(
header
+
"
\n
"
);
}
headers
.
append
(
"
\n
"
);
// parse the headers
parse_request
(
headers
);
if
(
headers_
[
restinio
::
http_field_t
::
expect
]
==
"100-continue"
and
response_
.
status_code
!=
200
){
notify_state_change
(
State
::
SENDING
);
request_
.
append
(
body_
);
std
::
ostream
request_stream
(
&
conn_
->
input
());
request_stream
<<
body_
<<
"
\r\n
"
;
conn_
->
async_write
(
std
::
bind
(
&
Request
::
handle_request
,
this
,
std
::
placeholders
::
_1
));
return
;
}
// has content-length
auto
content_length_it
=
response_
.
headers
.
find
(
HTTP_HEADER_CONTENT_LENGTH
);
if
(
content_length_it
!=
response_
.
headers
.
end
())
...
...
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