mhttpd - redirection from "old ODB paths" goes up one level too far

Create issue
Issue #173 resolved
Ben Smith created an issue

Commit 0a5c0da causes mhttpd to redirect users from the old ODB URL (e.g. http://host.ca/Logger) to the new-style URL (http://host.ca/?cmd=odb&odb_path=Logger). I am very very happy to see this feature.

Unfortunately, it seems to go up one level too far. My real-world example serves mhttpd beneath /midas:

Request: https://cdms-gw.triumf.ca/midas/Logger
Proxied to: http://localhost:8080/Logger
Redirected to: https://cdms-gw.triumf.ca/?cmd=odb&odb_path=Logger

It looks like the following logic works correctly:

         int level = 0;
         for (const char* s = dec_path; *s; s++) {
            if (*s == '/')
               level++;
         }
         std::string new_url;
         if (level == 0) {
            # Top-level directory like /Logger, (which appears in dec_path as "Logger")
            new_url += "./";
         } else {
            # Sub-directory
            for (int i=0; i<level; i++) {
               new_url += "../";
            }
         }
         new_url += "?cmd=odb";
         new_url += "&odb_path=";
         new_url += dec_path;
         //printf("redirect old odb path url [%s] to [%s]\n", dec_path, new_url.c_str());
         redirect(r, new_url.c_str());
         return;

The only exception I've found is the URL /root, which doesn't redirect to ?cmd=odb&odb_path=/. That was possibly unofficial behaviour anyway...

Comments (4)

  1. dd1

    Yes, I think you are right. I could not get consistent behaviour from my "../" counting code. I suspect this is because we use strange URLs. If the URLs were "https://gateway/blah/status.html", I think the counting would have worked, but our URL is "https://gateway/blah?cmd=blah" which is kind of a "directory" URL, not a page URL, and I never did understand how that is supposed to work.

    Eventually we will start using the URLs with the page name included: https://gateway/blah/{status,programs,alarm}.html and ".." counting will work, but in the mean time, I will see if I can use a different HTTP redirect instead.

    K.O.

  2. Log in to comment