From c7d9f7857ca842e9b43144228d405cf232cbf862 Mon Sep 17 00:00:00 2001 From: Andreas Weber Date: Tue, 29 Oct 2024 21:46:19 +0100 Subject: [PATCH] fix: named response is only set, if all testResults are valid --- CHANGELOG.md | 8 +++- package-lock.json | 4 +- package.json | 2 +- src/plugins/core/execute/index.ts | 1 + .../core/execute/metaDataNameInterceptor.ts | 37 +++++++++++++++++++ src/plugins/core/registerCorePlugin.ts | 2 +- .../core/response/handleNameMetaData.ts | 16 -------- src/plugins/core/response/index.ts | 1 - 8 files changed, 48 insertions(+), 23 deletions(-) create mode 100644 src/plugins/core/execute/metaDataNameInterceptor.ts delete mode 100644 src/plugins/core/response/handleNameMetaData.ts diff --git a/CHANGELOG.md b/CHANGELOG.md index 6cee1f82..f2ccef98 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,10 +1,14 @@ +## [6.16.2] (2024-10-29) + +### Fix +- named response is only set, if all testResults are valid + ## [6.16.1] ( 2024-10-29) ### Fix -- support `http_proxy` environment variable +- support `https_proxy` environment variable - support html mimetype for dom parser and use only valid mimetype in parseFromString - ## [6.16.0] ( 2024-10-28) ### Features - support client certificates on OAuth2 Requests (#802) diff --git a/package-lock.json b/package-lock.json index 68816766..6a4a1280 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "httpyac", - "version": "6.16.1", + "version": "6.16.2", "lockfileVersion": 3, "requires": true, "packages": { "": { "name": "httpyac", - "version": "6.16.1", + "version": "6.16.2", "license": "MIT", "dependencies": { "@cloudamqp/amqp-client": "^2.1.1", diff --git a/package.json b/package.json index 775e1ba6..77f008c6 100644 --- a/package.json +++ b/package.json @@ -4,7 +4,7 @@ "license": "MIT", "publisher": "AnWeber", "description": "HTTP/REST CLI Client for *.http files", - "version": "6.16.1", + "version": "6.16.2", "homepage": "https://github.com/AnWeber/httpyac", "repository": { "type": "git", diff --git a/src/plugins/core/execute/index.ts b/src/plugins/core/execute/index.ts index 46efa295..d86c81b2 100644 --- a/src/plugins/core/execute/index.ts +++ b/src/plugins/core/execute/index.ts @@ -1,5 +1,6 @@ export * from './createRequestInterceptor'; export * from './lazyVariableInterceptor'; export * from './logResponseInterceptor'; +export * from './metaDataNameInterceptor'; export * from './processedHttpRegionInterceptor'; export * from './regionScopedVariablesInterceptor'; diff --git a/src/plugins/core/execute/metaDataNameInterceptor.ts b/src/plugins/core/execute/metaDataNameInterceptor.ts new file mode 100644 index 00000000..2f8deabd --- /dev/null +++ b/src/plugins/core/execute/metaDataNameInterceptor.ts @@ -0,0 +1,37 @@ +import * as models from '../../../models'; +import * as utils from '../../../utils'; + +import { HookInterceptor, HookTriggerContext } from 'hookpoint'; + +export class MetaDataNameInterceptor implements HookInterceptor<[models.ProcessorContext], boolean | void> { + id = 'metaDataName'; + async afterLoop( + hookContext: HookTriggerContext<[models.ProcessorContext], boolean | undefined> + ): Promise { + const context = hookContext.args[0]; + if (!context.httpRegion.response || !utils.isString(context.httpRegion.metaData.name)) { + return true; + } + + if ( + context.httpRegion.testResults && + context.httpRegion.testResults.some(t => t.status !== models.TestResultStatus.SUCCESS) + ) { + return true; + } + + const name = context.httpRegion.metaData.name + .trim() + .replace(/\s/gu, '-') + .replace(/-./gu, value => value[1].toUpperCase()); + utils.setVariableInContext( + { + [name]: context.httpRegion.response.parsedBody || context.httpRegion.response.body, + [`${name}Response`]: context.httpRegion.response, + }, + context + ); + + return true; + } +} diff --git a/src/plugins/core/registerCorePlugin.ts b/src/plugins/core/registerCorePlugin.ts index 97be6269..1659784c 100644 --- a/src/plugins/core/registerCorePlugin.ts +++ b/src/plugins/core/registerCorePlugin.ts @@ -37,7 +37,6 @@ function initOnRequestHook(api: models.HttpyacHooksApi) { } function initOnResponseHook(api: models.HttpyacHooksApi) { - api.hooks.onResponse.addHook('handleMetaDataName', response.handleNameMetaData); api.hooks.onResponse.addHook('setLastResponseInVariables', response.setLastResponseInVariables); api.hooks.onResponse.addInterceptor(response.jsonResponseInterceptor); } @@ -95,6 +94,7 @@ function initExecuteInterceptor(api: models.HttpyacHooksApi) { api.hooks.responseLogging.addInterceptor(processedHttpRegionInterceptor.getResponseLoggingInterceptor()); api.hooks.execute.addInterceptor(new execute.CreateRequestInterceptor()); api.hooks.execute.addInterceptor(new execute.LazyVariableInterceptor()); + api.hooks.execute.addInterceptor(new execute.MetaDataNameInterceptor()); api.hooks.execute.addInterceptor(new execute.LogResponseInterceptor()); } function initProvideEnvironmentsHook(api: models.HttpyacHooksApi) { diff --git a/src/plugins/core/response/handleNameMetaData.ts b/src/plugins/core/response/handleNameMetaData.ts deleted file mode 100644 index 22b8a8e2..00000000 --- a/src/plugins/core/response/handleNameMetaData.ts +++ /dev/null @@ -1,16 +0,0 @@ -import * as models from '../../../models'; -import * as utils from '../../../utils'; - -export function handleNameMetaData(response: models.HttpResponse, context: models.ProcessorContext) { - const { httpRegion } = context; - if (utils.isString(httpRegion.metaData.name)) { - const name = httpRegion.metaData.name - .trim() - .replace(/\s/gu, '-') - .replace(/-./gu, value => value[1].toUpperCase()); - utils.setVariableInContext( - { [name]: response.parsedBody || response.body, [`${name}Response`]: response }, - context - ); - } -} diff --git a/src/plugins/core/response/index.ts b/src/plugins/core/response/index.ts index bb2e7c46..12738f84 100644 --- a/src/plugins/core/response/index.ts +++ b/src/plugins/core/response/index.ts @@ -1,3 +1,2 @@ -export * from './handleNameMetaData'; export * from './jsonResponseInterceptor'; export * from './setLastResponseInVariables';