HISE Logo Forum
    • Categories
    • Register
    • Login

    Setting server headers for downloads

    Scheduled Pinned Locked Moved Scripting
    23 Posts 3 Posters 2.7k Views
    Loading More Posts
    • 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.
    • d.healeyD
      d.healey
      last edited by

      Does the Server.setHttpHeader() function apply to downloads as well as GET/POST?

      Free HISE Bootcamp Full Course for beginners.
      YouTube Channel - Public HISE tutorials
      My Patreon - HISE tutorials

      1 Reply Last reply Reply Quote 0
      • d.healeyD
        d.healey
        last edited by d.healey

        Bump bump - user token doesn't seem to be sent when downloading files.

        Free HISE Bootcamp Full Course for beginners.
        YouTube Channel - Public HISE tutorials
        My Patreon - HISE tutorials

        ustkU 1 Reply Last reply Reply Quote 0
        • ustkU
          ustk @d.healey
          last edited by ustk

          @d-healey Do you mean the parameters object is not sent using Server.downloadFile(...)?

          Hise made me an F5 dude, browser just suffers...

          d.healeyD 1 Reply Last reply Reply Quote 0
          • d.healeyD
            d.healey @ustk
            last edited by

            @ustk No I want to know if Server.setHttpHeaders has an effect on Server.downloadFile. My WooCommerce site is set to only allow downloads for logged in users, so I send the token along in a header before starting the download, but it doesn't accept it as the user being logged in so the server throws an error.

            Free HISE Bootcamp Full Course for beginners.
            YouTube Channel - Public HISE tutorials
            My Patreon - HISE tutorials

            ustkU 2 Replies Last reply Reply Quote 0
            • ustkU
              ustk @d.healey
              last edited by

              @d-healey I can't help much. Are you sure you respected the object format for the token you are sending?

              Hise made me an F5 dude, browser just suffers...

              d.healeyD 1 Reply Last reply Reply Quote 0
              • ustkU
                ustk @d.healey
                last edited by ustk

                @d-healey Shouldn't the token be sent from the download function instead of the header?
                Just saying shit, sorry...

                Hise made me an F5 dude, browser just suffers...

                1 Reply Last reply Reply Quote 0
                • d.healeyD
                  d.healey @ustk
                  last edited by

                  @ustk said in Setting server headers for downloads:

                  Are you sure you respected the object format for the token you are sending?

                  Yeah, it works for all my POST and GET requests.

                  Free HISE Bootcamp Full Course for beginners.
                  YouTube Channel - Public HISE tutorials
                  My Patreon - HISE tutorials

                  ustkU 1 Reply Last reply Reply Quote 1
                  • ustkU
                    ustk @d.healey
                    last edited by

                    @d-healey So the pendingDownload doesn't take a extraHeader parameter like the pendingCallbackdoes...
                    I don't see how to add this though, because their structures are different... @Christoph-Hart's the guy we need :)

                    Hise made me an F5 dude, browser just suffers...

                    d.healeyD 1 Reply Last reply Reply Quote 1
                    • d.healeyD
                      d.healey @ustk
                      last edited by

                      @ustk Yeah I had a look myself and came to the same conclusion :)

                      Free HISE Bootcamp Full Course for beginners.
                      YouTube Channel - Public HISE tutorials
                      My Patreon - HISE tutorials

                      ustkU 1 Reply Last reply Reply Quote 0
                      • ustkU
                        ustk @d.healey
                        last edited by

                        @d-healey In fact it seems doable, but then I can't test it as my woo-commerce isn't ready...

                        Try to add

                        String extraHeader;
                        

                        inside the ScriptDownloadObject struct (between line 384-389 in ScriptingApiObjects.h)

                        and

                        newDownload->extraHeader = extraHeader;
                        

                        at line 54 of GlobalServer.cpp

                        And cross your fingers 🤣

                        Hise made me an F5 dude, browser just suffers...

                        d.healeyD 1 Reply Last reply Reply Quote 0
                        • d.healeyD
                          d.healey @ustk
                          last edited by

                          Thanks, I'll try it now!

                          @ustk said in Setting server headers for downloads:

                          I can't test it as my woo-commerce isn't ready...

                          You should setup a local server for testing using something like XAMPP if you're going to be working with the Server API a lot.

                          Free HISE Bootcamp Full Course for beginners.
                          YouTube Channel - Public HISE tutorials
                          My Patreon - HISE tutorials

                          ustkU 1 Reply Last reply Reply Quote 1
                          • ustkU
                            ustk @d.healey
                            last edited by

                            @d-healey Yeah thanks, I don't know anything about servers and web stuff, but I take your words for it :)

                            Hise made me an F5 dude, browser just suffers...

                            1 Reply Last reply Reply Quote 1
                            • d.healeyD
                              d.healey
                              last edited by

                              Didn't work unfortunately.

                              Free HISE Bootcamp Full Course for beginners.
                              YouTube Channel - Public HISE tutorials
                              My Patreon - HISE tutorials

                              ustkU 2 Replies Last reply Reply Quote 0
                              • ustkU
                                ustk @d.healey
                                last edited by

                                @d-healey Oh I think that's because the extraHeader has to be linked to the pendingCallback one, or we need to create a new one somehow. I think we're close ;)

                                Hise made me an F5 dude, browser just suffers...

                                1 Reply Last reply Reply Quote 0
                                • ustkU
                                  ustk @d.healey
                                  last edited by

                                  @d-healey So I think you we need to create a new method for setting the header specific to downloadObject, so try adding a method like this to the ScriptingApiObjects.h

                                  void setDownloadHttpHeader(String newHeader)
                                  {
                                      extraHeader = newHeader;
                                  }
                                  

                                  Hise made me an F5 dude, browser just suffers...

                                  d.healeyD 1 Reply Last reply Reply Quote 0
                                  • d.healeyD
                                    d.healey @ustk
                                    last edited by

                                    @ustk The download object doesn't exist until after the call to Server.downloadFile. So by then it will be too late to set the header.

                                    Free HISE Bootcamp Full Course for beginners.
                                    YouTube Channel - Public HISE tutorials
                                    My Patreon - HISE tutorials

                                    ustkU 2 Replies Last reply Reply Quote 1
                                    • ustkU
                                      ustk @d.healey
                                      last edited by

                                      @d-healey I don't understand why two extraHeader are declared, one in the pendingCallback and one below in private. I imagine the one that is used is the private one. So we shouldn't declared it in the ScriptingApiObject.
                                      This means that just passing it insed the addDownload (newDownload->extraHeader = extraHeader;) should be enough, just before adding a pending download as it is done for the pendingCallback.

                                      Hise made me an F5 dude, browser just suffers...

                                      1 Reply Last reply Reply Quote 0
                                      • ustkU
                                        ustk @d.healey
                                        last edited by

                                        @d-healey I think it should be passed to these inputStream calls instead of String():

                                        in start

                                        auto wis = downloadURL.createInputStream(false, nullptr, nullptr, String(), HISE_SCRIPT_SERVER_TIMEOUT, nullptr, &status);
                                        

                                        and in resume

                                        auto wis = downloadURL.createInputStream(false, nullptr, nullptr, String(), 0, nullptr, &status);
                                        

                                        Hise made me an F5 dude, browser just suffers...

                                        d.healeyD 1 Reply Last reply Reply Quote 1
                                        • d.healeyD
                                          d.healey @ustk
                                          last edited by

                                          @ustk Replacing String() with the token didn't work :(

                                          Free HISE Bootcamp Full Course for beginners.
                                          YouTube Channel - Public HISE tutorials
                                          My Patreon - HISE tutorials

                                          ustkU 1 Reply Last reply Reply Quote 0
                                          • ustkU
                                            ustk @d.healey
                                            last edited by

                                            @d-healey I'm definitely out of ideas now 🙄

                                            Hise made me an F5 dude, browser just suffers...

                                            d.healeyD 1 Reply Last reply Reply Quote 1
                                            • First post
                                              Last post

                                            18

                                            Online

                                            2.0k

                                            Users

                                            12.7k

                                            Topics

                                            110.0k

                                            Posts