Published body_parser
This commit is contained in:
parent
62f2235a6d
commit
3dda3cf844
12 changed files with 38 additions and 42 deletions
1
.gitignore
vendored
1
.gitignore
vendored
|
@ -14,7 +14,6 @@
|
||||||
.metals/
|
.metals/
|
||||||
build/
|
build/
|
||||||
#**/packages/
|
#**/packages/
|
||||||
packages/hubbub/
|
|
||||||
|
|
||||||
# Files created by dart2js
|
# Files created by dart2js
|
||||||
# (Most Dart developers will use pub build to compile Dart, use/modify these
|
# (Most Dart developers will use pub build to compile Dart, use/modify these
|
||||||
|
|
|
@ -2,7 +2,6 @@ name: angel3_auth
|
||||||
description: A complete authentication plugin for Angel. Includes support for stateless JWT tokens, Basic Auth, and more.
|
description: A complete authentication plugin for Angel. Includes support for stateless JWT tokens, Basic Auth, and more.
|
||||||
version: 4.0.4
|
version: 4.0.4
|
||||||
homepage: https://github.com/dukefirehawk/angel/tree/angel3/packages/auth
|
homepage: https://github.com/dukefirehawk/angel/tree/angel3/packages/auth
|
||||||
#publish_to: none
|
|
||||||
environment:
|
environment:
|
||||||
sdk: '>=2.12.0 <3.0.0'
|
sdk: '>=2.12.0 <3.0.0'
|
||||||
dependencies:
|
dependencies:
|
||||||
|
|
|
@ -14,7 +14,7 @@ class _User {
|
||||||
Map<String, dynamic> toJson() => {'handle': handle};
|
Map<String, dynamic> toJson() => {'handle': handle};
|
||||||
}
|
}
|
||||||
|
|
||||||
main() async {
|
void main() async {
|
||||||
var app = Angel();
|
var app = Angel();
|
||||||
var http = AngelHttp(app);
|
var http = AngelHttp(app);
|
||||||
var auth = AngelAuth<_User>(
|
var auth = AngelAuth<_User>(
|
||||||
|
@ -48,7 +48,7 @@ main() async {
|
||||||
if (e.isDenial) {
|
if (e.isDenial) {
|
||||||
res.write("Why'd you say no???");
|
res.write("Why'd you say no???");
|
||||||
} else {
|
} else {
|
||||||
res.write("oops: ${e.message}");
|
res.write('oops: ${e.message}');
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
);
|
);
|
||||||
|
@ -57,8 +57,7 @@ main() async {
|
||||||
..fallback(auth.decodeJwt)
|
..fallback(auth.decodeJwt)
|
||||||
..get('/', auth.authenticate('twitter'));
|
..get('/', auth.authenticate('twitter'));
|
||||||
|
|
||||||
app
|
app.get(
|
||||||
..get(
|
|
||||||
'/auth/twitter/callback',
|
'/auth/twitter/callback',
|
||||||
auth.authenticate(
|
auth.authenticate(
|
||||||
'twitter',
|
'twitter',
|
||||||
|
|
|
@ -32,7 +32,7 @@ class TwitterStrategy<User> extends AuthStrategy<User> {
|
||||||
|
|
||||||
TwitterStrategy(this.options, this.verifier, this.onError,
|
TwitterStrategy(this.options, this.verifier, this.onError,
|
||||||
{http.BaseClient client, Uri baseUrl})
|
{http.BaseClient client, Uri baseUrl})
|
||||||
: this.baseUrl = baseUrl ?? Uri.parse('https://api.twitter.com') {
|
: baseUrl = baseUrl ?? Uri.parse('https://api.twitter.com') {
|
||||||
var tokens = oauth.Tokens(
|
var tokens = oauth.Tokens(
|
||||||
consumerId: options.clientId, consumerKey: options.clientSecret);
|
consumerId: options.clientId, consumerKey: options.clientSecret);
|
||||||
_client = oauth.Client(tokens, client: client);
|
_client = oauth.Client(tokens, client: client);
|
||||||
|
|
|
@ -1,14 +1,15 @@
|
||||||
# body_parser
|
# Angel3 Body Parser
|
||||||
[![Pub](https://img.shields.io/pub/v/body_parser.svg)](https://pub.dartlang.org/packages/body_parser)
|
[![version](https://img.shields.io/badge/pub-v2.0.0-brightgreen)](https://pub.dartlang.org/packages/angel3_body_parser)
|
||||||
[![build status](https://travis-ci.org/angel-dart/body_parser.svg)](https://travis-ci.org/angel-dart/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)
|
||||||
|
|
||||||
Parse request bodies and query strings in Dart, as well multipart/form-data uploads. No external
|
[![License](https://img.shields.io/github/license/dukefirehawk/angel)](https://github.com/dukefirehawk/angel/tree/angel3/packages/body_parser/LICENSE)
|
||||||
dependencies required.
|
|
||||||
|
|
||||||
This is the request body parser powering the
|
**Forked from `body_parser` to support NNBD**
|
||||||
[Angel](https://angel-dart.github.io)
|
|
||||||
framework. If you are looking for a server-side solution with dependency injection,
|
Parse request bodies and query strings in Dart, as well multipart/form-data uploads. No external dependencies required.
|
||||||
WebSockets, and more, then I highly recommend it as your first choice. Bam!
|
|
||||||
|
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!
|
||||||
|
|
||||||
### Contents
|
### Contents
|
||||||
|
|
||||||
|
@ -33,7 +34,7 @@ To install Body Parser for your Dart project, simply add body_parser to your
|
||||||
pub dependencies.
|
pub dependencies.
|
||||||
|
|
||||||
dependencies:
|
dependencies:
|
||||||
body_parser: any
|
angel3_body_parser: ^2.0.0
|
||||||
|
|
||||||
# Usage
|
# Usage
|
||||||
|
|
||||||
|
@ -42,7 +43,7 @@ You can easily parse the query string and request body for a request by calling
|
||||||
|
|
||||||
```dart
|
```dart
|
||||||
import 'dart:convert';
|
import 'dart:convert';
|
||||||
import 'package:body_parser/body_parser.dart';
|
import 'package:angel3_body_parser/angel3_body_parser.dart';
|
||||||
|
|
||||||
main() async {
|
main() async {
|
||||||
// ...
|
// ...
|
||||||
|
@ -55,8 +56,7 @@ main() async {
|
||||||
|
|
||||||
You can also use `buildMapFromUri(Map, String)` to populate a map from a URL encoded string.
|
You can also use `buildMapFromUri(Map, String)` to populate a map from a URL encoded string.
|
||||||
|
|
||||||
This can easily be used with a library like [JSON God](https://github.com/thosakwe/json_god)
|
This can easily be used with a library like [Angel3 JSON God](https://pub.dev/packages/angel3_json_god) to build structured JSON/REST APIs. Add validation and you've got an instant backend.
|
||||||
to build structured JSON/REST APIs. Add validation and you've got an instant backend.
|
|
||||||
|
|
||||||
```dart
|
```dart
|
||||||
MyClass create(HttpRequest request) async {
|
MyClass create(HttpRequest request) async {
|
||||||
|
@ -69,13 +69,12 @@ In cases where you need to parse unrecognized content types, `body_parser` won't
|
||||||
on its own. However, you can use the `originalBuffer` property of a `BodyParseResult` to see the original
|
on its own. However, you can use the `originalBuffer` property of a `BodyParseResult` to see the original
|
||||||
request buffer. To get this functionality, pass `storeOriginalBuffer` as `true` when calling `parseBody`.
|
request buffer. To get this functionality, pass `storeOriginalBuffer` as `true` when calling `parseBody`.
|
||||||
|
|
||||||
For example, if you wanted to
|
For example, if you wanted to [parse GraphQL queries within your server](https://github.com/dukefirehawk/graphql_dart)...
|
||||||
[parse GraphQL queries within your server](https://github.com/angel-dart/graphql)...
|
|
||||||
|
|
||||||
```dart
|
```dart
|
||||||
app.get('/graphql', (req, res) async {
|
app.get('/graphql', (req, res) async {
|
||||||
if (req.headers.contentType.mimeType == 'application/graphql') {
|
if (req.headers.contentType.mimeType == 'application/graphql') {
|
||||||
var graphQlString = new String.fromCharCodes(req.originalBuffer);
|
var graphQlString = String.fromCharCodes(req.originalBuffer);
|
||||||
// ...
|
// ...
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
|
@ -3,7 +3,7 @@ import 'dart:convert';
|
||||||
import 'dart:io';
|
import 'dart:io';
|
||||||
import 'dart:isolate';
|
import 'dart:isolate';
|
||||||
import 'package:http_parser/http_parser.dart';
|
import 'package:http_parser/http_parser.dart';
|
||||||
import 'package:body_parser/body_parser.dart';
|
import 'package:angel3_body_parser/angel3_body_parser.dart';
|
||||||
|
|
||||||
void main() async {
|
void main() async {
|
||||||
var address = '127.0.0.1';
|
var address = '127.0.0.1';
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
/// A library for parsing HTTP request bodies and queries.
|
/// A library for parsing HTTP request bodies and queries.
|
||||||
library body_parser;
|
library angel3_body_parser;
|
||||||
|
|
||||||
export 'src/body_parse_result.dart';
|
export 'src/body_parse_result.dart';
|
||||||
export 'src/file_upload_info.dart';
|
export 'src/file_upload_info.dart';
|
|
@ -1,7 +1,7 @@
|
||||||
name: body_parser
|
name: angel3_body_parser
|
||||||
version: 2.0.0
|
version: 2.0.0
|
||||||
description: Parse request bodies and query strings in Dart. Supports JSON, URL-encoded, and multi-part bodies.
|
description: Parse request bodies and query strings in Dart. Supports JSON, URL-encoded, and multi-part bodies.
|
||||||
homepage: https://github.com/angel-dart/body_parser
|
homepage: https://github.com/dukefirehawk/angel/tree/angel3/packages/body_parser
|
||||||
environment:
|
environment:
|
||||||
sdk: '>=2.12.0 <3.0.0'
|
sdk: '>=2.12.0 <3.0.0'
|
||||||
dependencies:
|
dependencies:
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
import 'dart:io';
|
import 'dart:io';
|
||||||
import 'dart:convert';
|
import 'dart:convert';
|
||||||
import 'package:body_parser/body_parser.dart';
|
import 'package:angel3_body_parser/angel3_body_parser.dart';
|
||||||
import 'package:http/http.dart' as http;
|
import 'package:http/http.dart' as http;
|
||||||
import 'package:test/test.dart';
|
import 'package:test/test.dart';
|
||||||
import 'server_test.dart';
|
import 'server_test.dart';
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
import 'dart:convert';
|
import 'dart:convert';
|
||||||
import 'dart:io' show HttpRequest, HttpServer;
|
import 'dart:io' show HttpRequest, HttpServer;
|
||||||
|
|
||||||
import 'package:body_parser/body_parser.dart';
|
import 'package:angel3_body_parser/angel3_body_parser.dart';
|
||||||
import 'package:http/http.dart' as http;
|
import 'package:http/http.dart' as http;
|
||||||
import 'package:test/test.dart';
|
import 'package:test/test.dart';
|
||||||
|
|
||||||
|
@ -93,8 +93,8 @@ void main() {
|
||||||
};
|
};
|
||||||
test('POST Simple', () async {
|
test('POST Simple', () async {
|
||||||
print('Body: hello=world');
|
print('Body: hello=world');
|
||||||
var response = await client!.post(Uri.parse(url!),
|
var response = await client!
|
||||||
headers: headers, body: 'hello=world');
|
.post(Uri.parse(url!), headers: headers, body: 'hello=world');
|
||||||
print('Response: ${response.body}');
|
print('Response: ${response.body}');
|
||||||
var result = json.decode(response.body);
|
var result = json.decode(response.body);
|
||||||
expect(result['query'], equals({}));
|
expect(result['query'], equals({}));
|
||||||
|
|
2
packages/cache/lib/src/serializer.dart
vendored
2
packages/cache/lib/src/serializer.dart
vendored
|
@ -20,7 +20,7 @@ RequestHandler cacheSerializationResults(
|
||||||
// return cache.putIfAbsent(value, () => oldSerializer(value));
|
// return cache.putIfAbsent(value, () => oldSerializer(value));
|
||||||
//}
|
//}
|
||||||
|
|
||||||
return oldSerializer!(value);
|
return oldSerializer(value);
|
||||||
};
|
};
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
|
|
|
@ -4,7 +4,7 @@ description: Shelf interop with Angel. Use this to wrap existing server code.
|
||||||
homepage: https://github.com/angel-dart/shelf
|
homepage: https://github.com/angel-dart/shelf
|
||||||
publish_to: none
|
publish_to: none
|
||||||
environment:
|
environment:
|
||||||
sdk: '>=2.10.0 <3.0.0'
|
sdk: '>=2.12.0 <3.0.0'
|
||||||
dependencies:
|
dependencies:
|
||||||
angel_framework:
|
angel_framework:
|
||||||
git:
|
git:
|
||||||
|
|
Loading…
Reference in a new issue