Thank you for your prompt!
I think I should give my question a clear description.
The "Connection:keep-alive" is in the reply header, when I call close() of
the reply, the connection is still on ,I wonder how can I send a second request
to the server using this connection in such case ?
If I just simply make a second request like the following
manager->get(QNetworkRequest(QUrl("url")));
it seems a another new TCP connection to the server will be initiated (I have
checked with a network sniffer)
------------------ Original ------------------
From: "Mandeep Sandhu";<mandeepsandhu....@gmail.com>;
Date: Wed, Nov 27, 2013 04:57 PM
To: "iMath"<2281570...@qq.com>;
Cc: "Interest@qt-project.org"<interest@qt-project.org>;
Subject: Re: [Interest] QNetworkAccessManager and HTTP persistent connection
Please reply to the whole list and not to me individually. Maybe
someone on this list might have a more specific answer.
Both pipelined and persistent connections use a single TCP connection.
But in pipelining, the client can send multiple requests WITHOUT
WAITING for a response from the server whereas in persistent
connections the second (or subsequent) responses are sent only after
receiving response of the previous request:
http://en.wikipedia.org/wiki/HTTP_pipelining
If the server has not sent a "Connection: Close" then closing the
connection from the client _might_ to be a bug.
How are you ascertaining that the client is initiating the close? Does
the packet sniffer show the client sending a FIN packet?
-mandeep
On Wed, Nov 27, 2013 at 12:21 PM, iMath <2281570...@qq.com> wrote:
> HTTP persistent connection, also called HTTP keep-alive, or HTTP connection
> reuse, is the idea of using a single TCP connection to send and receive
> multiple HTTP requests/responses, as opposed to opening a new connection for
> every single request/response
> pair.(http://en.wikipedia.org/wiki/HTTP_persistent_connection)
>
> "Connection:keep-alive" is in the response header.
>
> I want to send my a second http request using the same connection that was
> setup when the first HTTP request was made. how can this be achieved through
> Qt?
>
>
> ------------------ Original ------------------
> From: "Mandeep Sandhu";<mandeepsandhu....@gmail.com>;
> Date: Tue, Nov 26, 2013 08:50 PM
> To: "iMath"<2281570...@qq.com>;
> Cc: "Interest@qt-project.org"<interest@qt-project.org>;
> Subject: Re: [Interest] QNetworkAccessManager and HTTP persistent
> connection
>
> I think I was wrong in telling you that HTTP persistent connection was
> same as HTTP pipelining. They aren't.
>
> In HTTP pipelining multiple HTTP requests can be made w/o waiting for
> response of each connection. Whereas in HTTP persistent connection
> (default as you said in HTTP 1.1), the same TCP connection is used for
> sending HTTP request "one-after-another".
>
> Can you check if the the outgoing HTTP request has the "Connection:
> keep-alive" set in its (HTTP) header. Also, I've read that sometimes
> webservers will send a "Connection: Close" header in its response in
> which case the client will close it's connection, so check if the
> webserver is playing nice with your request. Which webserver are you
> testing against?
>
> HTH,
> -mandeep
>
>
>
> On Tue, Nov 26, 2013 at 5:19 PM, iMath <2281570...@qq.com> wrote:
>> unfortunately ,it doesn't work on Qt4/WinXP
>> I have set
>> request.setAttribute(QNetworkRequest::HttpPipeliningAllowedAttribute,
>> true);
>>
>> but the attribute QNetworkRequest::HttpPipeliningWasUsedAttribute in the
>> reply is false .
>> ------------------ Original ------------------
>> From: "Mandeep Sandhu";<mandeepsandhu....@gmail.com>;
>> Date: Tue, Nov 26, 2013 02:14 PM
>> To: "iMath"<2281570...@qq.com>;
>> Cc: "interest"<interest@qt-project.org>;
>> Subject: Re: [Interest] QNetworkAccessManager and HTTP persistent
>> connection
>>
>> On Sat, Nov 23, 2013 at 7:15 PM, iMath <2281570...@qq.com> wrote:
>>> HTTP 1.1 supports persistent connection by default, so I want to send my
>>> a
>>> second http request using the same connection that was setup when the
>>> first
>>> HTTP request was made. how can this be achieved through Qt?
>>
>> I think you meant HTTP "pipelining" (that's the jargon used inside Qt
>> code). I'm not 100% sure but in Qt5, the default _should_ be to use
>> HTTP pipelining.
>>
>> In any case, you can explcitly check in the reply object if pipelining
>> was indeed used or not. Check for the
>> "QNetworkRequest::HttpPipeliningWasUsedAttribute" attribute in your
>> reply.
>>
>> Alternately, you can try and explicitly request this behaviour by
>> setting the n/w request attribute:
>>
>> request.setAttribute(QNetworkRequest::HttpPipeliningAllowedAttribute,
>> true);
>>
>> If it still doesn't work, then it might be a bug. What platform are
>> you running your on, BTW?
>>
>> HTH,
>> -mandeep
>>
>>
>>
>>>
>>> If I simply make the second request after the first one finished like the
>>> following
>>>
>>> QNetworkAccessManager *manager = new QNetworkAccessManager(this);
>>> connect(manager, SIGNAL(finished(QNetworkReply*)),
>>> this, SLOT(replyFinished(QNetworkReply*)));
>>>
>>> manager->get(QNetworkRequest(QUrl("http://qt-project.org")));
>>>
>>> it seems a new TCP connection to the server will be initiated (I have
>>> checked with a network sniffer) The experiment also says: If the reply is
>>> deleteLater() or abort() within finished() signal, the connection will be
>>> closed.
>>>
>>>
>>> _______________________________________________
>>> Interest mailing list
>>> Interest@qt-project.org
>>> http://lists.qt-project.org/mailman/listinfo/interest
>>>
_______________________________________________
Interest mailing list
Interest@qt-project.org
http://lists.qt-project.org/mailman/listinfo/interest