HISE Logo Forum
    • Categories
    • Register
    • Login

    HISE adds trailing slash to server post calls

    Scheduled Pinned Locked Moved Bug Reports
    server apiserverbug
    10 Posts 4 Posters 805 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.
    • oskarshO
      oskarsh
      last edited by

      HISE adds a trailing slash to the end of every route for post calls.

      So:
      POST www.example.com/test

      will become
      POST www.example.com/test/

      I think its not correct to add a trailing slash automatically because its not the same route in the end. I am working on a project with supabase which automatically generates the routes based on the table schema which does not add a trailing slash to every route.

      This is the code in the ScriptingApi callWithPost function.

      const bool isNotAFile = !subURL.containsChar('.');
      const bool trailingSlashMissing = !subURL.endsWithChar('/');
              
       if(isNotAFile && trailingSlashMissing)
      {
              // We need to append a slash in order to prevent redirecting to a GET call
              subURL << '/';
      }
      

      I've removed that code and its working in HISE I can use the correct routes without the added /. However when exporting my app to a standalone or a vst I get no network calls in my app.

      What do you think should POST call automatically add a trailing slash?

      breathing HISE

      Christoph HartC 1 Reply Last reply Reply Quote 0
      • Christoph HartC
        Christoph Hart @oskarsh
        last edited by

        @oskarsh It's been a while since I've wrote this, so I might not remember the details (however the comment suggests there was a nasty bug when not appending slashes). IIRC it was something that didn't work on macOS - if you forget to add a trailing slash, the Windows server call still goes through, so that was my lousy attempt of making it consistent.

        My knowledge of server / web APIs is very limited, so if you have a suggestion how to improve that, let me know.

        oskarshO 1 Reply Last reply Reply Quote 0
        • oskarshO
          oskarsh @Christoph Hart
          last edited by

          @Christoph-Hart I cannot comment on the actual architecture since I am not proficient in C++ enough but it seems like you are using a simple wrapper around the JUCE code and a queue for the requests to pass thru.

          There is also this line:
          p->isPost = true;

          so the request that is sent to the server contains the information. I think the problem is in this function [0]:

          void ScriptingApi::Server::callWithPOST(String subURL, var parameters, var callback)
          {
          	if (HiseJavascriptEngine::isJavascriptFunction(callback))
          	{
          		GlobalServer::PendingCallback::Ptr p = new GlobalServer::PendingCallback(getScriptProcessor(), callback);
          		p->url = getWithParameters(subURL, parameters); <- should be withPOSTData
          		p->isPost = true;
          		globalServer.addPendingCallback(p);
          	}
          }
          

          I think the getWithParameter call should be withPOSTData [1].

          I believe its save to remove the trailing slash code like I did. I can verify its working on Linux and Windows. I think the code needs a slight modification to use withPOSTData instead of getWithParameter. Sadly I cannot verify this on MacOS since I do not have access to my macbook right now.

          [0] -> https://github.com/christophhart/HISE/blob/2d88ad47af71047dede7769b9794f0707aed83d4/hi_scripting/scripting/api/ScriptingApi.cpp#L6983
          [1] -> https://docs.juce.com/master/classURL.html#a424c1066a6e5c978ca7bdfab2a757889#withPOSTData

          breathing HISE

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

            I just hit this problem too. My rest endpoint doesn't have the slash, but HISE adds it so my call doesn't work. I'm trying to tackle it from the other end by adding the slash to my endpoint.

            Libre Wave - Freedom respecting instruments and effects
            My Patreon - HISE tutorials
            YouTube Channel - Public HISE tutorials

            oskarshO 1 Reply Last reply Reply Quote 0
            • oskarshO
              oskarsh @d.healey
              last edited by

              @d-healey while adding a slash to the endpoint certainly works i still believe that it's very bad practice to alter the called url automatically. From my experience as a web developer many rest API s do not contain a slash at the end and it's not the same rest url in the end. However there is no official standard.

              I would very much welcome if this issue gets a second look. I tested my modification on Linux and Windows and it works well but I had no chance of testing macos yet for any side effects.

              Link Preview Image
              RESTful URI trailing slash or no trailing slash

              Is there an authoritative position I can cite when it comes to a trailing slash on a Restful URI? One from Roy Fielding would be great. The web has authoritative opinions both ways. The two pos...

              favicon

              Stack Overflow (stackoverflow.com)

              breathing HISE

              Christoph HartC 1 Reply Last reply Reply Quote 0
              • Christoph HartC
                Christoph Hart @oskarsh
                last edited by

                @oskarsh alright, so what we leave the default as it is, but add a Server.setUseTrailingSlash(true) function that let's you disable that project-wise?

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

                  @Christoph-Hart I like it

                  Libre Wave - Freedom respecting instruments and effects
                  My Patreon - HISE tutorials
                  YouTube Channel - Public HISE tutorials

                  Christoph HartC 1 Reply Last reply Reply Quote 0
                  • Christoph HartC
                    Christoph Hart @d.healey
                    last edited by

                    @d-healey Alright, I've added Server.setEnforceTrailingSlash(bool shouldBeAdded)so you can change this.

                    It won't show up in the API yet, so it's a magic spell until I'll rebuild the API docs on a Windows system :)

                    oskarshO 1 Reply Last reply Reply Quote 2
                    • oskarshO
                      oskarsh @Christoph Hart
                      last edited by

                      @Christoph-Hart Thanks Christoph for jumping onto this so quickly. Its working well on my end!

                      breathing HISE

                      1 Reply Last reply Reply Quote 0
                      • A
                        aaronventure
                        last edited by

                        small necro to report that there's a leading slash issue which can only be mitigated by setBaseURL

                        35dd898e-aac5-4c93-8883-d43f11969774-image.png

                        1 Reply Last reply Reply Quote 0
                        • First post
                          Last post

                        56

                        Online

                        1.7k

                        Users

                        11.7k

                        Topics

                        101.9k

                        Posts