Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Python Twisted How do I determine an absolute URL?

Tags:

python

twisted

I need to generate an absolute URL to a resource while handling a web request in Twisted. The host, port, and protocol (HTTP/HTTPS) can all vary based on deployment, so it would be really convenient to look things up dynamically.

The URL I need to is a modification of the url of the resource currently being processed with all arguments stripped away, so just finding the full request URL would help a lot.

In other words, I know "/path/foo", but how do I find "http://example.com:8080"?

like image 612
DonGar Avatar asked Oct 23 '25 12:10

DonGar


1 Answers

The Request passed in to lots of Twisted Web server APIs has a URLPath method that returns an instance of twisted.python.urlpath.URLPath. The string representation of a URLPath instance is a string like "http://example.com:8080/foo/bar".

like image 104
Jean-Paul Calderone Avatar answered Oct 25 '25 01:10

Jean-Paul Calderone