ontodev / droid

DROID Reminds us that Ordinary Individuals can be Developers
BSD 3-Clause "New" or "Revised" License
4 stars 1 forks source link

Consider setting the CGI SCRIPT_NAME to the URL path #124

Closed jamesaoverton closed 2 years ago

jamesaoverton commented 2 years ago

Currently when running a Flask app under CGI, we need to override the SCRIPT_NAME before calling the CGIHandler, like so:

https://github.com/ontodev/nanobot/blob/main/nanobot/run.py#L1823

If we do not, Flask will redirect to a weird URL that includes the absolute script path, such as https://droid.ontodev.com/var/www/droid.ontodev.com/projects/ODD/workspace/fix-1/test.py/?project-name=ODD&branch-name=fix-1&view-path=test.py when we want https://droid.ontodev.com/ODD/branches/fix-1/views/test.py

As in #123 we should consult the CGI spec, but this seems harmless.

lmcmicu commented 2 years ago

FYI here is what the CGI spec says:

SCRIPT_NAME

      A URL path that could identify the CGI script (rather then the
      particular CGI output). The syntax and semantics are identical to
      a decoded HTTP URL `hpath' token [[4](https://datatracker.ietf.org/doc/html/draft-robinson-www-interface-00#ref-4)].

         SCRIPT_NAME = "" | "/" [ path ]

      The leading "/" is not part of the path. It is optional if the
      path is NULL.

      The SCRIPT_NAME string is some leading part of the <path>
      component of the script URI derived in some implementation defined
      manner.

This doesn't seem inconsistent with the way that you are proposing to use it, agreed?

lmcmicu commented 2 years ago

The reason that Flask redirects, if you do not override SCRIPT_PATH, to the weird URL mentioned above which includes the script's absolute path, is because DROID is adding the absolute path.

It shouldn't be difficult to set it to the URL path (in the above example: https://droid.ontodev.com/ODD/branches/fix-1/views/test.py)