From edcae3f32d7c196fb21c5dc04b02c7d57e69df87 Mon Sep 17 00:00:00 2001 From: Benjamin Schoenberger <25782944+Reprevise@users.noreply.github.com> Date: Tue, 5 Aug 2025 10:06:15 -0400 Subject: [PATCH 1/3] feat: export MediaType from http_parser --- pkgs/http/lib/http.dart | 2 ++ 1 file changed, 2 insertions(+) diff --git a/pkgs/http/lib/http.dart b/pkgs/http/lib/http.dart index 31043f0e32..dda7fede3d 100644 --- a/pkgs/http/lib/http.dart +++ b/pkgs/http/lib/http.dart @@ -14,6 +14,8 @@ import 'src/request.dart'; import 'src/response.dart'; import 'src/streamed_request.dart'; +export 'package:http_parser/http_parser.dart' show MediaType; + export 'src/abortable.dart'; export 'src/base_client.dart'; export 'src/base_request.dart'; From 008477ae7de4a6ae8889a6149e38e442483966d5 Mon Sep 17 00:00:00 2001 From: Benjamin Schoenberger <25782944+Reprevise@users.noreply.github.com> Date: Tue, 5 Aug 2025 10:14:36 -0400 Subject: [PATCH 2/3] update tests to use MediaType exported from http package --- pkgs/http/test/multipart_test.dart | 13 ++++++++----- pkgs/http/test/utils.dart | 3 +-- 2 files changed, 9 insertions(+), 7 deletions(-) diff --git a/pkgs/http/test/multipart_test.dart b/pkgs/http/test/multipart_test.dart index 951e99017a..ef0fe85e77 100644 --- a/pkgs/http/test/multipart_test.dart +++ b/pkgs/http/test/multipart_test.dart @@ -6,7 +6,6 @@ import 'dart:async'; import 'package:http/http.dart' as http; import 'package:http/src/boundary_characters.dart'; -import 'package:http_parser/http_parser.dart'; import 'package:test/test.dart'; import 'utils.dart'; @@ -21,7 +20,8 @@ void main() { test('boundary characters', () { var testBoundary = String.fromCharCodes(boundaryCharacters); - var contentType = MediaType.parse('text/plain; boundary=$testBoundary'); + var contentType = + http.MediaType.parse('text/plain; boundary=$testBoundary'); var boundary = contentType.parameters['boundary']; expect(boundary, testBoundary); }); @@ -159,7 +159,7 @@ void main() { test('with a string file with a content-type but no charset', () { var request = http.MultipartRequest('POST', dummyUrl); var file = http.MultipartFile.fromString('file', '{"hello": "world"}', - contentType: MediaType('application', 'json')); + contentType: http.MediaType('application', 'json')); request.files.add(file); expect(request, bodyMatches(''' @@ -175,8 +175,11 @@ void main() { test('with a file with a iso-8859-1 body', () { var request = http.MultipartRequest('POST', dummyUrl); // "Ã¥" encoded as ISO-8859-1 and then read as UTF-8 results in "å". - var file = http.MultipartFile.fromString('file', 'non-ascii: "Ã¥"', - contentType: MediaType('text', 'plain', {'charset': 'iso-8859-1'})); + var file = http.MultipartFile.fromString( + 'file', + 'non-ascii: "Ã¥"', + contentType: http.MediaType('text', 'plain', {'charset': 'iso-8859-1'}), + ); request.files.add(file); expect(request, bodyMatches(''' diff --git a/pkgs/http/test/utils.dart b/pkgs/http/test/utils.dart index d4c319f73f..afa0b93067 100644 --- a/pkgs/http/test/utils.dart +++ b/pkgs/http/test/utils.dart @@ -5,7 +5,6 @@ import 'dart:convert'; import 'package:http/http.dart' as http; -import 'package:http_parser/http_parser.dart'; import 'package:test/test.dart'; /// A dummy URL for constructing requests that won't be sent. @@ -91,7 +90,7 @@ class _BodyMatches extends Matcher { Future _checks(http.MultipartRequest item) async { var bodyBytes = await item.finalize().toBytes(); var body = utf8.decode(bodyBytes); - var contentType = MediaType.parse(item.headers['content-type']!); + var contentType = http.MediaType.parse(item.headers['content-type']!); var boundary = contentType.parameters['boundary']!; var expected = cleanUpLiteral(_pattern) .replaceAll('\n', '\r\n') From 54bd931482dcf88396e85092d56465dfc79e2998 Mon Sep 17 00:00:00 2001 From: Benjamin Schoenberger <25782944+Reprevise@users.noreply.github.com> Date: Mon, 6 Oct 2025 19:51:30 -0400 Subject: [PATCH 3/3] Add CHANGELOG entry --- pkgs/http/CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/pkgs/http/CHANGELOG.md b/pkgs/http/CHANGELOG.md index 4c0c31af84..6d84d9c080 100644 --- a/pkgs/http/CHANGELOG.md +++ b/pkgs/http/CHANGELOG.md @@ -3,6 +3,7 @@ * **Breaking** Change the behavior of `Request.body` so that a charset parameter is only added for text and XML media types. This brings the behavior of `package:http` in line with RFC-8259. +* Export `MediaType` from `package:http_parser`. ## 1.5.0