From 382ef961c46e7677c7d467f6cce890bd5ed23bda Mon Sep 17 00:00:00 2001 From: Rushabh Mehta Date: Tue, 17 Sep 2013 15:16:01 +0530 Subject: [PATCH] [wsgi] [minor] fixed request host name --- webnotes/app.py | 5 +++-- webnotes/auth.py | 2 +- webnotes/install_lib/setup_public_folder.py | 1 - webnotes/modules/patch_handler.py | 2 +- webnotes/utils/__init__.py | 1 + website/templates/pages/rss.py | 5 ++--- website/templates/pages/sitemap.py | 5 ++--- 7 files changed, 10 insertions(+), 11 deletions(-) diff --git a/webnotes/app.py b/webnotes/app.py index b114385c98..431914aa4c 100644 --- a/webnotes/app.py +++ b/webnotes/app.py @@ -1,6 +1,6 @@ import sys, os -sys.path.extend(["..", "../app", "../lib"]) +sys.path.extend([".", "app", "lib"]) from werkzeug.wrappers import Request, Response from werkzeug.local import LocalManager @@ -17,8 +17,9 @@ local_manager = LocalManager([webnotes.local]) @Request.application def application(request): webnotes.local.request = request + webnotes.init() - + webnotes.local.form_dict = webnotes._dict({ k:v[0] if isinstance(v, (list, tuple)) else v \ for k, v in (request.form or request.args).iteritems() }) diff --git a/webnotes/auth.py b/webnotes/auth.py index 7e5ee8df25..78af63d26f 100644 --- a/webnotes/auth.py +++ b/webnotes/auth.py @@ -14,7 +14,7 @@ class HTTPRequest: def __init__(self): # Get Environment variables - self.domain = webnotes.get_request_header('HTTP_HOST') + self.domain = webnotes.request.host if self.domain and self.domain.startswith('www.'): self.domain = self.domain[4:] diff --git a/webnotes/install_lib/setup_public_folder.py b/webnotes/install_lib/setup_public_folder.py index 137857d1df..7777c0a090 100644 --- a/webnotes/install_lib/setup_public_folder.py +++ b/webnotes/install_lib/setup_public_folder.py @@ -20,7 +20,6 @@ def make(): symlinks = [ ["app", "../app/public"], ["lib", "../lib/public"], - ["blank.html", "../lib/public/html/blank.html"], ["unsupported.html", "../lib/public/html/unsupported.html"] ] diff --git a/webnotes/modules/patch_handler.py b/webnotes/modules/patch_handler.py index 4292bedfb5..bb20bac72c 100644 --- a/webnotes/modules/patch_handler.py +++ b/webnotes/modules/patch_handler.py @@ -66,7 +66,7 @@ def execute_patch(patchmodule, method=None, methodargs=None): tb = webnotes.getTraceback() log(tb) import os - if webnotes.get_request_header('HTTP_HOST'): + if webnotes.request: add_to_patch_log(tb) block_user(False) diff --git a/webnotes/utils/__init__.py b/webnotes/utils/__init__.py index 117cd2b8a1..0211ed73b8 100644 --- a/webnotes/utils/__init__.py +++ b/webnotes/utils/__init__.py @@ -71,6 +71,7 @@ def get_request_site_address(full_address=False): host_name = conf.host_name else: try: + host = webnotes.request.host protocol = 'HTTPS' in webnotes.get_request_header('SERVER_PROTOCOL') and 'https://' or 'http://' host_name = protocol + webnotes.get_request_header('HTTP_HOST') except TypeError: diff --git a/website/templates/pages/rss.py b/website/templates/pages/rss.py index eabcb23cb8..586566ac5b 100644 --- a/website/templates/pages/rss.py +++ b/website/templates/pages/rss.py @@ -1,14 +1,13 @@ import webnotes import os, urllib -from webnotes.utils import escape_html +from webnotes.utils import escape_html, get_request_site_address no_cache = True def get_context(): """generate rss feed""" - host = ('https://' if webnotes.get_request_header('HTTPS') else 'http://') \ - + webnotes.get_request_header('HTTP_HOST', "localhost") + host = get_request_site_address() blog_list = webnotes.conn.sql("""\ select page_name as name, published_on, modified, title, content from `tabBlog Post` diff --git a/website/templates/pages/sitemap.py b/website/templates/pages/sitemap.py index 3b829c2e17..99dbf1734e 100644 --- a/website/templates/pages/sitemap.py +++ b/website/templates/pages/sitemap.py @@ -6,13 +6,12 @@ from __future__ import unicode_literals import urllib import webnotes import webnotes.webutils +from webnotes.utils import get_request_site_address def get_context(): """generate the sitemap XML""" links = webnotes.webutils.get_website_sitemap().items() - - host = ('https://' if webnotes.get_request_header('HTTPS') else 'http://') \ - + webnotes.get_request_header('HTTP_HOST', "localhost") + host = get_request_site_address() for l in links: l[1]["loc"] = urllib.basejoin(host, urllib.quote(l[1].get("page_name", l[1]["link_name"])))