From b620bf853cd3a80cd5a7b446983fcea5bbafa555 Mon Sep 17 00:00:00 2001 From: thomashii Date: Sat, 10 Jul 2021 10:17:05 +0800 Subject: [PATCH] Updated body_parser --- packages/body_parser/CHANGELOG.md | 4 ++++ packages/body_parser/README.md | 4 ++-- packages/body_parser/pubspec.yaml | 4 ++-- packages/body_parser/test/form_data_test.dart | 13 ++++++++++++- packages/body_parser/test/server_test.dart | 13 ++++++++++++- 5 files changed, 32 insertions(+), 6 deletions(-) diff --git a/packages/body_parser/CHANGELOG.md b/packages/body_parser/CHANGELOG.md index 37320d3a..45224779 100644 --- a/packages/body_parser/CHANGELOG.md +++ b/packages/body_parser/CHANGELOG.md @@ -1,5 +1,9 @@ # Change Log +## 2.1.1 + +* Fixed calling deprecated methods in unit test + ## 2.1.0 * Replaced `http_server` with `belatuk_http_server` diff --git a/packages/body_parser/README.md b/packages/body_parser/README.md index 82a77ca7..b77eeb35 100644 --- a/packages/body_parser/README.md +++ b/packages/body_parser/README.md @@ -1,6 +1,6 @@ # Angel3 Body Parser -[![version](https://img.shields.io/badge/pub-v2.1.0-brightgreen)](https://pub.dartlang.org/packages/angel3_body_parser) +[![version](https://img.shields.io/badge/pub-v2.1.1-brightgreen)](https://pub.dartlang.org/packages/angel3_body_parser) [![Null Safety](https://img.shields.io/badge/null-safety-brightgreen)](https://dart.dev/null-safety) [![Gitter](https://img.shields.io/gitter/room/angel_dart/discussion)](https://gitter.im/angel_dart/discussion) @@ -10,7 +10,7 @@ Parse request bodies and query strings in Dart, as well multipart/form-data uploads. No external dependencies required. -This is the request body parser powering the [Angel3](https://github.com/dukefirehawk/angel) framework. If you are looking for a server-side solution with dependency injection, WebSockets, and more, then I highly recommend it as your first choice. Bam! +This is the request body parser powering the [Angel3 framework](https://github.com/dukefirehawk/angel). If you are looking for a server-side solution with dependency injection, WebSockets, and more, then I highly recommend it as your first choice. Bam! ## Contents diff --git a/packages/body_parser/pubspec.yaml b/packages/body_parser/pubspec.yaml index e6cab06c..3a6ca2c9 100644 --- a/packages/body_parser/pubspec.yaml +++ b/packages/body_parser/pubspec.yaml @@ -1,7 +1,7 @@ name: angel3_body_parser -version: 2.1.0 +version: 2.1.1 description: Parse request bodies and query strings in Dart. Supports JSON, URL-encoded, and multi-part bodies. -homepage: https://github.com/dukefirehawk/angel/tree/angel3/packages/body_parser +repository: https://github.com/dukefirehawk/angel/tree/angel3/packages/body_parser environment: sdk: '>=2.12.0 <3.0.0' dependencies: diff --git a/packages/body_parser/test/form_data_test.dart b/packages/body_parser/test/form_data_test.dart index f9624390..b3716ac3 100644 --- a/packages/body_parser/test/form_data_test.dart +++ b/packages/body_parser/test/form_data_test.dart @@ -2,9 +2,20 @@ import 'dart:io'; import 'dart:convert'; import 'package:angel3_body_parser/angel3_body_parser.dart'; import 'package:http/http.dart' as http; +import 'package:http_parser/http_parser.dart'; import 'package:test/test.dart'; import 'server_test.dart'; +Future _parseBody(HttpRequest request) { + return parseBodyFromStream( + request, + request.headers.contentType != null + ? MediaType.parse(request.headers.contentType.toString()) + : null, + request.uri, + storeOriginalBuffer: false); +} + void main() { HttpServer? server; String? url; @@ -15,7 +26,7 @@ void main() { server!.listen((HttpRequest request) async { //Server will simply return a JSON representation of the parsed body // ignore: deprecated_member_use - request.response.write(jsonEncodeBody(await parseBody(request))); + request.response.write(jsonEncodeBody(await _parseBody(request))); await request.response.close(); }); url = 'http://localhost:${server!.port}'; diff --git a/packages/body_parser/test/server_test.dart b/packages/body_parser/test/server_test.dart index 7a8b61a0..a41a24c1 100644 --- a/packages/body_parser/test/server_test.dart +++ b/packages/body_parser/test/server_test.dart @@ -3,6 +3,7 @@ import 'dart:io' show HttpRequest, HttpServer; import 'package:angel3_body_parser/angel3_body_parser.dart'; import 'package:http/http.dart' as http; +import 'package:http_parser/http_parser.dart'; import 'package:test/test.dart'; const TOKEN = @@ -26,6 +27,16 @@ String jsonEncodeBody(BodyParseResult result) { }); } +Future _parseBody(HttpRequest request) { + return parseBodyFromStream( + request, + request.headers.contentType != null + ? MediaType.parse(request.headers.contentType.toString()) + : null, + request.uri, + storeOriginalBuffer: true); +} + void main() { HttpServer? server; String? url; @@ -37,7 +48,7 @@ void main() { //Server will simply return a JSON representation of the parsed body request.response.write( // ignore: deprecated_member_use - jsonEncodeBody(await parseBody(request, storeOriginalBuffer: true))); + jsonEncodeBody(await _parseBody(request))); await request.response.close(); }); url = 'http://localhost:${server!.port}';