[wsgi] [minor] replace os.environ by webnotes.get_request_header
This commit is contained in:
parent
9d11c3e76a
commit
ca5d492d8d
7 changed files with 21 additions and 18 deletions
|
|
@ -188,11 +188,11 @@ def connect(db_name=None, password=None):
|
|||
import webnotes.profile
|
||||
local.user = webnotes.profile.Profile('Administrator')
|
||||
|
||||
def get_env_vars(env_var):
|
||||
def get_request_header(key, default=None):
|
||||
import os
|
||||
return os.environ.get(env_var,'None')
|
||||
return os.environ.get(key, default)
|
||||
|
||||
remote_ip = get_env_vars('REMOTE_ADDR') #Required for login from python shell
|
||||
remote_ip = get_request_header('REMOTE_ADDR') #Required for login from python shell
|
||||
logger = None
|
||||
|
||||
def get_db_password(db_name):
|
||||
|
|
|
|||
|
|
@ -14,19 +14,19 @@ class HTTPRequest:
|
|||
def __init__(self):
|
||||
|
||||
# Get Environment variables
|
||||
self.domain = webnotes.get_env_vars('HTTP_HOST')
|
||||
self.domain = webnotes.get_request_header('HTTP_HOST')
|
||||
if self.domain and self.domain.startswith('www.'):
|
||||
self.domain = self.domain[4:]
|
||||
|
||||
# language
|
||||
self.set_lang(webnotes.get_env_vars('HTTP_ACCEPT_LANGUAGE'))
|
||||
self.set_lang(webnotes.get_request_header('HTTP_ACCEPT_LANGUAGE'))
|
||||
|
||||
webnotes.remote_ip = webnotes.get_env_vars('REMOTE_ADDR')
|
||||
webnotes.remote_ip = webnotes.get_request_header('REMOTE_ADDR')
|
||||
|
||||
# load cookies
|
||||
webnotes.local.cookie_manager = CookieManager()
|
||||
|
||||
webnotes.request_method = webnotes.get_env_vars("REQUEST_METHOD")
|
||||
webnotes.request_method = webnotes.get_request_header("REQUEST_METHOD")
|
||||
|
||||
# override request method. All request to be of type POST, but if _type == "POST" then commit
|
||||
if webnotes.form_dict.get("_type"):
|
||||
|
|
|
|||
|
|
@ -210,7 +210,7 @@ def json_handler(obj):
|
|||
(type(obj), repr(obj))
|
||||
|
||||
def accept_gzip():
|
||||
if "gzip" in os.environ.get("HTTP_ACCEPT_ENCODING", ""):
|
||||
if "gzip" in webnotes.get_request_header("HTTP_ACCEPT_ENCODING", ""):
|
||||
return True
|
||||
|
||||
def compressBuf(buf):
|
||||
|
|
|
|||
|
|
@ -66,7 +66,7 @@ def execute_patch(patchmodule, method=None, methodargs=None):
|
|||
tb = webnotes.getTraceback()
|
||||
log(tb)
|
||||
import os
|
||||
if os.environ.get('HTTP_HOST'):
|
||||
if webnotes.get_request_header('HTTP_HOST'):
|
||||
add_to_patch_log(tb)
|
||||
|
||||
block_user(False)
|
||||
|
|
|
|||
|
|
@ -98,10 +98,10 @@ class Session:
|
|||
self.data['user'] = webnotes.local.login_manager.user
|
||||
self.data['sid'] = sid
|
||||
self.data['data']['user'] = webnotes.local.login_manager.user
|
||||
self.data['data']['session_ip'] = os.environ.get('REMOTE_ADDR')
|
||||
self.data['data']['session_ip'] = webnotes.get_request_header('REMOTE_ADDR')
|
||||
self.data['data']['last_updated'] = webnotes.utils.now()
|
||||
self.data['data']['session_expiry'] = self.get_expiry_period()
|
||||
self.data['data']['session_country'] = get_geo_ip_country(os.environ.get('REMOTE_ADDR'))
|
||||
self.data['data']['session_country'] = get_geo_ip_country(webnotes.get_request_header('REMOTE_ADDR'))
|
||||
|
||||
# insert session
|
||||
webnotes.conn.begin()
|
||||
|
|
@ -247,7 +247,10 @@ def get_geo_ip_country(ip_addr):
|
|||
import os
|
||||
from webnotes.utils import get_base_path
|
||||
|
||||
geo_ip_file = os.path.join(get_base_path(), "lib", "data", "GeoIP.dat")
|
||||
geo_ip = pygeoip.GeoIP(geo_ip_file, pygeoip.MEMORY_CACHE)
|
||||
try:
|
||||
geo_ip_file = os.path.join(get_base_path(), "lib", "data", "GeoIP.dat")
|
||||
geo_ip = pygeoip.GeoIP(geo_ip_file, pygeoip.MEMORY_CACHE)
|
||||
return geo_ip.country_name_by_addr(ip_addr)
|
||||
except Exception, e:
|
||||
return
|
||||
|
||||
return geo_ip.country_name_by_addr(ip_addr)
|
||||
|
|
@ -71,13 +71,13 @@ def get_request_site_address(full_address=False):
|
|||
host_name = conf.host_name
|
||||
else:
|
||||
try:
|
||||
protocol = 'HTTPS' in os.environ.get('SERVER_PROTOCOL') and 'https://' or 'http://'
|
||||
host_name = protocol + os.environ.get('HTTP_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:
|
||||
return 'http://localhost'
|
||||
|
||||
if full_address:
|
||||
return host_name + os.environ.get("REQUEST_URI", "")
|
||||
return host_name + webnotes.get_request_header("REQUEST_URI", "")
|
||||
else:
|
||||
return host_name
|
||||
|
||||
|
|
|
|||
|
|
@ -35,7 +35,7 @@ def generate():
|
|||
from webnotes.model.doc import Document
|
||||
from webnotes.utils import escape_html
|
||||
|
||||
host = (os.environ.get('HTTPS') and 'https://' or 'http://') + os.environ.get('HTTP_HOST')
|
||||
host = (webnotes.get_request_header('HTTPS') and 'https://' or 'http://') + webnotes.get_request_header('HTTP_HOST')
|
||||
|
||||
items = ''
|
||||
blog_list = webnotes.conn.sql("""\
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue