Skip to content

Commit 6271faf

Browse files
authored
feat: export MediaType from http_parser (#1803)
1 parent 32dee0c commit 6271faf

File tree

4 files changed

+12
-7
lines changed

4 files changed

+12
-7
lines changed

pkgs/http/CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
* **Breaking** Change the behavior of `Request.body` so that a charset
44
parameter is only added for text and XML media types. This brings the
55
behavior of `package:http` in line with RFC-8259.
6+
* Export `MediaType` from `package:http_parser`.
67

78
## 1.5.0
89

pkgs/http/lib/http.dart

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@ import 'src/request.dart';
1414
import 'src/response.dart';
1515
import 'src/streamed_request.dart';
1616

17+
export 'package:http_parser/http_parser.dart' show MediaType;
18+
1719
export 'src/abortable.dart';
1820
export 'src/base_client.dart';
1921
export 'src/base_request.dart';

pkgs/http/test/multipart_test.dart

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ import 'dart:async';
66

77
import 'package:http/http.dart' as http;
88
import 'package:http/src/boundary_characters.dart';
9-
import 'package:http_parser/http_parser.dart';
109
import 'package:test/test.dart';
1110

1211
import 'utils.dart';
@@ -21,7 +20,8 @@ void main() {
2120

2221
test('boundary characters', () {
2322
var testBoundary = String.fromCharCodes(boundaryCharacters);
24-
var contentType = MediaType.parse('text/plain; boundary=$testBoundary');
23+
var contentType =
24+
http.MediaType.parse('text/plain; boundary=$testBoundary');
2525
var boundary = contentType.parameters['boundary'];
2626
expect(boundary, testBoundary);
2727
});
@@ -159,7 +159,7 @@ void main() {
159159
test('with a string file with a content-type but no charset', () {
160160
var request = http.MultipartRequest('POST', dummyUrl);
161161
var file = http.MultipartFile.fromString('file', '{"hello": "world"}',
162-
contentType: MediaType('application', 'json'));
162+
contentType: http.MediaType('application', 'json'));
163163
request.files.add(file);
164164

165165
expect(request, bodyMatches('''
@@ -175,8 +175,11 @@ void main() {
175175
test('with a file with a iso-8859-1 body', () {
176176
var request = http.MultipartRequest('POST', dummyUrl);
177177
// "Ã¥" encoded as ISO-8859-1 and then read as UTF-8 results in "å".
178-
var file = http.MultipartFile.fromString('file', 'non-ascii: "Ã¥"',
179-
contentType: MediaType('text', 'plain', {'charset': 'iso-8859-1'}));
178+
var file = http.MultipartFile.fromString(
179+
'file',
180+
'non-ascii: "Ã¥"',
181+
contentType: http.MediaType('text', 'plain', {'charset': 'iso-8859-1'}),
182+
);
180183
request.files.add(file);
181184

182185
expect(request, bodyMatches('''

pkgs/http/test/utils.dart

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
import 'dart:convert';
66

77
import 'package:http/http.dart' as http;
8-
import 'package:http_parser/http_parser.dart';
98
import 'package:test/test.dart';
109

1110
/// A dummy URL for constructing requests that won't be sent.
@@ -91,7 +90,7 @@ class _BodyMatches extends Matcher {
9190
Future<void> _checks(http.MultipartRequest item) async {
9291
var bodyBytes = await item.finalize().toBytes();
9392
var body = utf8.decode(bodyBytes);
94-
var contentType = MediaType.parse(item.headers['content-type']!);
93+
var contentType = http.MediaType.parse(item.headers['content-type']!);
9594
var boundary = contentType.parameters['boundary']!;
9695
var expected = cleanUpLiteral(_pattern)
9796
.replaceAll('\n', '\r\n')

0 commit comments

Comments
 (0)