mhttpd - redirection from "old ODB paths" goes up one level too far
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)
-
-
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.
-
- changed status to resolved
-
just updated it on CERN agdaq, and the redirect is working. Thanks for this fix. K.O.
- Log in to comment
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.