Skip to content

Commit 0675332

Browse files
committed
Fix search endpoint Accept header
1 parent 722f84d commit 0675332

1 file changed

Lines changed: 8 additions & 1 deletion

File tree

mocks/server.js

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -366,9 +366,13 @@ function resolveReferences(obj, level, startDepth = 0) {
366366
// Helper to determine response format based on Accept header
367367
function getResponseFormat(req) {
368368
const accept = req.headers.accept || '';
369-
if (accept.includes('application/vnd.ddi.structure+xml') || accept.includes('application/xml') || accept.includes('text/xml')) {
369+
// Only return XML if explicitly requested (not for text/html from browsers)
370+
if (accept.includes('application/vnd.ddi.structure+xml') ||
371+
(accept.includes('application/xml') && !accept.includes('text/html')) ||
372+
(accept.includes('text/xml') && !accept.includes('text/html'))) {
370373
return 'xml';
371374
}
375+
// Default to JSON (even if browser sends text/html)
372376
return 'json';
373377
}
374378

@@ -392,9 +396,12 @@ function sendResponse(req, res, data, rootElementName) {
392396
res.send(xml);
393397
} catch (error) {
394398
console.error('XML conversion error:', error);
399+
res.set('Content-Type', 'application/json');
395400
res.json(data); // Fallback to JSON on error
396401
}
397402
} else {
403+
// Set JSON Content-Type (same as other endpoints)
404+
res.set('Content-Type', 'application/json');
398405
res.json(data);
399406
}
400407
}

0 commit comments

Comments
 (0)