Skip to content

Commit

Permalink
avoid forward lyrebird header in response (#888)
Browse files Browse the repository at this point in the history
* avoid forward lyrebird header in response

---------

Co-authored-by: noO0ob <wujiasheng03@meituan.com>
  • Loading branch information
noO0oOo0ob and noO0ob authored Jan 21, 2025
1 parent 2ef1d39 commit 5498aa6
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 3 deletions.
4 changes: 2 additions & 2 deletions lyrebird/mock/blueprints/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,13 +52,13 @@ def index(path=''):
resp = Response(
gen(),
status=req_context.flow['response']['code'],
headers=req_context.flow['response']['headers']
headers=req_context.get_response_headers()
)
elif req_context.flow['response']:
resp = Response(
req_context.flow['response'].get('data', ''),
status=req_context.flow['response'].get('code', 200),
headers=req_context.flow['response'].get('headers', {})
headers=req_context.get_response_headers()
)
else:
path_not_found_handler.handle(req_context)
Expand Down
16 changes: 15 additions & 1 deletion lyrebird/mock/handlers/handler_context.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@

logger = get_logger()
proxy_handler = ProxyHandler()
lyrebird_response_headers = None


class HandlerContext:
Expand Down Expand Up @@ -213,7 +214,20 @@ def get_request_headers(self):
continue
headers[name] = value
return headers


# Before response returns, remove the Lyrebird internal headers
def get_response_headers(self):
global lyrebird_response_headers
if not lyrebird_response_headers:
lyrebird_response_headers = application.config.get('proxy.response.delete_headers', [])

headers = self.flow['response'].get('headers', {})
lyrebird_response_headers = []
for key in lyrebird_response_headers:
if key in headers:
del headers[key]
return headers

def get_request_cookies(self, in_request_handler=True):
if in_request_handler:
return self.request.cookies
Expand Down

0 comments on commit 5498aa6

Please sign in to comment.