diff src/server/blog.py @ 1006:d0b27d1e2d50

server: moved code to retrieve external server from legacy blog to server.py, and use it to find websocket URL
author Goffi <goffi@goffi.org>
date Sat, 06 Jan 2018 12:37:56 +0100
parents fd4eae654182
children f2170536ba23
line wrap: on
line diff
--- a/src/server/blog.py	Fri Jan 05 16:30:05 2018 +0100
+++ b/src/server/blog.py	Sat Jan 06 12:37:56 2018 +0100
@@ -35,7 +35,6 @@
 import re
 import os
 import sys
-import urlparse
 import urllib
 
 from libervia.server.html_tools import sanitizeHtml, convertNewLinesToXHTML
@@ -391,37 +390,8 @@
             title = _(u"{user}'s blog").format(user=profile)
             feed_elt.addElement(u'title', content=title)
 
-            # to construct base blog url, we use base_url_ext if given by user
-            # and complete unknown parts with what we find in request's url
-            url_path = request.URLPath()
-            ext_data = self.host.base_url_ext_data
-            if request.requestHeaders.hasHeader('x-forwarded-host'):
-                # we are behing a proxy
-                # we fill proxy_scheme and proxy_netloc value
-                proxy_host = request.requestHeaders.getRawHeaders('x-forwarded-host')[0]
-                try:
-                    proxy_server = request.requestHeaders.getRawHeaders('x-forwarded-server')[0]
-                except TypeError:
-                    # no x-forwarded-server found, we use proxy_host
-                    proxy_netloc = proxy_host
-                else:
-                    # if the proxy host has a port, we use it with server name
-                    proxy_port = urlparse.urlsplit('//{}'.format(proxy_host)).port
-                    proxy_netloc = '{}:{}'.format(proxy_server, proxy_port) if proxy_port is not None else proxy_server
-                proxy_netloc = proxy_netloc.decode('utf-8')
-                try:
-                    proxy_scheme = request.requestHeaders.getRawHeaders('x-forwarded-proto')[0].decode('utf-8')
-                except TypeError:
-                    proxy_scheme = None
-            else:
-                proxy_scheme, proxy_netloc = None, None
-
-            base_blog_url = urlparse.urlunsplit((
-                ext_data.scheme or proxy_scheme or url_path.scheme.decode('utf-8'),
-                ext_data.netloc or proxy_netloc or url_path.netloc.decode('utf-8'),
-                u'{}blog/{user}'.format(ext_data.path or u'/', user=profile),
-                '',
-                ''))
+            base_blog_url = self.host.getExtBaseURL(request,
+                u'blog/{user}'.format(user=profile))
 
             # atom link
             link_feed_elt = feed_elt.addElement('link')