#24834: Optional port in Host request header breaks get_current_site()
-------------------------------+------------------------------------
Reporter: ngnpope | Owner: ngnpope
Type: Bug | Status: assigned
Component: contrib.sites | Version: 1.5
Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 1
Easy pickings: 0 | UI/UX: 0
-------------------------------+------------------------------------
Comment (by ngnpope):
Fair enough. I can see that sites hosted on different ports might be
desirable to some, although it would be a minor use case. For more
background, my situation was a customer explicitly specifying a standard
port (80/443) for a web service request and an HTTP 500 error was thrown
out from the `CurrentSiteMiddleware` due to `Site.DoesNotExist` even
though the domain part of the host header would have correctly matched a
record in the database. Note that I do not configure `SITE_ID` as I want
the site record to be chosen automatically based on the request and
`SITE_ID` takes precedence.
Making these changes would mean that `Site.domain` is a bit of a misnomer,
but I don't think we would be able to change that to `Site.host` without
backwards incompatibility issues. C'est la vie.
Some questions:
- Would it make sense to always strip if the port is 80/443 or would you
definitely prefer to only do that as a last resort?
- Would it make sense to always strip any port so that you could have
`example.com` where the host is `example.com:8080` and the only port that
can be connected to is `8080`?
- I expect that we would need to make the documentation much clearer
regarding what values can be stored in `Site.domain`?
I feel that we want to ensure that people do not needlessly create
multiple records, e.g. `example.com`, `example.com:80` and
`example.com:443`. This may lead to confusion where other models have a
foreign key to `Site` and may lead to "missing" content.
--
Ticket URL: <https://code.djangoproject.com/ticket/24834#comment:5>
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 unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To post to this group, send email to [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/django-updates/065.1311ff4f099632ad219e652d29552ddb%40djangoproject.com.
For more options, visit https://groups.google.com/d/optout.