Refine Ollama response content-type validation

Allow application/json and missing content-type headers, only rejecting
obvious non-JSON responses like HTML error pages. This improves
compatibility with different Ollama server configurations.
This commit is contained in:
2026-05-20 22:57:43 +02:00
parent f1afba70ff
commit 3d3b996839
+4 -2
View File
@@ -163,8 +163,10 @@ export class OllamaClient {
}
const contentType = response.headers?.get?.('content-type');
if (contentType && !contentType.includes('application/x-ndjson')) {
throw new Error('Invalid response format');
// Ollama may return application/x-ndjson, application/json, or no content-type at all.
// Reject only obvious non-JSON responses (e.g., HTML error pages).
if (contentType && contentType.includes('text/html')) {
throw new Error('Invalid response format: server returned HTML instead of JSON');
}
reader = response.body.getReader();