Updated body_parser

This commit is contained in:
thomashii 2021-07-10 10:17:05 +08:00
parent 346389f1ef
commit b620bf853c
5 changed files with 32 additions and 6 deletions

View file

@ -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`

View file

@ -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

View file

@ -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:

View file

@ -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<BodyParseResult> _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}';

View file

@ -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<BodyParseResult> _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}';