From aca695df2570d638c27004bf1c06ec50bd77a09f Mon Sep 17 00:00:00 2001 From: zhaoye Date: Wed, 10 Oct 2018 11:15:32 +0800 Subject: [PATCH] v0.13.8 - Bugfix/proxy response with wrong content length (#42) * remove content-length if content-encoding is gzip * v0.13.8 --- lyrebird/mock/handlers/proxy_handler.py | 8 +++++--- lyrebird/version.py | 2 +- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/lyrebird/mock/handlers/proxy_handler.py b/lyrebird/mock/handlers/proxy_handler.py index e98bffa60..4cd775ef2 100644 --- a/lyrebird/mock/handlers/proxy_handler.py +++ b/lyrebird/mock/handlers/proxy_handler.py @@ -40,12 +40,14 @@ def handle(self, handler_context): resp_headers = [('lyrebird', 'proxy')] for name, value in r.headers.items(): # rm 'content-length' from ignore list - if name.lower() in ('connection', - 'content-encoding', + if name.lower() in ('content-encoding', 'transfer-encoding'): continue + if name.lower() == 'content-length' and 'content-encoding' in r.headers and r.headers['content-encoding']=='gzip': + # 如果是gzip请求,由于requests自动解压gzip,所以此处抹去content-length,以匹配解压后的数据长度 + continue resp_headers.append((name, value)) - + handler_context.request.url = origin_url # After huangyuanzhen test, we use 2048byte buffer :D handler_context.response = Response( diff --git a/lyrebird/version.py b/lyrebird/version.py index bcbfaad0c..5c744dabb 100644 --- a/lyrebird/version.py +++ b/lyrebird/version.py @@ -1,3 +1,3 @@ -IVERSION = (0, 13, 7) +IVERSION = (0, 13, 8) VERSION = ".".join(str(i) for i in IVERSION) LYREBIRD = "Lyrebird " + VERSION