Commit 29cbdb30 authored by jan.koester's avatar jan.koester
Browse files

fixes

parent c3b5d62e
Loading
Loading
Loading
Loading
+24 −3
Original line number Diff line number Diff line
@@ -224,9 +224,28 @@ libhttppp::HttpClient::HttpClient(const HttpUrl& desturl)

bool libhttppp::HttpClient::tryHttp3First(){
  try {
    _cltsock = std::make_unique<netplus::quic>();
    _cltsock->connect(_url.getHost(), _url.getPort(), false);
    _cltsock->setNonBlock();
    auto q = std::make_unique<netplus::quic>();
    q->connect(_url.getHost(), _url.getPort(), false);
    q->setNonBlock();

    // Verify the QUIC handshake actually completes within a short timeout.
    // UDP connect() always succeeds, so we must probe the handshake.
    auto deadline = std::chrono::steady_clock::now() + std::chrono::milliseconds(500);
    while (!q->getHandshakeDone()) {
      if (std::chrono::steady_clock::now() >= deadline) {
        // Handshake did not complete — server likely doesn't support QUIC
        return false;
      }
      try {
        q->pumpNetwork(MSG_DONTWAIT);
      } catch (netplus::NetException &e) {
        if (e.getErrorType() != netplus::NetException::Note)
          return false;
      }
      _sw.waitRead(*q, 50);
    }

    _cltsock = std::move(q);
    _isH2 = false;
    return true;
  } catch (netplus::NetException&) {
@@ -247,6 +266,7 @@ void libhttppp::HttpClient::resetConnection(){
    _cltsock->setNonBlock();
    _isH2 = false;
  } else if (_url.getProtocol() == HttpUrl::HTTPS) {
    // Try QUIC/HTTP3 first for HTTPS connections
    if (tryHttp3First()) {
      return;
    }
@@ -308,6 +328,7 @@ void libhttppp::HttpClient::reconnect(){
    _cltsock->setNonBlock();
    _isH2 = false;
  } else if(_url.getProtocol() == HttpUrl::HTTPS) {
    // Try QUIC/HTTP3 first for HTTPS connections
    if (tryHttp3First()) {
      return;
    }