mirror of
https://github.com/open-webui/open-webui.git
synced 2026-11-14 09:21:22 +00:00
feat: client IP placeholders for connection custom headers (#33833)
Connection custom headers had no way to tell the upstream provider which client a request came from. Adding {{USER_IP}} and {{X_FORWARDED_FOR}} fills in the client address Open WebUI resolves for the request, for example {"X-Real-IP": "{{USER_IP}}"}. Both are empty when there is no client request, such as automations and background jobs. Headers that don't use them are unaffected.
Fixes #33819
This commit is contained in:
parent
184eada9ec
commit
d39cb17b97
3 changed files with 6 additions and 0 deletions
|
|
@ -1305,6 +1305,7 @@ async def chat_completion(
|
|||
else None,
|
||||
'user_id': user.id,
|
||||
'user_agent': request.headers.get('user-agent', '') or '',
|
||||
'client_ip': request.client.host if request.client else '',
|
||||
'internal': getattr(request.state, 'internal', False) is True,
|
||||
'chat_id': chat_id,
|
||||
'user_message': user_message,
|
||||
|
|
|
|||
|
|
@ -1765,6 +1765,7 @@ async def index_file(
|
|||
'file_id': file.id,
|
||||
'file_name': file.filename,
|
||||
'file_content_type': file.meta.get('content_type'),
|
||||
'client_ip': request.client.host if request.client else '',
|
||||
}
|
||||
docs = await loader.aload(file.filename, file.meta.get('content_type'), file_path)
|
||||
|
||||
|
|
|
|||
|
|
@ -131,6 +131,8 @@ def parse_custom_headers(
|
|||
if not user_agent:
|
||||
user_agent = metadata.get('user_agent', '') or ''
|
||||
|
||||
client_ip = getattr(getattr(request, 'client', None), 'host', None) or metadata.get('client_ip', '') or ''
|
||||
|
||||
# Extract user_message info for tree mapping
|
||||
user_message = metadata.get('user_message') or {}
|
||||
user_message_id = metadata.get('user_message_id', '') or (user_message.get('id', '') if user_message else '')
|
||||
|
|
@ -153,6 +155,8 @@ def parse_custom_headers(
|
|||
'{{USER_GROUPS}}': ','.join(group.name.strip() for group in user_groups) if user_groups else '',
|
||||
'{{USER_GROUP_IDS}}': ','.join(group.id for group in user_groups) if user_groups else '',
|
||||
'{{USER_AGENT}}': user_agent,
|
||||
'{{USER_IP}}': client_ip,
|
||||
'{{X_FORWARDED_FOR}}': client_ip,
|
||||
'{{AUTH_TYPE}}': getattr(getattr(request, 'state', None), 'auth_type', None) or '',
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue