##// END OF EJS Templates
middlewares: all porting for python3
super-admin -
r5082:35aadafc default
parent child Browse files
Show More
@@ -24,9 +24,14 b' import logging'
24 24
25 25 log = logging.getLogger(__name__)
26 26
27 try:
28 from appenlight_client.exceptions import get_current_traceback
29 except ImportError:
30 def get_current_traceback(*args, **kwargs):
31 return
32
27 33
28 34 def track_exception(environ):
29 from appenlight_client.exceptions import get_current_traceback
30 35
31 36 if 'appenlight.client' not in environ:
32 37 return
@@ -48,6 +48,8 b' class RequestWrapperTween(object):'
48 48 start = time.time()
49 49 log.debug('Starting request time measurement')
50 50 response = None
51 request.req_wrapper_start = start
52
51 53 try:
52 54 response = self.handler(request)
53 55 finally:
@@ -24,7 +24,9 b' SimpleHG middleware for handling mercuri'
24 24
25 25 import logging
26 26 import urllib.parse
27 import urllib.request, urllib.parse, urllib.error
27 import urllib.request
28 import urllib.parse
29 import urllib.error
28 30
29 31 from rhodecode.lib import utils
30 32 from rhodecode.lib.ext_json import json
@@ -85,26 +85,30 b' class VcsHttpProxy(object):'
85 85 repo_name, url)
86 86
87 87 def __call__(self, environ, start_response):
88 config = msgpack.packb(self._config)
88 config = self._config
89 89 request = webob.request.Request(environ)
90 90 request_headers = request.headers
91 91
92 request_headers.update({
92 call_context = {
93 93 # TODO: johbo: Remove this, rely on URL path only
94 'X-RC-Repo-Name': self._repo_name,
95 'X-RC-Repo-Path': self._repo_path,
96 'X-RC-Path-Info': environ['PATH_INFO'],
94 'repo_name': self._repo_name,
95 'repo_path': self._repo_path,
96 'path_info': get_path_info(environ),
97
98 'repo_store': self.rc_extras.get('repo_store'),
99 'server_config_file': self.rc_extras.get('config'),
97 100
98 'X-RC-Repo-Store': self.rc_extras.get('repo_store'),
99 'X-RC-Server-Config-File': self.rc_extras.get('config'),
101 'auth_user': self.rc_extras.get('username'),
102 'auth_user_id': str(self.rc_extras.get('user_id')),
103 'auth_user_ip': self.rc_extras.get('ip'),
100 104
101 'X-RC-Auth-User': self.rc_extras.get('username'),
102 'X-RC-Auth-User-Id': str(self.rc_extras.get('user_id')),
103 'X-RC-Auth-User-Ip': self.rc_extras.get('ip'),
105 'repo_config': config,
106 'locked_status_code': rhodecode.CONFIG.get('lock_ret_code'),
107 }
104 108
109 request_headers.update({
105 110 # TODO: johbo: Avoid encoding and put this into payload?
106 'X-RC-Repo-Config': base64.b64encode(config),
107 'X-RC-Locked-Status-Code': rhodecode.CONFIG.get('lock_ret_code'),
111 'X_RC_VCS_STREAM_CALL_CONTEXT': base64.b64encode(msgpack.packb(call_context))
108 112 })
109 113
110 114 method = environ['REQUEST_METHOD']
@@ -143,18 +143,6 b' def is_vcs_call(environ):'
143 143 return False
144 144
145 145
146 def get_path_elem(route_path):
147 if not route_path:
148 return None
149
150 cleaned_route_path = route_path.lstrip('/')
151 if cleaned_route_path:
152 cleaned_route_path_elems = cleaned_route_path.split('/')
153 if cleaned_route_path_elems:
154 return cleaned_route_path_elems[0]
155 return None
156
157
158 146 def detect_vcs_request(environ, backends):
159 147 checks = {
160 148 'hg': (is_hg, SimpleHg),
@@ -164,11 +152,26 b' def detect_vcs_request(environ, backends'
164 152 handler = None
165 153 # List of path views first chunk we don't do any checks
166 154 white_list = [
155 # favicon often requested by browsers
156 'favicon.ico',
157
167 158 # e.g /_file_store/download
168 '_file_store',
159 '_file_store++',
160
161 # _admin/api is safe too
162 '_admin/api',
163
164 # _admin/gist is safe too
165 '_admin/gists++',
166
167 # _admin/my_account is safe too
168 '_admin/my_account++',
169 169
170 170 # static files no detection
171 '_static',
171 '_static++',
172
173 # debug-toolbar
174 '_debug_toolbar++',
172 175
173 176 # skip ops ping, status
174 177 '_admin/ops/ping',
@@ -180,13 +183,12 b' def detect_vcs_request(environ, backends'
180 183 path_info = get_path_info(environ)
181 184 path_url = path_info.lstrip('/')
182 185
183 if path_elem in white_list:
184 log.debug('path `%s` in whitelist, skipping...', path_info)
186 for item in white_list:
187 if item.endswith('++') and path_url.startswith(item[:-2]):
188 log.debug('path `%s` in whitelist (match:%s), skipping...', path_url, item)
185 189 return handler
186
187 path_url = path_info.lstrip('/')
188 if path_url in white_list:
189 log.debug('full url path `%s` in whitelist, skipping...', path_url)
190 if item == path_url:
191 log.debug('path `%s` in whitelist (match:%s), skipping...', path_url, item)
190 192 return handler
191 193
192 194 if VCS_TYPE_KEY in environ:
@@ -200,7 +202,7 b' def detect_vcs_request(environ, backends'
200 202 log.debug('got handler:%s from environ', handler)
201 203
202 204 if not handler:
203 log.debug('request start: checking if request for `%s` is of VCS type in order: %s', path_elem, backends)
205 log.debug('request start: checking if request for `%s` is of VCS type in order: %s', path_url, backends)
204 206 for vcs_type in backends:
205 207 vcs_check, _handler = checks[vcs_type]
206 208 if vcs_check(environ):
General Comments 0
You need to be logged in to leave comments. Login now