更新
This commit is contained in:
12
Gateway.py
12
Gateway.py
@ -59,7 +59,7 @@ class GenericGateway(object):
|
||||
logger.info("Register route: %s", route.path)
|
||||
|
||||
def proxy_request(*args, **kwargs):
|
||||
|
||||
print('成功代理', route.name)
|
||||
upstream_path = route.upstream_path
|
||||
for p_name in route.upstream_params:
|
||||
v = get_params_from_context(p_name, kwargs)
|
||||
@ -79,6 +79,7 @@ class GenericGateway(object):
|
||||
if request.form:
|
||||
upstream_req_info['data'] = request.form
|
||||
|
||||
# print('upstream_req_info', upstream_req_info)
|
||||
for pipe_handler in route.inbound_pipes():
|
||||
upstream_req_info, args, kwargs = pipe_handler(upstream_req_info, *args, **kwargs)
|
||||
|
||||
@ -88,20 +89,23 @@ class GenericGateway(object):
|
||||
upstream_req_info['headers'] = {k: v for k, v in upstream_req_info['headers'].items()}
|
||||
upstream_req_info['headers'].pop('Content-Type', None)
|
||||
upstream_req_info['headers'].pop('content-type', None)
|
||||
|
||||
# print('upstream_req_info', upstream_req_info)
|
||||
resp = requests.request(**upstream_req_info)
|
||||
# print(resp.headers)
|
||||
status = resp.status_code
|
||||
content = None
|
||||
headers = resp.headers
|
||||
|
||||
print(route.outbound_pipes())
|
||||
for pipe_handler in route.outbound_pipes():
|
||||
resp, headers, status, content = pipe_handler(resp, headers, status, content, *args, **kwargs)
|
||||
|
||||
content = make_response(content or resp.content)
|
||||
for h_name, h_value in (headers or {}).items():
|
||||
# print(h_name, h_value)
|
||||
content.headers[h_name] = h_value
|
||||
|
||||
# print('content', headers)
|
||||
return content, status
|
||||
|
||||
# 修改函数名称:Flask route注册使用func name必须唯一
|
||||
proxy_request.__name__ = route.name
|
||||
return proxy_request
|
||||
|
Reference in New Issue
Block a user