Skip to content

Commit

Permalink
feat(response): support XML inference
Browse files Browse the repository at this point in the history
fix #8
  • Loading branch information
bradcypert committed Oct 4, 2023
1 parent d845589 commit c30fbd0
Show file tree
Hide file tree
Showing 4 changed files with 114 additions and 74 deletions.
8 changes: 7 additions & 1 deletion lib/router/response.dart
@@ -1,5 +1,6 @@
import 'dart:io';
import 'dart:convert';
import 'package:xml/xml.dart';

const _originKey = 'Access-Control-Allow-Origin';
const _methodsKey = 'Access-Control-Allow-Methods';
Expand Down Expand Up @@ -113,7 +114,12 @@ Future<void> writeResponse(HttpRequest request, Future<Response> resp) async {
if (bodyIsJsonable && body is! String) {
response.headers.contentType = ContentType.json;
} else {
response.headers.contentType = ContentType.text;
try {
XmlDocument.parse(body);
response.headers.contentType = ContentType.parse('application/xml');
} catch (e) {
response.headers.contentType = ContentType.text;
}
}
}

Expand Down

0 comments on commit c30fbd0

Please sign in to comment.