Mercurial > libervia-web
comparison 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 |
comparison
equal
deleted
inserted
replaced
1005:b6dc6cf76473 | 1006:d0b27d1e2d50 |
---|---|
33 from jinja2 import Environment, PackageLoader | 33 from jinja2 import Environment, PackageLoader |
34 from datetime import datetime | 34 from datetime import datetime |
35 import re | 35 import re |
36 import os | 36 import os |
37 import sys | 37 import sys |
38 import urlparse | |
39 import urllib | 38 import urllib |
40 | 39 |
41 from libervia.server.html_tools import sanitizeHtml, convertNewLinesToXHTML | 40 from libervia.server.html_tools import sanitizeHtml, convertNewLinesToXHTML |
42 from libervia.server.constants import Const as C | 41 from libervia.server.constants import Const as C |
43 | 42 |
389 items, metadata= data | 388 items, metadata= data |
390 feed_elt = domish.Element((NS_ATOM, u'feed')) | 389 feed_elt = domish.Element((NS_ATOM, u'feed')) |
391 title = _(u"{user}'s blog").format(user=profile) | 390 title = _(u"{user}'s blog").format(user=profile) |
392 feed_elt.addElement(u'title', content=title) | 391 feed_elt.addElement(u'title', content=title) |
393 | 392 |
394 # to construct base blog url, we use base_url_ext if given by user | 393 base_blog_url = self.host.getExtBaseURL(request, |
395 # and complete unknown parts with what we find in request's url | 394 u'blog/{user}'.format(user=profile)) |
396 url_path = request.URLPath() | |
397 ext_data = self.host.base_url_ext_data | |
398 if request.requestHeaders.hasHeader('x-forwarded-host'): | |
399 # we are behing a proxy | |
400 # we fill proxy_scheme and proxy_netloc value | |
401 proxy_host = request.requestHeaders.getRawHeaders('x-forwarded-host')[0] | |
402 try: | |
403 proxy_server = request.requestHeaders.getRawHeaders('x-forwarded-server')[0] | |
404 except TypeError: | |
405 # no x-forwarded-server found, we use proxy_host | |
406 proxy_netloc = proxy_host | |
407 else: | |
408 # if the proxy host has a port, we use it with server name | |
409 proxy_port = urlparse.urlsplit('//{}'.format(proxy_host)).port | |
410 proxy_netloc = '{}:{}'.format(proxy_server, proxy_port) if proxy_port is not None else proxy_server | |
411 proxy_netloc = proxy_netloc.decode('utf-8') | |
412 try: | |
413 proxy_scheme = request.requestHeaders.getRawHeaders('x-forwarded-proto')[0].decode('utf-8') | |
414 except TypeError: | |
415 proxy_scheme = None | |
416 else: | |
417 proxy_scheme, proxy_netloc = None, None | |
418 | |
419 base_blog_url = urlparse.urlunsplit(( | |
420 ext_data.scheme or proxy_scheme or url_path.scheme.decode('utf-8'), | |
421 ext_data.netloc or proxy_netloc or url_path.netloc.decode('utf-8'), | |
422 u'{}blog/{user}'.format(ext_data.path or u'/', user=profile), | |
423 '', | |
424 '')) | |
425 | 395 |
426 # atom link | 396 # atom link |
427 link_feed_elt = feed_elt.addElement('link') | 397 link_feed_elt = feed_elt.addElement('link') |
428 link_feed_elt['href'] = u'{base}/atom.xml'.format(base=base_blog_url) | 398 link_feed_elt['href'] = u'{base}/atom.xml'.format(base=base_blog_url) |
429 link_feed_elt['type'] = u'application/atom+xml' | 399 link_feed_elt['type'] = u'application/atom+xml' |