-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
66e691b
commit 89f34c9
Showing
6 changed files
with
105 additions
and
5 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,6 @@ | ||
import { valueExtractorHeader } from './value-extractor-header' | ||
import { valueExtractorJson } from './value-extractor-json' | ||
import { valueExtractorStatic } from './value-extractor-static' | ||
import { valueExtractorXml } from './value-extractor-xml' | ||
|
||
export const allValueExtractors = [valueExtractorJson, valueExtractorHeader, valueExtractorStatic] | ||
export const allValueExtractors = [valueExtractorJson, valueExtractorHeader, valueExtractorStatic, valueExtractorXml] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
import { VariableDefinition } from '../custom-header-format/variable-definition/variable-definition' | ||
import { ResponseHookContext } from '../insomnia/types/response-hook-context' | ||
import { ValueExtractor } from './value-extractor' | ||
import { DOMParser } from 'xmldom' | ||
import { select } from 'xpath' | ||
|
||
export const valueExtractorXml: ValueExtractor = { | ||
type: 'bodyXml', | ||
display: { | ||
name: 'Body Attribute (XML)', | ||
description: 'value of response body', | ||
argument: 'Response XPath', | ||
}, | ||
extractFromResponse: async ( | ||
variableDefinition: VariableDefinition, | ||
context: ResponseHookContext, | ||
): Promise<string | null | undefined> => { | ||
const body = context.response.getBody()?.toString('utf-8') || '' | ||
const xmlDoc = new DOMParser().parseFromString(body) | ||
const nodes = select(variableDefinition.arg, xmlDoc) | ||
return nodes ? String(nodes) : null | ||
}, | ||
} |