[Solved] QNAM : check if range header supported



  • Is there any method from which I can know if host supports Range Header before sending it get request??

    @QNetworkAccessManager::get(QNetworkRequest) //before this@

    I want to know if it supports then I want to download some parts of the file, otherwise the full file. If I once made get request, it is gonna download it only that way.
    Any solution??

    Thanks
    Ashish Bansal


  • Moderators

    You can't know anything about the server before contacting it. The only way to check if it supports partial content is to ask for some, ideally a small part of small file not to wait and waste bandwidth if it sends the whole thing. If the server supports partial content it will respond with 206 status code instead of the usual 200.


  • Moderators

    Hi,

    Try with "QNetworkAccessManager::​head":http://doc.qt.io/qt-5/qnetworkaccessmanager.html#head. Then in reply you can check for the particular header.



  • [quote author="Chris Kawa" date="1419768795"]You can't know anything about the server before contacting it. The only way to check if it supports partial content is to ask for some, ideally a small part of small file not to wait and waste bandwidth if it sends the whole thing. If the server supports partial content it will respond with 206 status code instead of the usual 200.[/quote]

    Okay. Thanks!
    How can I check those status code and I have read somewhere some servers does not sends 206 but supports that header. Is there any way to tackle that??



  • [quote author="p3c0" date="1419768801"]Hi,

    Try with "QNetworkAccessManager::​head":http://doc.qt.io/qt-5/qnetworkaccessmanager.html#head. Then in reply you can check for the particular header.[/quote]

    Hey I just tried that but the reply is returning empty rawHeaderList.


  • Moderators

    bq. How can I check those status code

    @
    //reply is the QNetworkReply*
    reply->attribute(QNetworkRequest::HttpStatusCodeAttribute);
    @

    As for the broken servers you'd have to compare sizes. Request for e.g. 1 byte of a larger file and see if you get the byte or the whole thing in reply.



  • [quote author="Chris Kawa" date="1419770030"]bq. How can I check those status code

    @
    //reply is the QNetworkReply*
    reply->attribute(QNetworkRequest::HttpStatusCodeAttribute);
    @

    As for the broken servers you'd have to compare sizes. Request for e.g. 1 byte of a larger file and see if you get the byte or the whole thing in reply.[/quote]

    Okay, Cool!
    Thanks again!


  • Moderators

    @ashishbansal may we know which URL are you trying ?



  • [quote author="p3c0" date="1419771749"]ashishbansal may we know which URL are you trying ?[/quote]

    I have tried with these two links : http://ashish-bansal.in/css/loader.css and
    https://s.basketbuild.com/dl/devs?dl=pawitp/i9082_cm12.0/cm-12-20141220-UNOFFICIAL-i9082.zip

    And like this.

    @QNetworkReply *headReply = qnam->head(*req);
    qDebug() << headReply->rawHeaderList();@

    And I am getting this as output.
    @()
    () @


  • Moderators

    You can't check any contents of the reply before it arrives. Neither the method I gave nor that one will work this way. You need to connect to the finished() signal of the reply and check then.



  • [quote author="Chris Kawa" date="1419772556"]You can't check the contents of the reply before it arrives. Neither the method I gave nor that one will work this way. You need to connect to the finished() signal of the reply and check then.[/quote]

    Oh that's why that method didn't worked. While testing your method, I made the changes in slot connected to QNetworkReply::downloadProgress . That's why it worked.


  • Moderators

    QNetworkAccessManager::​head works as expected for those URL's.



  • [quote author="p3c0" date="1419773224"]QNetworkAccessManager::​head works as expected for those URL's.[/quote]

    Yeah I realized that silly mistake.
    Thanks!


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.