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. to the new-style URL ( 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:

Proxied to: http://localhost:8080/Logger
Redirected to:

It looks like the following logic works correctly:

         int level = 0;
         for (const char* s = dec_path; *s; s++) {
            if (*s == '/')
         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());

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.


  2. dd1

    I am not sure who processed the URL "/root". I suspect it was used for ODB URLs https://gateway/blah/ODBPATH to get to the ODB top level, ODBPATH "/" or "" (for top level) yield https://gateway/blah/ and takes us to the status page. So "/root" was tacked at the end. I guess I need to put this back... K.O.

  3. Log in to comment