如何在请求/响应会话完成之前保持HTTP / 2连接活动? [英] How to keep HTTP/2 connection alive till the request / response session is complete?

查看:181
本文介绍了如何在请求/响应会话完成之前保持HTTP / 2连接活动?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我目前正在使用  HttpDeclarePush 来利用HTTP / 2中的服务器推送功能。

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

我能够成功创建此函数接受的所有参数。但问题是当  HttpDeclarePush  执行时它返回值1229(ERROR_CONNECTION_INVALID)

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)

在进一步调查中我发现  HttpHeaderConnection    _HTTP_HEADER_ID  实际上已在函数中传递为  'close' 。这意味着在每个请求响应时,服务器关闭
连接,这也发生在我的情况下,我在日志中检查了它。

On further investigation I found that the HttpHeaderConnection in _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.

这是代码。

class http2_native_module : public CHttpModule
{
public:
    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
            HttpCloseRequestQueue(p_req_queue_handle);
        }
        catch (std::bad_alloc & e)
        {
            auto something = e;
        }

        return RQ_NOTIFICATION_CONTINUE;
    }

我甚至尝试更新标题连接值,如下所示,但它仍然给我1229。

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;

我发现HTTP / 2实际上忽略了HTTP HEADER中的内容,并使用其他一些机制作为其一部分FRAME。

I came to know that HTTP/2 actually ignores the content in HTTP HEADERs and uses some other mechanism as part of its FRAME.

这让我们看到了关于如何保持连接OPEN的下一个问题,它是否与HTTP / 2使用的FRAME(类似于HEADER)有关,如果是, C ++或者说Microsoft如何帮助我们在HTTP / 2中使用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?

推荐答案

感谢您在此处发帖。

>>如何在请求/响应会话完成之前保持HTTP / 2连接存活?

据我所知,  RequestQueue的HTTP Server API默认超时值是2分钟。

As far as I know, the HTTP Server API default timeout value for RequestQueue is 2 Minutes.

您可以使用  HttpSetRequestQueueProperty函数或  HttpSetServerSessionProperty函数来设置或查询连接超时。 HTTP Server API为连接上的第一个请求强制执行默认的IdleConnection和HeaderWait计时器。
Keep-Alive连接上的后续请求将使用特定于应用程序的超时。

You could use HttpSetRequestQueueProperty function or HttpSetServerSessionProperty functions to set or query the connection timeouts. The HTTP Server API enforces the default IdleConnection and HeaderWait timers for the first request on a connection. Subsequent requests on a Keep-Alive connection will use the application specific timeouts.

有关详细信息,请参阅以下文档。

For more information, please refer to this document below.

https://docs.microsoft.com/zh-cn/ windows / desktop / api / http / ns-http-_http_timeout_limit_info

希望这对您有帮助。

最好的问候,

Baron Bi


这篇关于如何在请求/响应会话完成之前保持HTTP / 2连接活动?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆