From c98d2a8fd304334e70ede331f537db5a189c79bf Mon Sep 17 00:00:00 2001 From: shenshuo <191715030@qq.com> Date: Fri, 16 Aug 2024 23:27:55 +0800 Subject: [PATCH] =?UTF-8?q?2024=E5=B9=B48=E6=9C=8816=E6=97=A5=20=20?= =?UTF-8?q?=E5=B1=8F=E8=94=BDheaders=E6=95=B0=E6=8D=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- mg/subscribe.py | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/mg/subscribe.py b/mg/subscribe.py index 2b8673f..04997be 100644 --- a/mg/subscribe.py +++ b/mg/subscribe.py @@ -61,12 +61,16 @@ def process_message(msg_id, fields): log_data_dict['uri'] = request_data.get('uri')[0:255] log_data_dict['method'] = request_data.get('method') try: - log_data_dict['rq_headers'] = str(request_data.get('headers')) + headers = request_data.get('headers', {}) + # 处理 headers,隐藏 auth-key 的值 + filtered_headers = {key: '******' if 'auth-key' in key.lower() else value for key, value in headers.items()} + # 将处理后的 headers 转换为字符串并保存 + log_data_dict['rq_headers'] = str(filtered_headers) except Exception as err: log_data_dict['rq_headers'] = "{}" - logging.error(f"格式化header {err}") + logging.error(f"格式化 header 失败: {err}") # log_data_dict['rq_query'] = request_data.get('method') - + log_data_dict['rq_headers'] = "{}" # 隐藏headers request_data_data = request_data.get('data') try: if request_data_data: @@ -99,7 +103,7 @@ def create_consumer_group(self, stream_name, group_name): if not self.redis_conn.exists(stream_name): self.redis_conn.xadd(stream_name, {'test': 'true'}) ret = self.redis_conn.xgroup_create(stream_name, group_name, id=0) - print(ret) + # print(ret) except Exception as err: logging.debug('create_consumer_group', err)