def test_handle_exception(self, super_mock, request_mock): def raise_exception(self, e): raise e super_mock.side_effect = raise_exception request_mock.httprequest.method = 'POST' request_mock.httprequest.full_path = '/full' request_mock.httprequest.url = '/normal' request_mock.session.u2f_last_registration_challenge = REQUEST_DATA req = HttpRequest(request_mock.httprequest) res = req._handle_exception(U2FAuthenticationError()) self.assertEqual( res.location, '/web/u2f/login?redirect=%2Fweb%2Fproxy%2Fpost%2Ffull' ) request_mock.httprequest.method = 'GET' request_mock.params = {} res = req._handle_exception(U2FAuthenticationError()) self.assertEqual( res.location, '/web/u2f/login?redirect=%2Fnormal' )
def get_request(self, httprequest): if 'User-Agent' in httprequest.headers and 'MicroMessenger' in httprequest.headers[ 'User-Agent']: return HttpRequest(httprequest) if httprequest.args.get('jsonp'): return JsonRequest(httprequest) if httprequest.mimetype in ("application/json", "application/json-rpc"): return JsonRequest(httprequest) else: return HttpRequest(httprequest)
def get_request(self, httprequest): if 'Referer' in httprequest.headers and 'servicewechat.com' in httprequest.headers[ 'Referer']: if httprequest.mimetype == "application/json": return HttpRequest(httprequest) if httprequest.args.get('jsonp'): return JsonRequest(httprequest) if httprequest.mimetype in ("application/json", "application/json-rpc"): return JsonRequest(httprequest) else: return HttpRequest(httprequest)
def get_request(self, httprequest): if 'Referer' in httprequest.headers and 'servicewechat.com' in httprequest.headers['Referer']: lang = httprequest.session.context.get('lang','') if lang!='zh-CN': httprequest.session.context["lang"] = 'zh_CN' if httprequest.mimetype=="application/json": return HttpRequest(httprequest) if httprequest.args.get('jsonp'): return JsonRequest(httprequest) if httprequest.mimetype in ("application/json", "application/json-rpc"): return JsonRequest(httprequest) else: return HttpRequest(httprequest)
def get_request(self, httprequest): if 'Referer' in httprequest.headers and 'servicewechat.com' in httprequest.headers[ 'Referer']: if not httprequest.accept_languages.best: httprequest.session.context["lang"] = 'zh_CN' if httprequest.mimetype == "application/json": return HttpRequest(httprequest) if httprequest.args.get('jsonp'): return JsonRequest(httprequest) if httprequest.mimetype in ("application/json", "application/json-rpc"): return JsonRequest(httprequest) else: return HttpRequest(httprequest)
def get_request(self, httprequest): is_json = httprequest.args.get('jsonp') or httprequest.mimetype in ( "application/json", "application/json-rpc") httprequest.data = {} woo_hook_path = ks_match_the_url_path(httprequest.path) if woo_hook_path and is_json: request = httprequest.get_data().decode(httprequest.charset) httprequest.data = json.loads(request) return HttpRequest(httprequest) return old_get_request(self, httprequest)
def get_request_new(self, httprequest): if ('/api/v1/' in httprequest.path) and (httprequest.mimetype == "application/json"): return ApiRequest(httprequest) if httprequest.args.get('jsonp'): return JsonRequest(httprequest) if httprequest.mimetype in ("application/json", "application/json-rpc"): return JsonRequest(httprequest) else: return HttpRequest(httprequest)
def get_request_new(self, httprequest): if '/api/' in httprequest.url and httprequest.mimetype in ( "application/json", "application/json-rpc"): return ApiRequest(httprequest) elif httprequest.args.get('jsonp'): return JsonRequest(httprequest) elif httprequest.mimetype in ("application/json", "application/json-rpc"): return JsonRequest(httprequest) else: return HttpRequest(httprequest)
def api_get_request(self, httprequest): # deduce type of request if httprequest.headers.get('Type') and httprequest.headers.get('Type') in ( 'api'): return ApiJsonRequest(httprequest) if httprequest.args.get('jsonp'): return JsonRequest(httprequest) if httprequest.mimetype in ("application/json", "application/json-rpc"): return JsonRequest(httprequest) else: return HttpRequest(httprequest)