These are chat archives for cherrypy/cherrypy

31st
Dec 2016
Sviatoslav Sydorenko
@webknjaz
Dec 31 2016 04:23
@jaraco there are lots of questions about having URL resolution. it seems to me that we should design some subsystem allowing to implement url_for across the app regardless of the dispatchers being used
Jason R. Coombs
@jaraco
Dec 31 2016 20:59
@webknjaz Perhaps. I guess it depends on what that entails. I know there’s already a cherrypy.url() which does some form of URL resolution. But if there’s another set of use cases that CherryPy can solve as a framework, that also sounds reasonable.
Sviatoslav Sydorenko
@webknjaz
Dec 31 2016 21:14

@jaraco Yeah, there are some cases I've faced personally.

For example, if running behind the proxy (nginx) URI-based redirects (raise HTTPRedirect) try to construct the complete URL based on the information that the app is running on localhost's port and while it is served as https://some.site/ externally redirects may set Location: header to http://localhost:8080/some_path (note the difference in 1. scheme, 2. FQDN, 3. port).

Also it would be nice to have some url names, so that one could insert urls in their templates and code. Just like {% url 'somename' id=3 %} in django or {{ url_for('somename', id=3) }} in others.

I've built some kind of an ugly urlmap to do this, which runs at the start (as a plugin) and analyzes the mount tree:
https://github.com/GDG-Ukraine/gdg.org.ua/blob/master/src/GDGUkraine/lib/utils/url.py
https://github.com/GDG-Ukraine/gdg.org.ua/blob/master/src/GDGUkraine/lib/plugins/urlmap.py
But I really want to have something smarter and much more generic.

Jason R. Coombs
@jaraco
Dec 31 2016 22:10
I think the cherrypy.url is meant to provide that functionality, with tools supporting the adaptation of scheme and hostname and port. I’m not sure, though, how well it works for dispatchers other than the default dispatcher.
Sviatoslav Sydorenko
@webknjaz
Dec 31 2016 23:10
it doesn't provide anything I really need at all) thus I had to invent crutches..