#7930: FORCE_SCRIPT_NAME does not work with dev server
-------------------------------+------------------------------------
Reporter: ElliottM | Owner: nobody
Type: Bug | Status: reopened
Component: HTTP handling | Version: master
Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------+------------------------------------
Changes (by nkryptic):
* cc: nkryptic (added)
Comment:
Im attaching a patch, but you can also view the work on Github at
https://github.com/nkryptic/django/commit/71921091981fc187831550a37d5b65cf76039b16
I think this issue is more widespread than just the development
`runserver` command. Changing `FORCE_SCRIPT_NAME` will also break the
`LiveServerTestCase`. Finally, it looks like there is an issue if you
change `FORCE_SCRIPT_NAME` with `override_settings` while testing, if the
test does any request processing and therefore calls
`django.core.urlresolvers.set_script_prefix`. SInce `set_script_prefix`
changes the global `_prefixes` object, it doesn't get unset and will
remain present for tests afterwards. The patch includes a test signal
handler for `setting_changed` which addresses this.
What the patch does is add a new `UrlPrefixedAwareHandler` that is applied
in the base `runserver` command, wrapping the normal handler. This wsgi
middleware only performs when `FORCE_SCRIPT_NAME` is present. If it is,
the script will ensure incoming requests begin with `FORCE_SCRIPT_NAME`
and then strip it from then environ's `PATH_INFO` before passing environ
on to the normal handler. If the incoming request doesn't begin with
`FORCE_SCRIPT_NAME`, a 400 Bad Request is raised.
Also, the `StaticFilesHandler` has to become aware of `FORCE_SCRIPT_NAME`,
as it will check both the `PATH_INFO` from the incoming environ and also
`request.path` later (which will be prepended with `FORCE_SCRIPT_NAME`).
I don't know if the new tests written are enough to ensure this patch's
validity, or if there is need for additional documentation from this. I
open to suggestions. I'd also be happy to claim this issue, although I
didn't see an 'accept' option, even though it is owned by nobody.
--
Ticket URL: <https://code.djangoproject.com/ticket/7930#comment:10>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.
--
You received this message because you are subscribed to the Google Groups
"Django updates" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit https://groups.google.com/groups/opt_out.