[Interest] QNetworkAccessManager and HTTP persistent connection

Mandeep Sandhu mandeepsandhu.chd at gmail.com
Tue Nov 26 13:20:15 CET 2013


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 <2281570025 at 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.chd at gmail.com>;
> Date:  Tue, Nov 26, 2013 02:14 PM
> To:  "iMath"<2281570025 at qq.com>;
> Cc:  "interest"<interest at qt-project.org>;
> Subject:  Re: [Interest] QNetworkAccessManager and HTTP persistent
> connection
>
> On Sat, Nov 23, 2013 at 7:15 PM, iMath <2281570025 at 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 at qt-project.org
>> http://lists.qt-project.org/mailman/listinfo/interest
>>



More information about the Interest mailing list