@@ -5,6 +5,7 @@ import { getErrText } from '@fastgpt/global/common/error/utils';
55import type { RequireOnlyOne } from '@fastgpt/global/common/type/utils' ;
66import type { HttpToolConfigType } from '@fastgpt/global/core/app/type' ;
77import { contentTypeMap , ContentTypes } from '@fastgpt/global/core/workflow/constants' ;
8+ import { replaceEditorVariable } from '@fastgpt/global/core/workflow/runtime/utils' ;
89
910export type RunHTTPToolParams = {
1011 baseUrl : string ;
@@ -32,40 +33,49 @@ const buildHttpRequest = ({
3233 staticHeaders,
3334 staticBody
3435} : Omit < RunHTTPToolParams , 'baseUrl' | 'toolPath' > ) => {
36+ const replaceVariables = ( text : string ) => {
37+ return replaceEditorVariable ( {
38+ text,
39+ nodes : [ ] ,
40+ variables : params
41+ } ) ;
42+ } ;
43+
3544 const body = ( ( ) => {
3645 if ( ! staticBody || staticBody . type === ContentTypes . none ) {
37- return [ 'POST' , 'PUT' , 'PATCH' ] . includes ( method . toUpperCase ( ) ) ? params : undefined ;
46+ return [ 'POST' , 'PUT' , 'PATCH' ] . includes ( method . toUpperCase ( ) ) ? { } : undefined ;
3847 }
3948
4049 if ( staticBody . type === ContentTypes . json ) {
41- const staticContent = staticBody . content ? JSON . parse ( staticBody . content ) : { } ;
42- return { ...staticContent , ...params } ;
50+ const contentWithReplacedVars = staticBody . content
51+ ? replaceVariables ( staticBody . content )
52+ : '{}' ;
53+ const staticContent = JSON . parse ( contentWithReplacedVars ) ;
54+ return { ...staticContent } ;
4355 }
4456
4557 if ( staticBody . type === ContentTypes . formData ) {
4658 const formData = new ( require ( 'form-data' ) ) ( ) ;
4759 staticBody . formData ?. forEach ( ( { key, value } ) => {
48- formData . append ( key , value ) ;
49- } ) ;
50- Object . entries ( params ) . forEach ( ( [ key , value ] ) => {
51- formData . append ( key , value ) ;
60+ const replacedKey = replaceVariables ( key ) ;
61+ const replacedValue = replaceVariables ( value ) ;
62+ formData . append ( replacedKey , replacedValue ) ;
5263 } ) ;
5364 return formData ;
5465 }
5566
5667 if ( staticBody . type === ContentTypes . xWwwFormUrlencoded ) {
5768 const urlencoded = new URLSearchParams ( ) ;
5869 staticBody . formData ?. forEach ( ( { key, value } ) => {
59- urlencoded . append ( key , value ) ;
60- } ) ;
61- Object . entries ( params ) . forEach ( ( [ key , value ] ) => {
62- urlencoded . append ( key , String ( value ) ) ;
70+ const replacedKey = replaceVariables ( key ) ;
71+ const replacedValue = replaceVariables ( value ) ;
72+ urlencoded . append ( replacedKey , replacedValue ) ;
6373 } ) ;
6474 return urlencoded . toString ( ) ;
6575 }
6676
6777 if ( staticBody . type === ContentTypes . xml || staticBody . type === ContentTypes . raw ) {
68- return staticBody . content || '' ;
78+ return replaceVariables ( staticBody . content || '' ) ;
6979 }
7080
7181 return undefined ;
@@ -78,7 +88,9 @@ const buildHttpRequest = ({
7888 ...( headerSecret ? getSecretValue ( { storeSecret : headerSecret } ) : { } ) ,
7989 ...( staticHeaders ?. reduce (
8090 ( acc , { key, value } ) => {
81- acc [ key ] = value ;
91+ const replacedKey = replaceVariables ( key ) ;
92+ const replacedValue = replaceVariables ( value ) ;
93+ acc [ replacedKey ] = replacedValue ;
8294 return acc ;
8395 } ,
8496 { } as Record < string , string >
@@ -89,7 +101,9 @@ const buildHttpRequest = ({
89101 const staticParamsObj =
90102 staticParams ?. reduce (
91103 ( acc , { key, value } ) => {
92- acc [ key ] = value ;
104+ const replacedKey = replaceVariables ( key ) ;
105+ const replacedValue = replaceVariables ( value ) ;
106+ acc [ replacedKey ] = replacedValue ;
93107 return acc ;
94108 } ,
95109 { } as Record < string , any >
0 commit comments