diff --git a/.gitignore b/.gitignore
index 70817aa5..b4d6e266 100644
--- a/.gitignore
+++ b/.gitignore
@@ -1,43 +1,39 @@
-### VisualStudioCode template
-.settings
-
+# Created by .ignore support plugin (hsz.mobi)
### JetBrains template
-# Covers JetBrains IDEs: IntelliJ, RubyMine, PhpStorm, AppCode, PyCharm, CLion, Android Studio
-
-*.iml
-
-## Directory-based project format:
-.idea
-/Test Results - Run_All_Tests.html
-# if you remove the above rule, at least ignore the following:
+# Covers JetBrains IDEs: IntelliJ, RubyMine, PhpStorm, AppCode, PyCharm, CLion, Android Studio and Webstorm
+# Reference: https://intellij-support.jetbrains.com/hc/en-us/articles/206544839
# User-specific stuff:
-# .idea/workspace.xml
-# .idea/tasks.xml
-# .idea/dictionaries
+.idea/**/workspace.xml
+.idea/**/tasks.xml
+.idea/dictionaries
# Sensitive or high-churn files:
-# .idea/dataSources.ids
-# .idea/dataSources.xml
-# .idea/sqlDataSources.xml
-# .idea/dynamic.xml
-# .idea/uiDesigner.xml
+.idea/**/dataSources/
+.idea/**/dataSources.ids
+.idea/**/dataSources.xml
+.idea/**/dataSources.local.xml
+.idea/**/sqlDataSources.xml
+.idea/**/dynamic.xml
+.idea/**/uiDesigner.xml
# Gradle:
-# .idea/gradle.xml
-# .idea/libraries
+.idea/**/gradle.xml
+.idea/**/libraries
+
+# CMake
+cmake-build-debug/
# Mongo Explorer plugin:
-# .idea/mongoSettings.xml
+.idea/**/mongoSettings.xml
## File-based project format:
-*.ipr
*.iws
## Plugin-specific files:
# IntelliJ
-/out/
+out/
# mpeltonen/sbt-idea plugin
.idea_modules/
@@ -45,27 +41,24 @@
# JIRA plugin
atlassian-ide-plugin.xml
+# Cursive Clojure plugin
+.idea/replstate.xml
+
# Crashlytics plugin (for Android Studio and IntelliJ)
com_crashlytics_export_strings.xml
crashlytics.properties
crashlytics-build.properties
-
+fabric.properties
### Dart template
-# Don't commit the following directories created by pub.
-.buildlog
+# See https://www.dartlang.org/tools/private-files.html
+
+# Files and directories created by pub
+.packages
.pub/
build/
-packages
-.packages
-
-# Or the files created by dart2js.
-*.dart.js
-*.js_
-*.js.deps
-*.js.map
-
-# Include when developing application packages.
+# If you're building an application, you may want to check-in your pubspec.lock
pubspec.lock
-doc/api
-
+# Directory created by dartdoc
+# If you don't generate documentation locally you can remove this line.
+doc/api/
diff --git a/.idea/body_parser.iml b/.idea/body_parser.iml
new file mode 100644
index 00000000..0fd729f3
--- /dev/null
+++ b/.idea/body_parser.iml
@@ -0,0 +1,14 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/.idea/libraries/Dart_Packages.xml b/.idea/libraries/Dart_Packages.xml
index d2bdf597..83757bd2 100644
--- a/.idea/libraries/Dart_Packages.xml
+++ b/.idea/libraries/Dart_Packages.xml
@@ -5,407 +5,408 @@
-
+
-
+
-
+
-
+
-
+
-
+
-
+
-
+
-
+
-
+
-
+
-
+
-
+
-
+
-
+
-
+
-
+
-
+
-
+
-
+
-
+
-
+
-
+
-
+
-
+
-
+
-
+
-
+
-
+
-
+
-
+
-
+
-
+
-
+
-
+
-
+
-
+
-
+
-
+
-
+
-
+
-
+
-
+
-
+
-
+
-
+
-
+
-
+
-
+
-
+
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/.idea/modules.xml b/.idea/modules.xml
new file mode 100644
index 00000000..9c283837
--- /dev/null
+++ b/.idea/modules.xml
@@ -0,0 +1,8 @@
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/.idea/runConfigurations/server_dart.xml b/.idea/runConfigurations/server_dart.xml
new file mode 100644
index 00000000..2171ad5d
--- /dev/null
+++ b/.idea/runConfigurations/server_dart.xml
@@ -0,0 +1,7 @@
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/.idea/vcs.xml b/.idea/vcs.xml
new file mode 100644
index 00000000..35eb1ddf
--- /dev/null
+++ b/.idea/vcs.xml
@@ -0,0 +1,6 @@
+
+
+
+
+
+
\ No newline at end of file
diff --git a/README.md b/README.md
index 7c1ffb18..6c577eab 100644
--- a/README.md
+++ b/README.md
@@ -1,6 +1,6 @@
# body_parser
[![Pub](https://img.shields.io/pub/v/body_parser.svg)](https://pub.dartlang.org/packages/body_parser)
-![build status](https://travis-ci.org/thosakwe/body_parser.svg)
+[![build status](https://travis-ci.org/angel-dart/body_parser.svg)](https://travis-ci.org/angel-dart/body_parser)
Parse request bodies and query strings in Dart, as well multipart/form-data uploads. No external
dependencies required.
diff --git a/analysis_options.yaml b/analysis_options.yaml
new file mode 100644
index 00000000..518eb901
--- /dev/null
+++ b/analysis_options.yaml
@@ -0,0 +1,2 @@
+analyzer:
+ strong-mode: true
\ No newline at end of file
diff --git a/example/post.lua b/example/post.lua
new file mode 100644
index 00000000..524febc6
--- /dev/null
+++ b/example/post.lua
@@ -0,0 +1,6 @@
+-- example HTTP POST script which demonstrates setting the
+-- HTTP method, body, and adding a header
+
+wrk.method = "POST"
+wrk.body = "foo=bar&baz=quux"
+wrk.headers["Content-Type"] = "application/x-www-form-urlencoded"
\ No newline at end of file
diff --git a/example/server.dart b/example/server.dart
new file mode 100644
index 00000000..791d0524
--- /dev/null
+++ b/example/server.dart
@@ -0,0 +1,40 @@
+import 'dart:async';
+import 'dart:convert';
+import 'dart:io';
+import 'dart:isolate';
+import 'package:body_parser/body_parser.dart';
+
+main() async {
+ var address = InternetAddress.LOOPBACK_IP_V4;
+ var port = 3000;
+ var futures = [];
+
+ for (int i = 1; i < Platform.numberOfProcessors; i++) {
+ futures.add(Isolate.spawn(start, [address.address, port, i]));
+ }
+
+ Future.wait(futures).then((_) {
+ print('All instances started.');
+ print(
+ 'Test with "wrk -t12 -c400 -d30s -s ./example/post.lua http://localhost:3000" or similar');
+ start([address.address, port, 0]);
+ });
+}
+
+void start(List args) {
+ var address = new InternetAddress(args[0]);
+ int port = args[1], id = args[2];
+
+ HttpServer.bind(address, port, shared: true).then((server) {
+ server.listen((request) async {
+ var body = await parseBody(request);
+ request.response
+ ..headers.contentType = ContentType.JSON
+ ..write(JSON.encode(body.body))
+ ..close();
+ });
+
+ print(
+ 'Server #$id listening at http://${server.address.address}:${server.port}');
+ });
+}
diff --git a/lib/body_parser.dart b/lib/body_parser.dart
index 778bc540..0541b3e6 100644
--- a/lib/body_parser.dart
+++ b/lib/body_parser.dart
@@ -1,7 +1,6 @@
/// A library for parsing HTTP request bodies and queries.
library body_parser;
-export 'src/body_parser.dart';
export 'src/body_parse_result.dart';
export 'src/file_upload_info.dart';
export 'src/parse_body.dart';
diff --git a/lib/src/body_parser.dart b/lib/src/body_parser.dart
deleted file mode 100644
index ad199e7b..00000000
--- a/lib/src/body_parser.dart
+++ /dev/null
@@ -1,21 +0,0 @@
-import 'dart:async';
-import 'dart:io';
-import 'body_parse_result.dart';
-
-class BodyParser implements StreamTransformer, BodyParseResult> {
-
- @override
- Stream bind(HttpRequest stream) {
- var _stream = new StreamController();
-
- stream.toList().then((lists) {
- var ints = [];
- lists.forEach(ints.addAll);
- _stream.close();
-
-
- });
-
- return _stream.stream;
- }
-}
\ No newline at end of file
diff --git a/lib/src/parse_body.dart b/lib/src/parse_body.dart
index 926f5e71..5b830502 100644
--- a/lib/src/parse_body.dart
+++ b/lib/src/parse_body.dart
@@ -19,16 +19,20 @@ Future parseBody(HttpRequest request,
{bool storeOriginalBuffer: false}) async {
var result = new _BodyParseResultImpl();
- Future> getBytes() async {
- return await request.fold([], (a, b) => a..addAll(b));
+ Future> getBytes() {
+ return request
+ .fold(new BytesBuilder(copy: false), (a, b) => a..add(b))
+ .then((b) => b.takeBytes());
}
- Future getBody() async {
+ Future getBody() {
if (storeOriginalBuffer) {
- List bytes = await getBytes();
- return Uri.decodeFull(UTF8.decode(result.originalBuffer = bytes));
+ return getBytes().then((bytes) {
+ result.originalBuffer = bytes;
+ return UTF8.decode(bytes);
+ });
} else
- return await request.transform(UTF8.decoder).join().then(Uri.decodeFull);
+ return request.transform(UTF8.decoder).join();
}
try {
@@ -56,7 +60,8 @@ Future parseBody(HttpRequest request,
await for (HttpMultipartFormData part in parts) {
if (part.isBinary ||
part.contentDisposition.parameters.containsKey("filename")) {
- BytesBuilder builder = await part.fold(new BytesBuilder(),
+ BytesBuilder builder = await part.fold(
+ new BytesBuilder(copy: false),
(BytesBuilder b, d) => b..add(d is! String ? d : d.codeUnits));
var upload = new FileUploadInfo(
mimeType: part.contentType.mimeType,
diff --git a/pubspec.yaml b/pubspec.yaml
index f376b47f..dd230230 100644
--- a/pubspec.yaml
+++ b/pubspec.yaml
@@ -1,6 +1,6 @@
name: body_parser
author: Tobe O
-version: 1.0.2
+version: 1.0.3
description: Parse request bodies and query strings in Dart.
homepage: https://github.com/angel-dart/body_parser
dependencies:
diff --git a/test/all_test.dart b/test/all_test.dart
deleted file mode 100644
index 0686d5f0..00000000
--- a/test/all_test.dart
+++ /dev/null
@@ -1,9 +0,0 @@
-import 'package:test/test.dart';
-
-import 'server.dart' as server;
-import 'uploads.dart' as uploads;
-
-main() {
- group('server', server.main);
- group('uploads', uploads.main);
-}
diff --git a/test/uploads.dart b/test/form_data_test.dart
similarity index 100%
rename from test/uploads.dart
rename to test/form_data_test.dart
diff --git a/test/server.dart b/test/server_test.dart
similarity index 100%
rename from test/server.dart
rename to test/server_test.dart