mirror of
https://github.com/open-webui/open-webui.git
synced 2026-09-16 23:43:03 +00:00
feat: interpolate template variables in custom connection headers
Admins can now use {{chat_id}}, {{message_id}}, {{user_id}}, and
{{user_name}} as dynamic placeholders in custom header values for
OpenAI-compatible connections.
Before merging custom headers into the outgoing request,
get_headers_and_cookies() performs a simple string-replace pass
using values already available in the metadata dict and user object.
Header values with no {{...}} tokens pass through unchanged, and
unknown tokens are left as-is, so the change is fully backwards
compatible.
Use-case: providers like Manifest that use a session-scoped header
(e.g. x-session-key) to route or isolate conversations can now be
configured with {"x-session-key": "{{chat_id}}"} so every request
automatically carries the current chat UUID.
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
parent
8dae237a0b
commit
823a205fd2
2 changed files with 14 additions and 2 deletions
|
|
@ -215,7 +215,19 @@ async def get_headers_and_cookies(
|
|||
headers['Authorization'] = f'Bearer {token}'
|
||||
|
||||
if config.get('headers') and isinstance(config.get('headers'), dict):
|
||||
headers = {**headers, **config.get('headers')}
|
||||
template_vars = {
|
||||
'{{chat_id}}': (metadata or {}).get('chat_id', '') or '',
|
||||
'{{message_id}}': (metadata or {}).get('message_id', '') or '',
|
||||
'{{user_id}}': (user.id if user else '') or '',
|
||||
'{{user_name}}': (user.name if user else '') or '',
|
||||
}
|
||||
custom_headers = {}
|
||||
for k, v in config.get('headers').items():
|
||||
if isinstance(v, str):
|
||||
for token, value in template_vars.items():
|
||||
v = v.replace(token, value)
|
||||
custom_headers[k] = v
|
||||
headers = {**headers, **custom_headers}
|
||||
|
||||
return headers, cookies
|
||||
|
||||
|
|
|
|||
|
|
@ -444,7 +444,7 @@
|
|||
<div class="flex-1">
|
||||
<Tooltip
|
||||
content={$i18n.t(
|
||||
'Enter additional headers in JSON format (e.g. {"X-Custom-Header": "value"}'
|
||||
'Enter additional headers in JSON format (e.g. {"X-Custom-Header": "value"}). Dynamic values supported: {{chat_id}}, {{message_id}}, {{user_id}}, {{user_name}}'
|
||||
)}
|
||||
>
|
||||
<Textarea
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue