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/
|
||||
build/
|
||||
#**/packages/
|
||||
packages/hubbub/
|
||||
|
||||
# Files created by dart2js
|
||||
# (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.
|
||||
version: 4.0.4
|
||||
homepage: https://github.com/dukefirehawk/angel/tree/angel3/packages/auth
|
||||
#publish_to: none
|
||||
environment:
|
||||
sdk: '>=2.12.0 <3.0.0'
|
||||
dependencies:
|
||||
|
|
|
@ -14,7 +14,7 @@ class _User {
|
|||
Map<String, dynamic> toJson() => {'handle': handle};
|
||||
}
|
||||
|
||||
main() async {
|
||||
void main() async {
|
||||
var app = Angel();
|
||||
var http = AngelHttp(app);
|
||||
var auth = AngelAuth<_User>(
|
||||
|
@ -48,7 +48,7 @@ main() async {
|
|||
if (e.isDenial) {
|
||||
res.write("Why'd you say no???");
|
||||
} else {
|
||||
res.write("oops: ${e.message}");
|
||||
res.write('oops: ${e.message}');
|
||||
}
|
||||
},
|
||||
);
|
||||
|
@ -57,18 +57,17 @@ main() async {
|
|||
..fallback(auth.decodeJwt)
|
||||
..get('/', auth.authenticate('twitter'));
|
||||
|
||||
app
|
||||
..get(
|
||||
'/auth/twitter/callback',
|
||||
auth.authenticate(
|
||||
'twitter',
|
||||
AngelAuthOptions(
|
||||
callback: (req, res, jwt) {
|
||||
return res.redirect('/home?token=$jwt');
|
||||
},
|
||||
),
|
||||
app.get(
|
||||
'/auth/twitter/callback',
|
||||
auth.authenticate(
|
||||
'twitter',
|
||||
AngelAuthOptions(
|
||||
callback: (req, res, jwt) {
|
||||
return res.redirect('/home?token=$jwt');
|
||||
},
|
||||
),
|
||||
);
|
||||
),
|
||||
);
|
||||
|
||||
app.get(
|
||||
'/home',
|
||||
|
|
|
@ -32,7 +32,7 @@ class TwitterStrategy<User> extends AuthStrategy<User> {
|
|||
|
||||
TwitterStrategy(this.options, this.verifier, this.onError,
|
||||
{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(
|
||||
consumerId: options.clientId, consumerKey: options.clientSecret);
|
||||
_client = oauth.Client(tokens, client: client);
|
||||
|
|
|
@ -1,14 +1,15 @@
|
|||
# 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/angel-dart/body_parser.svg)](https://travis-ci.org/angel-dart/body_parser)
|
||||
# Angel3 Body Parser
|
||||
[![version](https://img.shields.io/badge/pub-v2.0.0-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)
|
||||
|
||||
Parse request bodies and query strings in Dart, as well multipart/form-data uploads. No external
|
||||
dependencies required.
|
||||
[![License](https://img.shields.io/github/license/dukefirehawk/angel)](https://github.com/dukefirehawk/angel/tree/angel3/packages/body_parser/LICENSE)
|
||||
|
||||
This is the request body parser powering the
|
||||
[Angel](https://angel-dart.github.io)
|
||||
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!
|
||||
**Forked from `body_parser` to support NNBD**
|
||||
|
||||
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!
|
||||
|
||||
### Contents
|
||||
|
||||
|
@ -33,7 +34,7 @@ To install Body Parser for your Dart project, simply add body_parser to your
|
|||
pub dependencies.
|
||||
|
||||
dependencies:
|
||||
body_parser: any
|
||||
angel3_body_parser: ^2.0.0
|
||||
|
||||
# Usage
|
||||
|
||||
|
@ -42,7 +43,7 @@ You can easily parse the query string and request body for a request by calling
|
|||
|
||||
```dart
|
||||
import 'dart:convert';
|
||||
import 'package:body_parser/body_parser.dart';
|
||||
import 'package:angel3_body_parser/angel3_body_parser.dart';
|
||||
|
||||
main() async {
|
||||
// ...
|
||||
|
@ -55,8 +56,7 @@ main() async {
|
|||
|
||||
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)
|
||||
to build structured JSON/REST APIs. Add validation and you've got an instant backend.
|
||||
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.
|
||||
|
||||
```dart
|
||||
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
|
||||
request buffer. To get this functionality, pass `storeOriginalBuffer` as `true` when calling `parseBody`.
|
||||
|
||||
For example, if you wanted to
|
||||
[parse GraphQL queries within your server](https://github.com/angel-dart/graphql)...
|
||||
For example, if you wanted to [parse GraphQL queries within your server](https://github.com/dukefirehawk/graphql_dart)...
|
||||
|
||||
```dart
|
||||
app.get('/graphql', (req, res) async {
|
||||
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:isolate';
|
||||
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 {
|
||||
var address = '127.0.0.1';
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
/// A library for parsing HTTP request bodies and queries.
|
||||
library body_parser;
|
||||
library angel3_body_parser;
|
||||
|
||||
export 'src/body_parse_result.dart';
|
||||
export 'src/file_upload_info.dart';
|
|
@ -1,7 +1,7 @@
|
|||
name: body_parser
|
||||
name: angel3_body_parser
|
||||
version: 2.0.0
|
||||
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:
|
||||
sdk: '>=2.12.0 <3.0.0'
|
||||
dependencies:
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
import 'dart:io';
|
||||
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:test/test.dart';
|
||||
import 'server_test.dart';
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
import 'dart:convert';
|
||||
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:test/test.dart';
|
||||
|
||||
|
@ -93,8 +93,8 @@ void main() {
|
|||
};
|
||||
test('POST Simple', () async {
|
||||
print('Body: hello=world');
|
||||
var response = await client!.post(Uri.parse(url!),
|
||||
headers: headers, body: 'hello=world');
|
||||
var response = await client!
|
||||
.post(Uri.parse(url!), headers: headers, body: 'hello=world');
|
||||
print('Response: ${response.body}');
|
||||
var result = json.decode(response.body);
|
||||
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 oldSerializer!(value);
|
||||
return oldSerializer(value);
|
||||
};
|
||||
|
||||
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
|
||||
publish_to: none
|
||||
environment:
|
||||
sdk: '>=2.10.0 <3.0.0'
|
||||
sdk: '>=2.12.0 <3.0.0'
|
||||
dependencies:
|
||||
angel_framework:
|
||||
git:
|
||||
|
|
Loading…
Reference in a new issue