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:
@@ -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();
|
||||
|
||||
Reference in New Issue
Block a user