How to keep HTTP/2 connection alive till the request / response session is complete? RRS feed

  • Question

  • User-1813431743 posted


    I am currently using HttpDeclarePush to exploit the Server Push feature in HTTP/2.

    I am able to successfully create all the parameters that this function accepts. But the issue is when HttpDeclarePush executes it returns a value of 1229 (ERROR_CONNECTION_INVALID) - https://docs.microsoft.com/en-us/windows/desktop/debug/system-error-codes--1000-1299-.

    On further investigation I found that the HttpHeaderConnection in _HTTP_HEADER_ID(https://docs.microsoft.com/en-us/windows/desktop/api/http/ne-http-_http_header_id) is actually passed in the function as 'close'. That implies that on every request response the server closes the connection and that is also happening in my case, I checked it in the log.

    Here is the code.

    class http2_native_module : public CHttpModule
        REQUEST_NOTIFICATION_STATUS OnBeginRequest(IN IHttpContext * p_http_context, IN IHttpEventProvider * p_provider)
            HTTP_REQUEST_ID    request_id;
            const HTTPAPI_VERSION version = HTTPAPI_VERSION_2;
            auto pHttpRequest = p_http_context->GetRequest();
            auto phttpRequestRaw = pHttpRequest->GetRawHttpRequest();
            HANDLE p_req_queue_handle = nullptr;
            auto isHttp2 = phttpRequestRaw->Flags;
        try {
                const auto request_queue_handle = HttpCreateRequestQueue(version, nullptr, nullptr, NULL, &p_req_queue_handle);
                const auto verb = phttpRequestRaw->Verb;
                const auto http_path = L"/polyfills.0d74a55d0dbab6b8c32c.js"; //ITEM that I want to PUSH to client
                const auto query = nullptr;
                request_id = phttpRequestRaw->RequestId;
                auto headers = phttpRequestRaw->Headers;
                auto connId = phttpRequestRaw->ConnectionId;                
                WriteEventViewerLog(L"OnBeginRequest - Entering HTTPDECLAREPUSH");
                headers.KnownHeaders[1].pRawValue = NULL;
                headers.KnownHeaders[1].RawValueLength = 0;
                const auto is_success = HttpDeclarePush(p_req_queue_handle, request_id, verb, http_path, query, &headers);
                sprintf_s(szBuffer, "%lu", is_success);
                Log("is_success value", szBuffer);  //ERROR CODE 1229 here
            catch (std::bad_alloc & e)
                auto something = e;
            return RQ_NOTIFICATION_CONTINUE;

    I even tried to update the header connection value as below but it still gives me 1229.

    headers.KnownHeaders[1].pRawValue = NULL;
    headers.KnownHeaders[1].RawValueLength = 0;

    I understand from https://http2.github.io/http2-spec/ that HTTP/2 actually ignores the content in HTTP HEADERs and uses some other mechanism as part of its FRAME.

    This brings us to the next question on how we can keep the connection OPEN and is it something related to the FRAME (similar to HEADER) that HTTP/2 uses, if so, how C++ or rather Microsoft helps us to play and exploit with the FRAME in HTTP/2?

    Thursday, July 12, 2018 11:56 AM

All replies

  • User121216299 posted

    Hi Bodapati,

    I try to understand your issue and find that you are working with C++.

    I try to contact the MSDN C++ forum and they had confirm that issue is more related with C++.

    They had informed me to redirect you to correct forum for this issue.

    I suggest you to post your issue on forum below which is best suitable forum for this question.

    MSDN C++ Forum

    I suggest you to close this thread, Before creating a new thread in C++ forum.

    It can be helpful for us to close this thread on our side.

    The reason why we recommend posting appropriately is you will get the most qualified pool of respondents, and other partners who read the forums regularly can either share their knowledge or learn from your interaction with us.

    Thank you for your understanding.



    Monday, July 16, 2018 5:59 AM