Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. [Solved] QNAM : check if range header supported
Forum Updated to NodeBB v4.3 + New Features

[Solved] QNAM : check if range header supported

Scheduled Pinned Locked Moved General and Desktop
13 Posts 3 Posters 3.0k Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • A Offline
    A Offline
    ashishbansal
    wrote on 28 Dec 2014, 12:07 last edited by
    #1

    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

    1 Reply Last reply
    0
    • C Online
      C Online
      Chris Kawa
      Lifetime Qt Champion
      wrote on 28 Dec 2014, 12:13 last edited by
      #2

      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.

      1 Reply Last reply
      0
      • P Offline
        P Offline
        p3c0
        Moderators
        wrote on 28 Dec 2014, 12:13 last edited by
        #3

        Hi,

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

        157

        1 Reply Last reply
        0
        • A Offline
          A Offline
          ashishbansal
          wrote on 28 Dec 2014, 12:27 last edited by
          #4

          [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??

          1 Reply Last reply
          0
          • A Offline
            A Offline
            ashishbansal
            wrote on 28 Dec 2014, 12:28 last edited by
            #5

            [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.

            1 Reply Last reply
            0
            • C Online
              C Online
              Chris Kawa
              Lifetime Qt Champion
              wrote on 28 Dec 2014, 12:33 last edited by
              #6

              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.

              1 Reply Last reply
              0
              • A Offline
                A Offline
                ashishbansal
                wrote on 28 Dec 2014, 12:37 last edited by
                #7

                [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!

                1 Reply Last reply
                0
                • P Offline
                  P Offline
                  p3c0
                  Moderators
                  wrote on 28 Dec 2014, 13:02 last edited by
                  #8

                  @ashishbansal may we know which URL are you trying ?

                  157

                  1 Reply Last reply
                  0
                  • A Offline
                    A Offline
                    ashishbansal
                    wrote on 28 Dec 2014, 13:12 last edited by
                    #9

                    [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.
                    @()
                    () @

                    1 Reply Last reply
                    0
                    • C Online
                      C Online
                      Chris Kawa
                      Lifetime Qt Champion
                      wrote on 28 Dec 2014, 13:15 last edited by
                      #10

                      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.

                      1 Reply Last reply
                      0
                      • A Offline
                        A Offline
                        ashishbansal
                        wrote on 28 Dec 2014, 13:21 last edited by
                        #11

                        [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.

                        1 Reply Last reply
                        0
                        • P Offline
                          P Offline
                          p3c0
                          Moderators
                          wrote on 28 Dec 2014, 13:27 last edited by
                          #12

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

                          157

                          1 Reply Last reply
                          0
                          • A Offline
                            A Offline
                            ashishbansal
                            wrote on 28 Dec 2014, 13:31 last edited by
                            #13

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

                            Yeah I realized that silly mistake.
                            Thanks!

                            1 Reply Last reply
                            0

                            1/13

                            28 Dec 2014, 12:07

                            • Login

                            • Login or register to search.
                            1 out of 13
                            • First post
                              1/13
                              Last post
                            0
                            • Categories
                            • Recent
                            • Tags
                            • Popular
                            • Users
                            • Groups
                            • Search
                            • Get Qt Extensions
                            • Unsolved