http_well_known: have absolute URI at Location header
RFC-2616 suggests that the Location URI must be absolute. However, as a server, we can not know if the client called us as "http://" or "webdav://" or else.. Pending some more change to get the ssl scheme from the calling classes. bzr revid: p_christ@hol.gr-20101123185251-qxjgsq2c8bl12puy
This commit is contained in:
parent
5c6f324697
commit
7db1504d7c
|
@ -21,6 +21,7 @@
|
|||
|
||||
|
||||
import logging
|
||||
import urlparse
|
||||
from service.websrv_lib import FixSendError, HTTPHandler, HttpOptions
|
||||
from service.http_server import HttpLogHandler
|
||||
|
||||
|
@ -53,8 +54,25 @@ class RedirectHTTPHandler(HttpLogHandler, FixSendError, HttpOptions, HTTPHandler
|
|||
self.send_error(404, "File not found")
|
||||
return None
|
||||
|
||||
addr, port = self.server.server_name, self.server.server_port
|
||||
try:
|
||||
addr, port = self.request.getsockname()
|
||||
except Exception, e:
|
||||
self.log_error("Cannot calculate own address:" , e)
|
||||
|
||||
if self.headers.has_key('Host'):
|
||||
uparts = list(urlparse.urlparse("http://%s:%d"% (addr,port)))
|
||||
uparts[1] = self.headers['Host']
|
||||
baseuri = urlparse.urlunparse(uparts)
|
||||
else:
|
||||
baseuri = "http://%s:%d"% (addr, port )
|
||||
|
||||
|
||||
location = baseuri + self.redirect_paths[self.path]
|
||||
# relative uri: location = self.redirect_paths[self.path]
|
||||
|
||||
self.send_response(301)
|
||||
self.send_header("Location", self.redirect_paths[self.path])
|
||||
self.send_header("Location", location)
|
||||
self.send_header("Content-Length", 0)
|
||||
self.end_headers()
|
||||
# Do we need a Cache-content: header here?
|
||||
|
|
Loading…
Reference in New Issue