Resolved all issues
This commit is contained in:
parent
10e2516301
commit
374b80c44d
5 changed files with 42 additions and 34 deletions
1
.travis.yml
Normal file
1
.travis.yml
Normal file
|
@ -0,0 +1 @@
|
|||
language: dart
|
|
@ -1,5 +1,6 @@
|
|||
# Body Parser
|
||||
![version 1.0.0-dev+1](https://img.shields.io/badge/version-1.0.0--dev-red.svg)
|
||||
![version 1.0.0-dev+2](https://img.shields.io/badge/version-1.0.0--dev+2-red.svg)
|
||||
![build status](https://travis-ci.org/thosakwe/body_parser.svg)
|
||||
|
||||
**NOT YET PRODUCTION READY**
|
||||
|
||||
|
|
|
@ -17,6 +17,7 @@ import 'map_from_uri.dart';
|
|||
Future<BodyParseResult> parseBody(HttpRequest request) async {
|
||||
var result = new BodyParseResult();
|
||||
|
||||
try {
|
||||
if (request.headers.contentType != null) {
|
||||
if (request.headers.contentType.primaryType == 'multipart' &&
|
||||
request.headers.contentType.parameters.containsKey('boundary')) {
|
||||
|
@ -27,19 +28,21 @@ Future<BodyParseResult> parseBody(HttpRequest request) async {
|
|||
HttpMultipartFormData.parse(part, defaultEncoding: UTF8));
|
||||
|
||||
await for (HttpMultipartFormData part in parts) {
|
||||
if (part.isBinary || part.contentDisposition.parameters.containsKey("filename")) {
|
||||
BytesBuilder builder = await part.fold(new BytesBuilder(), (BytesBuilder b, d) => b..add(d is! String ? d : d.codeUnits));
|
||||
if (part.isBinary ||
|
||||
part.contentDisposition.parameters.containsKey("filename")) {
|
||||
BytesBuilder builder = await part.fold(new BytesBuilder(),
|
||||
(BytesBuilder b, d) => b..add(d is! String ? d : d.codeUnits));
|
||||
var upload = new FileUploadInfo(
|
||||
mimeType: part.contentType.mimeType,
|
||||
name: part.contentDisposition.parameters['name'],
|
||||
filename: part.contentDisposition.parameters['filename'] ?? 'file',
|
||||
filename:
|
||||
part.contentDisposition.parameters['filename'] ?? 'file',
|
||||
data: builder.takeBytes());
|
||||
result.files.add(upload);
|
||||
} else if (part.isText) {
|
||||
var text = await part.join();
|
||||
buildMapFromUri(result.body, '${part.contentDisposition.parameters["name"]}=$text');
|
||||
} else {
|
||||
print("Found something else : ${part.contentDisposition}");
|
||||
buildMapFromUri(result.body,
|
||||
'${part.contentDisposition.parameters["name"]}=$text');
|
||||
}
|
||||
}
|
||||
} else if (request.headers.contentType.mimeType ==
|
||||
|
@ -54,6 +57,9 @@ Future<BodyParseResult> parseBody(HttpRequest request) async {
|
|||
} else if (request.uri.hasQuery) {
|
||||
buildMapFromUri(result.query, request.uri.query);
|
||||
}
|
||||
} catch (e) {
|
||||
//
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
name: body_parser
|
||||
author: Tobe O <thosakwe@gmail.com>
|
||||
version: 1.0.0-dev+1
|
||||
version: 1.0.0-dev+2
|
||||
description: Parse request bodies and query strings in Dart.
|
||||
homepage: https://github.com/thosakwe/body_parser
|
||||
dependencies:
|
||||
|
|
Loading…
Reference in a new issue