From d9e1887a2100b1cffa090951a87cd7ade852adee Mon Sep 17 00:00:00 2001 From: zhangtao <448143356@qq.com> Date: Tue, 5 Dec 2023 20:01:56 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E6=94=AF=E6=8C=81moreDebuggerInfo?= =?UTF-8?q?=E9=85=8D=E7=BD=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- CHANGELOG | 3 ++- index.js | 4 +++- lib/service_client.js | 18 ++++++++++++++++++ package.json | 2 +- readme.md | 12 +++++++++++- 5 files changed, 35 insertions(+), 4 deletions(-) diff --git a/CHANGELOG b/CHANGELOG index 15250d8..4994d97 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -4,4 +4,5 @@ websocket mode support complex url. 1.0.5 add headerExtension to `http` and `websocket` mode. 1.0.7 error message typo. -1.0.10 config.defaultErrorCode \ No newline at end of file +1.0.10 config.defaultErrorCode +2.0.20 feature: Add more logInfo config diff --git a/index.js b/index.js index 3cf2155..f4e4d8b 100644 --- a/index.js +++ b/index.js @@ -163,7 +163,8 @@ HcProxy.prototype.mount = function (router, app) { let beforeRequest = u.beforeRequest; let beforeResponse = u.beforeResponse; let statusCode = u.return; - let serviceOpt = u.serviceOpt || service.serviceOpt || {} + let serviceOpt = u.serviceOpt || service.serviceOpt || {}; + let moreDebuggerInfo = u.moreDebuggerInfo; return { serviceName, @@ -189,6 +190,7 @@ HcProxy.prototype.mount = function (router, app) { beforeRequest, beforeResponse, serviceOpt, + moreDebuggerInfo }; }); diff --git a/lib/service_client.js b/lib/service_client.js index 9bff6f7..565f053 100644 --- a/lib/service_client.js +++ b/lib/service_client.js @@ -141,6 +141,24 @@ module.exports = function (u, proxyHeaders) { beforeRequest(req, options, u); } log.info(`[hc-proxy] ${req.method} ${qpath} -> ${options.url}`); + + if (u.moreDebuggerInfo) { + const {filter} = u.moreDebuggerInfo; + const {headers} = filter; + let needLog = true; + for (let header in headers) { + if (!needLog) { + break; + } + if (req.headers[header.toLocaleLowerCase()] !== headers[header]) { + needLog = false; + } + } + if (needLog) { + log.info(`[moreDebugger] body -> ${JSON.stringify(req.body)} headers -> ${JSON.stringify(req.headers)}`) + } + } + let optKeys = ['pipe']; optKeys.forEach((key) => { delete options[key]; diff --git a/package.json b/package.json index 990f832..c6d4de5 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "hc-proxy", - "version": "2.0.19", + "version": "2.0.20", "description": "honeycomb api proxy express middleware.", "main": "index.js", "scripts": { diff --git a/readme.md b/readme.md index 90d227d..e32923f 100644 --- a/readme.md +++ b/readme.md @@ -239,7 +239,17 @@ options.service 详情 /* delete方法使用querystring代理, 默认为true */ useQuerystringInDelete: {Boolean}, /** 用户覆盖的urllibOption,覆盖系统默认值,优先级: service.api.urllibOption > service.urllibOption > hc-proxy默认设置 */ - urllibOption: {Object} + urllibOption: {Object}, + /** filter全部命中之后才会出日志 + * { + * filter: { + * headers: { + * key: value + * } + * } + * } + */ + moreDebuggerInfo: {Object} } ] }