diff --git a/dio/CHANGELOG.md b/dio/CHANGELOG.md index 8bdad790f..eebd85f38 100644 --- a/dio/CHANGELOG.md +++ b/dio/CHANGELOG.md @@ -7,6 +7,7 @@ See the [Migration Guide][] for the complete breaking changes list.** - Raise the min Dart SDK version to 2.18.0. - Add constructor for `DioExceptionType.badCertificate`. +- Create type alias `DioMediaType` for `http_parser`'s `MediaType`. ## 5.4.3+1 diff --git a/dio/lib/src/multipart_file.dart b/dio/lib/src/multipart_file.dart index 603b333a2..013401acd 100644 --- a/dio/lib/src/multipart_file.dart +++ b/dio/lib/src/multipart_file.dart @@ -7,6 +7,9 @@ import 'multipart_file/io_multipart_file.dart' if (dart.library.html) 'multipart_file/browser_multipart_file.dart'; import 'utils.dart'; +/// The type (alias) for specifying the content-type of the `MultipartFile`. +typedef DioMediaType = MediaType; + /// A file to be uploaded as part of a [MultipartRequest]. This doesn't need to /// correspond to a physical file. /// @@ -27,7 +30,7 @@ class MultipartFile { Stream> stream, this.length, { this.filename, - MediaType? contentType, + DioMediaType? contentType, Map>? headers, }) : _data = (() => stream), headers = caseInsensitiveKeyMap(headers), @@ -43,7 +46,7 @@ class MultipartFile { Stream> Function() data, this.length, { this.filename, - MediaType? contentType, + DioMediaType? contentType, Map>? headers, }) : _data = data, headers = caseInsensitiveKeyMap(headers), @@ -56,7 +59,7 @@ class MultipartFile { factory MultipartFile.fromBytes( List value, { String? filename, - MediaType? contentType, + DioMediaType? contentType, final Map>? headers, }) { return MultipartFile.fromStream( @@ -77,7 +80,7 @@ class MultipartFile { factory MultipartFile.fromString( String value, { String? filename, - MediaType? contentType, + DioMediaType? contentType, final Map>? headers, }) { contentType ??= MediaType('text', 'plain'); @@ -106,7 +109,7 @@ class MultipartFile { final Map>? headers; /// The content-type of the file. Defaults to `application/octet-stream`. - final MediaType? contentType; + final DioMediaType? contentType; /// The stream builder that will emit the file's contents for every call. final Stream> Function() _data; @@ -125,7 +128,7 @@ class MultipartFile { static Future fromFile( String filePath, { String? filename, - MediaType? contentType, + DioMediaType? contentType, final Map>? headers, }) => multipartFileFromPath( @@ -138,7 +141,7 @@ class MultipartFile { static MultipartFile fromFileSync( String filePath, { String? filename, - MediaType? contentType, + DioMediaType? contentType, final Map>? headers, }) => multipartFileFromPathSync( diff --git a/dio/lib/src/multipart_file/io_multipart_file.dart b/dio/lib/src/multipart_file/io_multipart_file.dart index 320acfdc4..164ce2419 100644 --- a/dio/lib/src/multipart_file/io_multipart_file.dart +++ b/dio/lib/src/multipart_file/io_multipart_file.dart @@ -1,7 +1,6 @@ import 'dart:async'; import 'dart:io'; -import 'package:http_parser/http_parser.dart'; import 'package:path/path.dart' as p; import '../multipart_file.dart'; @@ -9,7 +8,7 @@ import '../multipart_file.dart'; Future multipartFileFromPath( String filePath, { String? filename, - MediaType? contentType, + DioMediaType? contentType, final Map>? headers, }) async { filename ??= p.basename(filePath); @@ -27,7 +26,7 @@ Future multipartFileFromPath( MultipartFile multipartFileFromPathSync( String filePath, { String? filename, - MediaType? contentType, + DioMediaType? contentType, final Map>? headers, }) { filename ??= p.basename(filePath); diff --git a/dio/test/formdata_test.dart b/dio/test/formdata_test.dart index 3c530d7c4..b416adcdd 100644 --- a/dio/test/formdata_test.dart +++ b/dio/test/formdata_test.dart @@ -2,7 +2,6 @@ import 'dart:convert'; import 'dart:io'; import 'package:dio/dio.dart'; -import 'package:http_parser/http_parser.dart'; import 'package:test/test.dart'; import 'mock/adapters.dart'; @@ -36,7 +35,7 @@ void main() async { headers: { 'test': ['c'], }, - contentType: MediaType.parse('text/plain'), + contentType: DioMediaType.parse('text/plain'), ), ], }); @@ -88,7 +87,7 @@ void main() async { headers: { 'test': ['c'], }, - contentType: MediaType.parse('text/plain'), + contentType: DioMediaType.parse('text/plain'), ), ), ); @@ -124,7 +123,7 @@ void main() async { headers: { 'test': ['c'], }, - contentType: MediaType.parse('text/plain'), + contentType: DioMediaType.parse('text/plain'), ), ], }); diff --git a/dio/test/multipart_file_test.dart b/dio/test/multipart_file_test.dart index 424b1f354..b858736ee 100644 --- a/dio/test/multipart_file_test.dart +++ b/dio/test/multipart_file_test.dart @@ -1,5 +1,4 @@ import 'package:dio/dio.dart'; -import 'package:http_parser/http_parser.dart'; import 'package:test/test.dart'; void main() async { @@ -7,7 +6,7 @@ void main() async { test( 'fromFile sets correct content-type', () async { - final mediaType = MediaType.parse('text/plain'); + final mediaType = DioMediaType.parse('text/plain'); final file = await MultipartFile.fromFile( 'test/mock/_testfile', filename: '1.txt',