Commit 77e5788f authored by jan.koester's avatar jan.koester
Browse files

test

parent 47415099
Loading
Loading
Loading
Loading
+17 −1
Original line number Diff line number Diff line
@@ -1187,6 +1187,11 @@ libhttppp::HttpResponse libhttppp::HttpClient::GetStream(libhttppp::HttpRequest
        size_t header_end = std::string::npos;
        size_t search_from = 0;

        // Single deadline for the whole header, not one per chunk — a peer
        // trickling a byte every few seconds must not be able to hold this
        // loop (and the calling thread) open indefinitely.
        auto header_deadline = std::chrono::steady_clock::now() + std::chrono::seconds(10);

        for (;;) {
            if (raw.size() >= 4) {
                size_t start = (search_from >= 3) ? search_from - 3 : 0;
@@ -1203,8 +1208,19 @@ libhttppp::HttpResponse libhttppp::HttpClient::GetStream(libhttppp::HttpRequest
            if (header_end != std::string::npos)
                break;

            auto now = std::chrono::steady_clock::now();
            if (now >= header_deadline) {
                HTTPException he;
                he[HTTPException::Error] << "HTTP GetStream: timeout while reading header";
                throw he;
            }
            int remaining_sec = static_cast<int>(std::chrono::duration_cast<std::chrono::seconds>(
                header_deadline - now).count());
            if (remaining_sec <= 0)
                remaining_sec = 1;

            netplus::buffer buf(CHUNKSIZE);
            size_t n = _recvBlocking(buf, 10);
            size_t n = _recvBlocking(buf, remaining_sec);
            if (n == 0) {
                netplus::NetException ne;
                ne[netplus::NetException::Error] << "HTTP GetStream: EOF while reading header";