'Functionality that medusa\'s http request doesn\'t have; set an
attribute named \'server_url\' on the request based on the Host: header'

def get_server_url(self):

    default_port = {'http': '80', 'https': '443'}
    environ = self.cgi_environment()
    if ((environ.get('HTTPS') in ('on', 'ON')) or (environ.get('SERVER_PORT_SECURE') == '1')):
        protocol = 'https'
    else:
        protocol = 'http'
    if ('HTTP_HOST' in environ):
        host = environ['HTTP_HOST'].strip()
        (hostname, port) = urllib.splitport(host)
    else:
        hostname = environ['SERVER_NAME'].strip()
        port = environ['SERVER_PORT']
    if ((port is None) or (default_port[protocol] == port)):
        host = hostname
    else:
        host = ((hostname + ':') + port)
    server_url = ('%s://%s' % (protocol, host))
    if (server_url[(-1):] == '/'):
        server_url = server_url[:(-1)]
    return server_url
