mirror of
https://github.com/ollama/ollama-python.git
synced 2026-10-02 07:07:23 +00:00
Fixing empty header + ensuring security (#313)
* Fixing empty header + ensuring security
This commit is contained in:
committed by
Michael Yang
parent
f25834217b
commit
72052188c3
+9
-4
@@ -90,11 +90,16 @@ class BaseClient:
|
|||||||
base_url=_parse_host(host or os.getenv('OLLAMA_HOST')),
|
base_url=_parse_host(host or os.getenv('OLLAMA_HOST')),
|
||||||
follow_redirects=follow_redirects,
|
follow_redirects=follow_redirects,
|
||||||
timeout=timeout,
|
timeout=timeout,
|
||||||
|
# Lowercase all headers to ensure override
|
||||||
headers={
|
headers={
|
||||||
'Content-Type': 'application/json',
|
k.lower(): v
|
||||||
'Accept': 'application/json',
|
for k, v in {
|
||||||
'User-Agent': f'ollama-python/{__version__} ({platform.machine()} {platform.system().lower()}) Python/{platform.python_version()}',
|
**(headers or {}),
|
||||||
}.update(headers or {}),
|
'Content-Type': 'application/json',
|
||||||
|
'Accept': 'application/json',
|
||||||
|
'User-Agent': f'ollama-python/{__version__} ({platform.machine()} {platform.system().lower()}) Python/{platform.python_version()}',
|
||||||
|
}.items()
|
||||||
|
},
|
||||||
**kwargs,
|
**kwargs,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|||||||
@@ -968,3 +968,19 @@ async def test_async_client_copy(httpserver: HTTPServer):
|
|||||||
client = AsyncClient(httpserver.url_for('/api/copy'))
|
client = AsyncClient(httpserver.url_for('/api/copy'))
|
||||||
response = await client.copy('dum', 'dummer')
|
response = await client.copy('dum', 'dummer')
|
||||||
assert response['status'] == 'success'
|
assert response['status'] == 'success'
|
||||||
|
|
||||||
|
|
||||||
|
def test_headers():
|
||||||
|
client = Client()
|
||||||
|
assert client._client.headers['content-type'] == 'application/json'
|
||||||
|
assert client._client.headers['accept'] == 'application/json'
|
||||||
|
assert client._client.headers['user-agent'].startswith('ollama-python/')
|
||||||
|
|
||||||
|
client = Client(
|
||||||
|
headers={
|
||||||
|
'X-Custom': 'value',
|
||||||
|
'Content-Type': 'text/plain',
|
||||||
|
}
|
||||||
|
)
|
||||||
|
assert client._client.headers['x-custom'] == 'value'
|
||||||
|
assert client._client.headers['content-type'] == 'application/json'
|
||||||
|
|||||||
Reference in New Issue
Block a user