src: Use nghttp2_session_upgrade2
This commit is contained in:
parent
269a100081
commit
558934cee5
|
@ -815,7 +815,7 @@ int HttpClient::on_upgrade_connect() {
|
|||
} else {
|
||||
auto meth = std::find_if(
|
||||
std::begin(config.headers), std::end(config.headers),
|
||||
[](const Header &kv) { return util::strieq_l(":method", kv.name); });
|
||||
[](const Header &kv) { return util::streq_l(":method", kv.name); });
|
||||
|
||||
if (meth == std::end(config.headers)) {
|
||||
req = "GET ";
|
||||
|
@ -988,8 +988,18 @@ int HttpClient::connection_made() {
|
|||
if (!reqvec[0]->data_prd) {
|
||||
stream_user_data = reqvec[0].get();
|
||||
}
|
||||
rv = nghttp2_session_upgrade(session, settings_payload.data(),
|
||||
settings_payloadlen, stream_user_data);
|
||||
// If HEAD is used, that is only when user specified it with -H
|
||||
// option.
|
||||
auto head_request =
|
||||
stream_user_data &&
|
||||
std::find_if(std::begin(config.headers), std::end(config.headers),
|
||||
[](const Header &kv) {
|
||||
return util::streq_l(":method", kv.name) &&
|
||||
util::streq_l("HEAD", kv.value);
|
||||
}) != std::end(config.headers);
|
||||
rv = nghttp2_session_upgrade2(session, settings_payload.data(),
|
||||
settings_payloadlen, head_request,
|
||||
stream_user_data);
|
||||
if (rv != 0) {
|
||||
std::cerr << "[ERROR] nghttp2_session_upgrade() returned error: "
|
||||
<< nghttp2_strerror(rv) << std::endl;
|
||||
|
|
|
@ -108,9 +108,10 @@ int Http2Upstream::upgrade_upstream(HttpsUpstream *http) {
|
|||
auto settings_payload =
|
||||
base64::decode(std::begin(http2_settings), std::end(http2_settings));
|
||||
|
||||
rv = nghttp2_session_upgrade(
|
||||
rv = nghttp2_session_upgrade2(
|
||||
session_, reinterpret_cast<const uint8_t *>(settings_payload.c_str()),
|
||||
settings_payload.size(), nullptr);
|
||||
settings_payload.size(),
|
||||
http->get_downstream()->get_request_method() == HTTP_HEAD, nullptr);
|
||||
if (rv != 0) {
|
||||
if (LOG_ENABLED(INFO)) {
|
||||
ULOG(INFO, this) << "nghttp2_session_upgrade() returned error: "
|
||||
|
|
|
@ -404,6 +404,10 @@ bool streq_l(const char (&a)[N], InputIt b, size_t blen) {
|
|||
return streq(a, N - 1, b, blen);
|
||||
}
|
||||
|
||||
template <size_t N> bool streq_l(const char (&a)[N], const std::string &b) {
|
||||
return streq(a, N - 1, std::begin(b), b.size());
|
||||
}
|
||||
|
||||
bool strifind(const char *a, const char *b);
|
||||
|
||||
template <typename InputIt> void inp_strlower(InputIt first, InputIt last) {
|
||||
|
|
Loading…
Reference in New Issue