c-hyper: use hyper_request_set_uri_parts to make h2 better

and make sure to not send Host: over h2.

Fixes #7679
Reported-by: David Cook
Closes #7827
This commit is contained in:
Daniel Stenberg 2021-10-08 11:33:50 +02:00
parent 9597d2def7
commit 4e0c28923a
No known key found for this signature in database
GPG Key ID: 5CC908FDB71E12C2

View File

@ -584,9 +584,22 @@ static CURLcode request_target(struct Curl_easy *data,
if(result)
return result;
if(hyper_request_set_uri(req, (uint8_t *)Curl_dyn_uptr(&r),
Curl_dyn_len(&r))) {
failf(data, "error setting path");
if(h2 && hyper_request_set_uri_parts(req,
/* scheme */
(uint8_t *)data->state.up.scheme,
strlen(data->state.up.scheme),
/* authority */
(uint8_t *)conn->host.name,
strlen(conn->host.name),
/* path_and_query */
(uint8_t *)Curl_dyn_uptr(&r),
Curl_dyn_len(&r))) {
failf(data, "error setting uri parts to hyper");
result = CURLE_OUT_OF_MEMORY;
}
else if(!h2 && hyper_request_set_uri(req, (uint8_t *)Curl_dyn_uptr(&r),
Curl_dyn_len(&r))) {
failf(data, "error setting uri to hyper");
result = CURLE_OUT_OF_MEMORY;
}
else
@ -939,9 +952,21 @@ CURLcode Curl_http(struct Curl_easy *data, bool *done)
if(result)
return result;
if(data->state.aptr.host &&
Curl_hyper_header(data, headers, data->state.aptr.host))
goto error;
if(!h2) {
if(data->state.aptr.host &&
Curl_hyper_header(data, headers, data->state.aptr.host))
goto error;
}
else {
/* For HTTP/2, we show the Host: header as if we sent it, to make it look
like for HTTP/1 but it isn't actually sent since :authority is then
used. */
if(Curl_debug(data, CURLINFO_HEADER_OUT, data->state.aptr.host,
strlen(data->state.aptr.host))) {
result = CURLE_ABORTED_BY_CALLBACK;
goto error;
}
}
if(data->state.aptr.proxyuserpwd &&
Curl_hyper_header(data, headers, data->state.aptr.proxyuserpwd))