dart-lang / http_parser

A platform-independent Dart package for parsing and serializing HTTP formats.
https://pub.dev/packages/http_parser
BSD 3-Clause "New" or "Revised" License
38 stars 28 forks source link

Error parsing mime-type with trailing semicolon #62

Closed kascote closed 1 year ago

kascote commented 1 year ago

I detected and error trying to read this RSS https://status.slack.com/feed/rss

this is the error

Unhandled exception:
Error on line 1, column 25: Invalid media type: expected /[^()<>@,;:"\\/[\]?={} \t\x00-\x1F\x7F]+/.
  ╷
1 │ text/xml; charset=UTF-8;
  │                         ^
  ╵
#0      wrapFormatException (package:http_parser/src/utils.dart:15:5)
#1      new MediaType.parse (package:http_parser/src/media_type.dart:46:7)
#2      _contentTypeForHeaders (package:http/src/response.dart:85:45)
#3      _encodingForHeaders (package:http/src/response.dart:78:24)
#4      Response.body (package:http/src/response.dart:28:22)
#5      updateContent (package:test_rss/test_rss.dart:71:26)
<asynchronous suspension>

and this is a Dart pad test case, but doesn't show all the error message.

https://dartpad.dev/?id=d42c08d17403e34b7a3441e4ff9bfa09

import 'package:http/http.dart' as http;
void main() async {
  final url = Uri.parse('https://status.slack.com/feed/rss');
  final response = await http.get(url);
  print(response.body);
}