@@ -42,6 +42,8 @@ export class RequestVariableCacheValueProcessor {
4242
4343 private static resolveHttpPart ( http : HttpRequest | HttpResponse , httpPart : HttpPart , nameOrPath ?: string ) : ResolveResult {
4444 if ( httpPart === "body" ) {
45+ const forceJsonExtension = 'asJson.' ;
46+ const forceXmlExtension = 'asXml.' ;
4547 const { body, headers } = http ;
4648 if ( ! body ) {
4749 const message = http instanceof HttpRequest ? ResolveWarningMessage . RequestBodyNotExist : ResolveWarningMessage . ResponseBodyNotExist ;
@@ -57,12 +59,23 @@ export class RequestVariableCacheValueProcessor {
5759 return { state : ResolveState . Success , value : body } ;
5860 }
5961
62+ let forceJson = false ;
63+ let forceXml = false ;
64+ if ( nameOrPath . startsWith ( forceJsonExtension ) ) {
65+ nameOrPath = nameOrPath . substring ( forceJsonExtension . length ) ;
66+ forceJson = true ;
67+ } else if ( nameOrPath . startsWith ( forceXmlExtension ) ) {
68+ nameOrPath = nameOrPath . substring ( forceXmlExtension . length ) ;
69+ forceXml = true ;
70+ }
71+
6072 const contentTypeHeader = getContentType ( headers ) ;
61- if ( MimeUtility . isJSON ( contentTypeHeader ) || ( MimeUtility . isJavaScript ( contentTypeHeader ) && isJSONString ( body as string ) ) ) {
73+ if ( MimeUtility . isJSON ( contentTypeHeader ) ||
74+ ( forceJson || MimeUtility . isJavaScript ( contentTypeHeader ) ) && isJSONString ( body as string ) ) {
6275 const parsedBody = JSON . parse ( body as string ) ;
6376
6477 return this . resolveJsonHttpBody ( parsedBody , nameOrPath ) ;
65- } else if ( MimeUtility . isXml ( contentTypeHeader ) ) {
78+ } else if ( forceXml || MimeUtility . isXml ( contentTypeHeader ) ) {
6679 return this . resolveXmlHttpBody ( body , nameOrPath ) ;
6780 } else {
6881 return { state : ResolveState . Warning , value : body , message : ResolveWarningMessage . UnsupportedBodyContentType } ;
0 commit comments