mirror of
https://github.com/infiniflow/ragflow.git
synced 2026-05-03 16:57:48 +08:00
Feat: support variable interpolation in headers (#13680)
Closes #13277 ### What problem does this PR solve? Adds `{variable_name}` (and `{component@variable}`) interpolation support to HTTP header values in the `Invoke` component, matching the existing URL interpolation behavior. ### Type of change - [x] New Feature (non-breaking change which adds functionality) <img width="1280" height="867" alt="image" src="https://github.com/user-attachments/assets/8ab7b4e9-7cc0-4a7f-8a5f-f838a15a5fda" /> --------- Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
This commit is contained in:
@ -97,8 +97,10 @@ class Invoke(ComponentBase, ABC):
|
||||
except Exception:
|
||||
return ""
|
||||
|
||||
variable_pattern = r"\{([a-zA-Z_][a-zA-Z0-9_.@-]*)\}"
|
||||
|
||||
# {base_url} or {component_id@variable_name}
|
||||
url = re.sub(r"\{([a-zA-Z_][a-zA-Z0-9_.@-]*)\}", replace_variable, url)
|
||||
url = re.sub(variable_pattern, replace_variable, url)
|
||||
|
||||
if url.find("http") != 0:
|
||||
url = "http://" + url
|
||||
@ -106,7 +108,25 @@ class Invoke(ComponentBase, ABC):
|
||||
method = self._param.method.lower()
|
||||
headers = {}
|
||||
if self._param.headers:
|
||||
headers = json.loads(self._param.headers)
|
||||
try:
|
||||
parsed_headers = json.loads(self._param.headers)
|
||||
except json.JSONDecodeError as e:
|
||||
logging.warning(
|
||||
"Invoke headers are not valid JSON, ignoring headers. raw=%r error=%s",
|
||||
self._param.headers,
|
||||
e,
|
||||
)
|
||||
parsed_headers = {}
|
||||
if not isinstance(parsed_headers, dict):
|
||||
logging.warning(
|
||||
"Invoke headers JSON is of type %s, expected an object; ignoring headers.",
|
||||
type(parsed_headers).__name__,
|
||||
)
|
||||
parsed_headers = {}
|
||||
headers = parsed_headers
|
||||
for key, value in list(headers.items()):
|
||||
if isinstance(value, str):
|
||||
headers[key] = re.sub(variable_pattern, replace_variable, value)
|
||||
proxies = None
|
||||
if re.sub(r"https?:?/?/?", "", self._param.proxy):
|
||||
proxies = {"http": self._param.proxy, "https": self._param.proxy}
|
||||
|
||||
Reference in New Issue
Block a user