This commit is contained in:
Tobe O 2018-06-22 23:29:38 -04:00
parent b1c4529b84
commit 5d851b6cde
37 changed files with 628 additions and 757 deletions

View file

@ -5,7 +5,7 @@
<entry key="analyzer">
<value>
<list>
<option value="$USER_HOME$/.pub-cache/hosted/pub.dartlang.org/analyzer-0.31.1/lib" />
<option value="$USER_HOME$/.pub-cache/hosted/pub.dartlang.org/analyzer-0.32.1/lib" />
</list>
</value>
</entry>
@ -33,7 +33,7 @@
<entry key="angel_route">
<value>
<list>
<option value="$USER_HOME$/.pub-cache/hosted/pub.dartlang.org/angel_route-2.0.5/lib" />
<option value="$USER_HOME$/.pub-cache/hosted/pub.dartlang.org/angel_route-2.0.7/lib" />
</list>
</value>
</entry>
@ -51,13 +51,6 @@
</list>
</value>
</entry>
<entry key="barback">
<value>
<list>
<option value="$USER_HOME$/.pub-cache/hosted/pub.dartlang.org/barback-0.15.2+16/lib" />
</list>
</value>
</entry>
<entry key="body_parser">
<value>
<list>
@ -79,13 +72,6 @@
</list>
</value>
</entry>
<entry key="cli_util">
<value>
<list>
<option value="$USER_HOME$/.pub-cache/hosted/pub.dartlang.org/cli_util-0.1.2+1/lib" />
</list>
</value>
</entry>
<entry key="code_buffer">
<value>
<list>
@ -96,14 +82,14 @@
<entry key="collection">
<value>
<list>
<option value="$USER_HOME$/.pub-cache/hosted/pub.dartlang.org/collection-1.14.9/lib" />
<option value="$USER_HOME$/.pub-cache/hosted/pub.dartlang.org/collection-1.14.10/lib" />
</list>
</value>
</entry>
<entry key="combinator">
<value>
<list>
<option value="$USER_HOME$/.pub-cache/hosted/pub.dartlang.org/combinator-1.0.0-beta+7/lib" />
<option value="$USER_HOME$/.pub-cache/hosted/pub.dartlang.org/combinator-1.0.0+3/lib" />
</list>
</value>
</entry>
@ -124,7 +110,7 @@
<entry key="crypto">
<value>
<list>
<option value="$USER_HOME$/.pub-cache/hosted/pub.dartlang.org/crypto-2.0.3/lib" />
<option value="$USER_HOME$/.pub-cache/hosted/pub.dartlang.org/crypto-2.0.5/lib" />
</list>
</value>
</entry>
@ -152,21 +138,21 @@
<entry key="front_end">
<value>
<list>
<option value="$USER_HOME$/.pub-cache/hosted/pub.dartlang.org/front_end-0.1.0-alpha.9/lib" />
<option value="$USER_HOME$/.pub-cache/hosted/pub.dartlang.org/front_end-0.1.1/lib" />
</list>
</value>
</entry>
<entry key="glob">
<value>
<list>
<option value="$USER_HOME$/.pub-cache/hosted/pub.dartlang.org/glob-1.1.5/lib" />
<option value="$USER_HOME$/.pub-cache/hosted/pub.dartlang.org/glob-1.1.6/lib" />
</list>
</value>
</entry>
<entry key="html">
<value>
<list>
<option value="$USER_HOME$/.pub-cache/hosted/pub.dartlang.org/html-0.13.3/lib" />
<option value="$USER_HOME$/.pub-cache/hosted/pub.dartlang.org/html-0.13.3+1/lib" />
</list>
</value>
</entry>
@ -180,7 +166,7 @@
<entry key="http_multi_server">
<value>
<list>
<option value="$USER_HOME$/.pub-cache/hosted/pub.dartlang.org/http_multi_server-2.0.4/lib" />
<option value="$USER_HOME$/.pub-cache/hosted/pub.dartlang.org/http_multi_server-2.0.5/lib" />
</list>
</value>
</entry>
@ -212,13 +198,6 @@
</list>
</value>
</entry>
<entry key="isolate">
<value>
<list>
<option value="$USER_HOME$/.pub-cache/hosted/pub.dartlang.org/isolate-1.1.0/lib" />
</list>
</value>
</entry>
<entry key="jael">
<value>
<list>
@ -243,14 +222,21 @@
<entry key="json_god">
<value>
<list>
<option value="$USER_HOME$/.pub-cache/hosted/pub.dartlang.org/json_god-2.0.0-beta+1/lib" />
<option value="$USER_HOME$/.pub-cache/hosted/pub.dartlang.org/json_god-2.0.0-beta+2/lib" />
</list>
</value>
</entry>
<entry key="json_rpc_2">
<value>
<list>
<option value="$USER_HOME$/.pub-cache/hosted/pub.dartlang.org/json_rpc_2-2.0.8/lib" />
</list>
</value>
</entry>
<entry key="kernel">
<value>
<list>
<option value="$USER_HOME$/.pub-cache/hosted/pub.dartlang.org/kernel-0.3.0-alpha.9/lib" />
<option value="$USER_HOME$/.pub-cache/hosted/pub.dartlang.org/kernel-0.3.1/lib" />
</list>
</value>
</entry>
@ -264,7 +250,7 @@
<entry key="matcher">
<value>
<list>
<option value="$USER_HOME$/.pub-cache/hosted/pub.dartlang.org/matcher-0.12.2+1/lib" />
<option value="$USER_HOME$/.pub-cache/hosted/pub.dartlang.org/matcher-0.12.3/lib" />
</list>
</value>
</entry>
@ -306,7 +292,7 @@
<entry key="node_preamble">
<value>
<list>
<option value="$USER_HOME$/.pub-cache/hosted/pub.dartlang.org/node_preamble-1.4.1/lib" />
<option value="$USER_HOME$/.pub-cache/hosted/pub.dartlang.org/node_preamble-1.4.2/lib" />
</list>
</value>
</entry>
@ -320,14 +306,14 @@
<entry key="package_resolver">
<value>
<list>
<option value="$USER_HOME$/.pub-cache/hosted/pub.dartlang.org/package_resolver-1.0.2/lib" />
<option value="$USER_HOME$/.pub-cache/hosted/pub.dartlang.org/package_resolver-1.0.3/lib" />
</list>
</value>
</entry>
<entry key="path">
<value>
<list>
<option value="$USER_HOME$/.pub-cache/hosted/pub.dartlang.org/path-1.5.1/lib" />
<option value="$USER_HOME$/.pub-cache/hosted/pub.dartlang.org/path-1.6.1/lib" />
</list>
</value>
</entry>
@ -341,7 +327,7 @@
<entry key="pool">
<value>
<list>
<option value="$USER_HOME$/.pub-cache/hosted/pub.dartlang.org/pool-1.3.4/lib" />
<option value="$USER_HOME$/.pub-cache/hosted/pub.dartlang.org/pool-1.3.5/lib" />
</list>
</value>
</entry>
@ -369,7 +355,7 @@
<entry key="shelf">
<value>
<list>
<option value="$USER_HOME$/.pub-cache/hosted/pub.dartlang.org/shelf-0.7.3/lib" />
<option value="$USER_HOME$/.pub-cache/hosted/pub.dartlang.org/shelf-0.7.3+1/lib" />
</list>
</value>
</entry>
@ -383,14 +369,14 @@
<entry key="shelf_static">
<value>
<list>
<option value="$USER_HOME$/.pub-cache/hosted/pub.dartlang.org/shelf_static-0.2.7/lib" />
<option value="$USER_HOME$/.pub-cache/hosted/pub.dartlang.org/shelf_static-0.2.7+1/lib" />
</list>
</value>
</entry>
<entry key="shelf_web_socket">
<value>
<list>
<option value="$USER_HOME$/.pub-cache/hosted/pub.dartlang.org/shelf_web_socket-0.2.2+1/lib" />
<option value="$USER_HOME$/.pub-cache/hosted/pub.dartlang.org/shelf_web_socket-0.2.2+2/lib" />
</list>
</value>
</entry>
@ -425,7 +411,7 @@
<entry key="stream_channel">
<value>
<list>
<option value="$USER_HOME$/.pub-cache/hosted/pub.dartlang.org/stream_channel-1.6.6/lib" />
<option value="$USER_HOME$/.pub-cache/hosted/pub.dartlang.org/stream_channel-1.6.7+1/lib" />
</list>
</value>
</entry>
@ -453,7 +439,7 @@
<entry key="test">
<value>
<list>
<option value="$USER_HOME$/.pub-cache/hosted/pub.dartlang.org/test-0.12.36/lib" />
<option value="$USER_HOME$/.pub-cache/hosted/pub.dartlang.org/test-0.12.42/lib" />
</list>
</value>
</entry>
@ -478,101 +464,107 @@
</list>
</value>
</entry>
<entry key="vm_service_client">
<value>
<list>
<option value="$USER_HOME$/.pub-cache/hosted/pub.dartlang.org/vm_service_client-0.2.4+3/lib" />
</list>
</value>
</entry>
<entry key="watcher">
<value>
<list>
<option value="$USER_HOME$/.pub-cache/hosted/pub.dartlang.org/watcher-0.9.7+7/lib" />
<option value="$USER_HOME$/.pub-cache/hosted/pub.dartlang.org/watcher-0.9.7+8/lib" />
</list>
</value>
</entry>
<entry key="web_socket_channel">
<value>
<list>
<option value="$USER_HOME$/.pub-cache/hosted/pub.dartlang.org/web_socket_channel-1.0.7/lib" />
<option value="$USER_HOME$/.pub-cache/hosted/pub.dartlang.org/web_socket_channel-1.0.8/lib" />
</list>
</value>
</entry>
<entry key="yaml">
<value>
<list>
<option value="$USER_HOME$/.pub-cache/hosted/pub.dartlang.org/yaml-2.1.13/lib" />
<option value="$USER_HOME$/.pub-cache/hosted/pub.dartlang.org/yaml-2.1.14/lib" />
</list>
</value>
</entry>
</option>
</properties>
<CLASSES>
<root url="file://$USER_HOME$/.pub-cache/hosted/pub.dartlang.org/analyzer-0.31.1/lib" />
<root url="file://$USER_HOME$/.pub-cache/hosted/pub.dartlang.org/analyzer-0.32.1/lib" />
<root url="file://$USER_HOME$/.pub-cache/hosted/pub.dartlang.org/angel_http_exception-1.0.0/lib" />
<root url="file://$USER_HOME$/.pub-cache/hosted/pub.dartlang.org/angel_jael-1.0.1/lib" />
<root url="file://$USER_HOME$/.pub-cache/hosted/pub.dartlang.org/angel_model-1.0.0/lib" />
<root url="file://$USER_HOME$/.pub-cache/hosted/pub.dartlang.org/angel_route-2.0.5/lib" />
<root url="file://$USER_HOME$/.pub-cache/hosted/pub.dartlang.org/angel_route-2.0.7/lib" />
<root url="file://$USER_HOME$/.pub-cache/hosted/pub.dartlang.org/args-1.4.3/lib" />
<root url="file://$USER_HOME$/.pub-cache/hosted/pub.dartlang.org/async-2.0.7/lib" />
<root url="file://$USER_HOME$/.pub-cache/hosted/pub.dartlang.org/barback-0.15.2+16/lib" />
<root url="file://$USER_HOME$/.pub-cache/hosted/pub.dartlang.org/body_parser-1.1.0/lib" />
<root url="file://$USER_HOME$/.pub-cache/hosted/pub.dartlang.org/boolean_selector-1.0.3/lib" />
<root url="file://$USER_HOME$/.pub-cache/hosted/pub.dartlang.org/charcode-1.1.1/lib" />
<root url="file://$USER_HOME$/.pub-cache/hosted/pub.dartlang.org/cli_util-0.1.2+1/lib" />
<root url="file://$USER_HOME$/.pub-cache/hosted/pub.dartlang.org/code_buffer-1.0.0/lib" />
<root url="file://$USER_HOME$/.pub-cache/hosted/pub.dartlang.org/collection-1.14.9/lib" />
<root url="file://$USER_HOME$/.pub-cache/hosted/pub.dartlang.org/combinator-1.0.0-beta+7/lib" />
<root url="file://$USER_HOME$/.pub-cache/hosted/pub.dartlang.org/collection-1.14.10/lib" />
<root url="file://$USER_HOME$/.pub-cache/hosted/pub.dartlang.org/combinator-1.0.0+3/lib" />
<root url="file://$USER_HOME$/.pub-cache/hosted/pub.dartlang.org/container-0.1.2/lib" />
<root url="file://$USER_HOME$/.pub-cache/hosted/pub.dartlang.org/convert-2.0.1/lib" />
<root url="file://$USER_HOME$/.pub-cache/hosted/pub.dartlang.org/crypto-2.0.3/lib" />
<root url="file://$USER_HOME$/.pub-cache/hosted/pub.dartlang.org/crypto-2.0.5/lib" />
<root url="file://$USER_HOME$/.pub-cache/hosted/pub.dartlang.org/csslib-0.14.4/lib" />
<root url="file://$USER_HOME$/.pub-cache/hosted/pub.dartlang.org/dart2_constant-1.0.1+dart2/lib" />
<root url="file://$USER_HOME$/.pub-cache/hosted/pub.dartlang.org/file-2.3.7/lib" />
<root url="file://$USER_HOME$/.pub-cache/hosted/pub.dartlang.org/front_end-0.1.0-alpha.9/lib" />
<root url="file://$USER_HOME$/.pub-cache/hosted/pub.dartlang.org/glob-1.1.5/lib" />
<root url="file://$USER_HOME$/.pub-cache/hosted/pub.dartlang.org/html-0.13.3/lib" />
<root url="file://$USER_HOME$/.pub-cache/hosted/pub.dartlang.org/front_end-0.1.1/lib" />
<root url="file://$USER_HOME$/.pub-cache/hosted/pub.dartlang.org/glob-1.1.6/lib" />
<root url="file://$USER_HOME$/.pub-cache/hosted/pub.dartlang.org/html-0.13.3+1/lib" />
<root url="file://$USER_HOME$/.pub-cache/hosted/pub.dartlang.org/http-0.11.3+16/lib" />
<root url="file://$USER_HOME$/.pub-cache/hosted/pub.dartlang.org/http_multi_server-2.0.4/lib" />
<root url="file://$USER_HOME$/.pub-cache/hosted/pub.dartlang.org/http_multi_server-2.0.5/lib" />
<root url="file://$USER_HOME$/.pub-cache/hosted/pub.dartlang.org/http_parser-3.1.2/lib" />
<root url="file://$USER_HOME$/.pub-cache/hosted/pub.dartlang.org/http_server-0.9.7/lib" />
<root url="file://$USER_HOME$/.pub-cache/hosted/pub.dartlang.org/intl-0.15.6/lib" />
<root url="file://$USER_HOME$/.pub-cache/hosted/pub.dartlang.org/io-0.3.2+1/lib" />
<root url="file://$USER_HOME$/.pub-cache/hosted/pub.dartlang.org/isolate-1.1.0/lib" />
<root url="file://$USER_HOME$/.pub-cache/hosted/pub.dartlang.org/jael-1.0.4/lib" />
<root url="file://$USER_HOME$/.pub-cache/hosted/pub.dartlang.org/jael_preprocessor-1.0.0+1/lib" />
<root url="file://$USER_HOME$/.pub-cache/hosted/pub.dartlang.org/js-0.6.1/lib" />
<root url="file://$USER_HOME$/.pub-cache/hosted/pub.dartlang.org/json_god-2.0.0-beta+1/lib" />
<root url="file://$USER_HOME$/.pub-cache/hosted/pub.dartlang.org/kernel-0.3.0-alpha.9/lib" />
<root url="file://$USER_HOME$/.pub-cache/hosted/pub.dartlang.org/json_god-2.0.0-beta+2/lib" />
<root url="file://$USER_HOME$/.pub-cache/hosted/pub.dartlang.org/json_rpc_2-2.0.8/lib" />
<root url="file://$USER_HOME$/.pub-cache/hosted/pub.dartlang.org/kernel-0.3.1/lib" />
<root url="file://$USER_HOME$/.pub-cache/hosted/pub.dartlang.org/logging-0.11.3+1/lib" />
<root url="file://$USER_HOME$/.pub-cache/hosted/pub.dartlang.org/matcher-0.12.2+1/lib" />
<root url="file://$USER_HOME$/.pub-cache/hosted/pub.dartlang.org/matcher-0.12.3/lib" />
<root url="file://$USER_HOME$/.pub-cache/hosted/pub.dartlang.org/merge_map-1.0.0/lib" />
<root url="file://$USER_HOME$/.pub-cache/hosted/pub.dartlang.org/meta-1.1.5/lib" />
<root url="file://$USER_HOME$/.pub-cache/hosted/pub.dartlang.org/mime-0.9.6+1/lib" />
<root url="file://$USER_HOME$/.pub-cache/hosted/pub.dartlang.org/mock_request-1.0.3/lib" />
<root url="file://$USER_HOME$/.pub-cache/hosted/pub.dartlang.org/multi_server_socket-1.0.1/lib" />
<root url="file://$USER_HOME$/.pub-cache/hosted/pub.dartlang.org/node_preamble-1.4.1/lib" />
<root url="file://$USER_HOME$/.pub-cache/hosted/pub.dartlang.org/node_preamble-1.4.2/lib" />
<root url="file://$USER_HOME$/.pub-cache/hosted/pub.dartlang.org/package_config-1.0.3/lib" />
<root url="file://$USER_HOME$/.pub-cache/hosted/pub.dartlang.org/package_resolver-1.0.2/lib" />
<root url="file://$USER_HOME$/.pub-cache/hosted/pub.dartlang.org/path-1.5.1/lib" />
<root url="file://$USER_HOME$/.pub-cache/hosted/pub.dartlang.org/package_resolver-1.0.3/lib" />
<root url="file://$USER_HOME$/.pub-cache/hosted/pub.dartlang.org/path-1.6.1/lib" />
<root url="file://$USER_HOME$/.pub-cache/hosted/pub.dartlang.org/plugin-0.2.0+2/lib" />
<root url="file://$USER_HOME$/.pub-cache/hosted/pub.dartlang.org/pool-1.3.4/lib" />
<root url="file://$USER_HOME$/.pub-cache/hosted/pub.dartlang.org/pool-1.3.5/lib" />
<root url="file://$USER_HOME$/.pub-cache/hosted/pub.dartlang.org/pub_semver-1.4.1/lib" />
<root url="file://$USER_HOME$/.pub-cache/hosted/pub.dartlang.org/quiver_hashcode-1.0.0/lib" />
<root url="file://$USER_HOME$/.pub-cache/hosted/pub.dartlang.org/random_string-0.0.1/lib" />
<root url="file://$USER_HOME$/.pub-cache/hosted/pub.dartlang.org/shelf-0.7.3/lib" />
<root url="file://$USER_HOME$/.pub-cache/hosted/pub.dartlang.org/shelf-0.7.3+1/lib" />
<root url="file://$USER_HOME$/.pub-cache/hosted/pub.dartlang.org/shelf_packages_handler-1.0.3/lib" />
<root url="file://$USER_HOME$/.pub-cache/hosted/pub.dartlang.org/shelf_static-0.2.7/lib" />
<root url="file://$USER_HOME$/.pub-cache/hosted/pub.dartlang.org/shelf_web_socket-0.2.2+1/lib" />
<root url="file://$USER_HOME$/.pub-cache/hosted/pub.dartlang.org/shelf_static-0.2.7+1/lib" />
<root url="file://$USER_HOME$/.pub-cache/hosted/pub.dartlang.org/shelf_web_socket-0.2.2+2/lib" />
<root url="file://$USER_HOME$/.pub-cache/hosted/pub.dartlang.org/source_map_stack_trace-1.1.4/lib" />
<root url="file://$USER_HOME$/.pub-cache/hosted/pub.dartlang.org/source_maps-0.10.5/lib" />
<root url="file://$USER_HOME$/.pub-cache/hosted/pub.dartlang.org/source_span-1.4.0/lib" />
<root url="file://$USER_HOME$/.pub-cache/hosted/pub.dartlang.org/stack_trace-1.9.2/lib" />
<root url="file://$USER_HOME$/.pub-cache/hosted/pub.dartlang.org/stream_channel-1.6.6/lib" />
<root url="file://$USER_HOME$/.pub-cache/hosted/pub.dartlang.org/stream_channel-1.6.7+1/lib" />
<root url="file://$USER_HOME$/.pub-cache/hosted/pub.dartlang.org/string_scanner-1.0.2/lib" />
<root url="file://$USER_HOME$/.pub-cache/hosted/pub.dartlang.org/symbol_table-1.0.4/lib" />
<root url="file://$USER_HOME$/.pub-cache/hosted/pub.dartlang.org/term_glyph-1.0.0/lib" />
<root url="file://$USER_HOME$/.pub-cache/hosted/pub.dartlang.org/test-0.12.36/lib" />
<root url="file://$USER_HOME$/.pub-cache/hosted/pub.dartlang.org/test-0.12.42/lib" />
<root url="file://$USER_HOME$/.pub-cache/hosted/pub.dartlang.org/tuple-1.0.1/lib" />
<root url="file://$USER_HOME$/.pub-cache/hosted/pub.dartlang.org/typed_data-1.1.5/lib" />
<root url="file://$USER_HOME$/.pub-cache/hosted/pub.dartlang.org/utf-0.9.0+4/lib" />
<root url="file://$USER_HOME$/.pub-cache/hosted/pub.dartlang.org/watcher-0.9.7+7/lib" />
<root url="file://$USER_HOME$/.pub-cache/hosted/pub.dartlang.org/web_socket_channel-1.0.7/lib" />
<root url="file://$USER_HOME$/.pub-cache/hosted/pub.dartlang.org/yaml-2.1.13/lib" />
<root url="file://$USER_HOME$/.pub-cache/hosted/pub.dartlang.org/vm_service_client-0.2.4+3/lib" />
<root url="file://$USER_HOME$/.pub-cache/hosted/pub.dartlang.org/watcher-0.9.7+8/lib" />
<root url="file://$USER_HOME$/.pub-cache/hosted/pub.dartlang.org/web_socket_channel-1.0.8/lib" />
<root url="file://$USER_HOME$/.pub-cache/hosted/pub.dartlang.org/yaml-2.1.14/lib" />
</CLASSES>
<JAVADOC />
<LIBRARY_FILE />

File diff suppressed because it is too large Load diff

View file

@ -1,3 +1,8 @@
# 1.1.4+5
* Intermediary release while patching up Dart 2 bugs.
* Stricter Dart 2 use.
* Remove `AngelMetrics` for good.
# 1.1.4+4
* Fix a bug that caused a race condition in hooked services.

View file

@ -1,5 +1,6 @@
analyzer:
strong-mode: true
strong-mode:
implicit-casts: false
linter:
rules:
- avoid_slow_async_io

View file

@ -141,12 +141,12 @@ HookedServiceEventListener remove(key, [remover(key, obj)]) {
else if (obj is List)
return obj..remove(key);
else if (obj is Iterable)
return obj.where((k) => !key);
return obj.where((k) => key != true);
else if (obj is Map)
return obj..remove(key);
else {
try {
reflect(obj).setField(new Symbol(key), null);
reflect(obj).setField(new Symbol(key.toString()), null);
return obj;
} catch (e) {
throw new ArgumentError("Cannot remove key '$key' from $obj.");

View file

@ -1,2 +0,0 @@
export 'src/stats/metric_server.dart';
export 'src/stats/stats.dart';

View file

@ -5,15 +5,17 @@ import 'service.dart';
///
/// Well-suited for testing.
class AnonymousService extends Service {
Function _index, _read, _create, _modify, _update, _remove;
Future Function([Map]) _index;
Future Function(Object, [Map]) _read, _create, _remove;
Future Function(Object, Object, [Map]) _modify, _update;
AnonymousService(
{FutureOr index([Map params]),
FutureOr read(id, [Map params]),
FutureOr create(data, [Map params]),
FutureOr modify(id, data, [Map params]),
FutureOr update(id, data, [Map params]),
FutureOr remove(id, [Map params])})
{Future index([Map params]),
Future read(id, [Map params]),
Future create(data, [Map params]),
Future modify(id, data, [Map params]),
Future update(id, data, [Map params]),
Future remove(id, [Map params])})
: super() {
_index = index;
_read = read;

View file

@ -1,8 +1,6 @@
library angel_framework.http;
import 'dart:async';
import 'package:angel_http_exception/angel_http_exception.dart';
import 'package:merge_map/merge_map.dart';
import '../util.dart';
import 'request_context.dart';
import 'response_context.dart';
@ -48,12 +46,12 @@ class HookedService extends Service {
RequestContext _getRequest(Map params) {
if (params == null) return null;
return params['__requestctx'];
return params['__requestctx'] as RequestContext;
}
ResponseContext _getResponse(Map params) {
if (params == null) return null;
return params['__responsectx'];
return params['__responsectx'] as ResponseContext;
}
Map _stripReq(Map params) {
@ -88,8 +86,7 @@ class HookedService extends Service {
/// Adds hooks to this instance.
void addHooks() {
Hooks hooks = getAnnotation(inner, Hooks);
final before = [];
final after = [];
List<HookedServiceEventListener> before = [], after = [];
if (hooks != null) {
before.addAll(hooks.before);
@ -99,7 +96,8 @@ class HookedService extends Service {
void applyListeners(Function fn, HookedServiceEventDispatcher dispatcher,
[bool isAfter]) {
Hooks hooks = getAnnotation(fn, Hooks);
final listeners = []..addAll(isAfter == true ? after : before);
final listeners = <HookedServiceEventListener>[]
..addAll(isAfter == true ? after : before);
if (hooks != null)
listeners.addAll(isAfter == true ? hooks.after : hooks.before);

View file

@ -5,7 +5,7 @@ const List<Type> _primitiveTypes = const [String, int, num, double, Null];
/// Shortcut for calling [preInject], and then [handleContained].
///
/// Use this to instantly create a request handler for a DI-enabled method.
RequestHandler createDynamicHandler(handler,
RequestHandler createDynamicHandler(Function handler,
{Iterable<String> optional: const []}) {
var injection = preInject(handler);
injection.optional.addAll(optional ?? []);
@ -77,7 +77,7 @@ bool suitableForInjection(
}
/// Handles a request with a DI-enabled handler.
RequestHandler handleContained(handler, InjectionRequest injection) {
RequestHandler handleContained(Function handler, InjectionRequest injection) {
return (RequestContext req, ResponseContext res) {
if (injection.parameters.isNotEmpty &&
injection.parameters.values.any((p) => p.match != null) &&

View file

@ -77,7 +77,7 @@ class MapService extends Service {
message:
'MapService does not support `create` with ${data.runtimeType}.');
var now = new DateTime.now().toIso8601String();
var result = data;
var result = data as Map;
if (autoIdAndDateFields == true) {
result
@ -85,7 +85,7 @@ class MapService extends Service {
..[autoSnakeCaseNames == false ? 'createdAt' : 'created_at'] = now
..[autoSnakeCaseNames == false ? 'updatedAt' : 'updated_at'] = now;
}
items.add(result);
items.add(result.cast<String, dynamic>());
return new Future.value(result);
}
@ -98,7 +98,7 @@ class MapService extends Service {
if (!items.any(_matchesId(id))) return create(data, params);
return read(id).then((item) {
var result = item..addAll(data);
var result = item..addAll(data as Map);
if (autoIdAndDateFields == true)
result
@ -121,7 +121,7 @@ class MapService extends Service {
throw new AngelHttpException.notFound(
message: 'No record found for ID $id');
var result = data;
var result = data as Map;
if (autoIdAndDateFields == true) {
result
..['id'] = id?.toString()
@ -130,7 +130,7 @@ class MapService extends Service {
..[autoSnakeCaseNames == false ? 'updatedAt' : 'updated_at'] =
new DateTime.now().toIso8601String();
}
items.add(result);
items.add(result.cast<String, dynamic>());
return new Future.value(result);
});
}

View file

@ -144,18 +144,18 @@ abstract class RequestContext {
/// within a service hook.
T grab<T>(key) {
if (params.containsKey(key))
return params[key];
return params[key] as T;
else if (_injections.containsKey(key))
return _injections[key];
return _injections[key] as T;
else if (properties.containsKey(key))
return properties[key];
return properties[key] as T;
else {
var prop = app?.findProperty(key);
if (prop != null)
return prop;
return prop as T;
else if (key is Type) {
try {
return app.container.make(key);
return app.container.make(key) as T;
} catch (e) {
return null;
}
@ -195,7 +195,7 @@ abstract class RequestContext {
throw new ArgumentError(
'RequestContext.accepts expects the `contentType` parameter to NOT be null.');
_acceptHeaderCache ??= headers.value(HttpHeaders.ACCEPT);
_acceptHeaderCache ??= headers.value('accept');
if (_acceptHeaderCache == null)
return false;

View file

@ -179,7 +179,7 @@ abstract class ResponseContext implements StreamSink<List<int>>, StringSink {
}
/// Serializes JSON to the response.
void json(value) => serialize(value, contentType: ContentType.JSON);
void json(value) => serialize(value, contentType: 'application/json');
/// Returns a JSONP response.
void jsonp(value, {String callbackName: "callback", contentType}) {
@ -202,7 +202,7 @@ abstract class ResponseContext implements StreamSink<List<int>>, StringSink {
if (!isOpen) throw closed();
return app.viewGenerator(view, data).then((content) {
write(content);
headers['content-type'] = ContentType.HTML.toString();
headers['content-type'] = 'text/html';
end();
});
}
@ -217,9 +217,9 @@ abstract class ResponseContext implements StreamSink<List<int>>, StringSink {
void redirect(url, {bool absolute: true, int code: 302}) {
if (!isOpen) throw closed();
headers
..['content-type'] = ContentType.HTML.toString()
..['content-type'] = 'text/html'
..['location'] =
url is String ? url : app.navigate(url, absolute: absolute);
url is String ? url : app.navigate(url as Iterable, absolute: absolute);
statusCode = code ?? 302;
write('''
<!DOCTYPE html>
@ -259,7 +259,7 @@ abstract class ResponseContext implements StreamSink<List<int>>, StringSink {
Route matched = _findRoute(app);
if (matched != null) {
redirect(matched.makeUri(params), code: code);
redirect(matched.makeUri(params.cast<String, dynamic>()), code: code);
return;
}
@ -290,7 +290,7 @@ abstract class ResponseContext implements StreamSink<List<int>>, StringSink {
final head =
controller.findExpose().path.toString().replaceAll(_straySlashes, '');
final tail = matched.makeUri(params).replaceAll(_straySlashes, '');
final tail = matched.makeUri(params.cast<String, dynamic>()).replaceAll(_straySlashes, '');
redirect('$head/$tail'.replaceAll(_straySlashes, ''), code: code);
}

View file

@ -8,6 +8,7 @@ import 'hooked_service.dart';
import 'metadata.dart';
import 'request_context.dart';
import 'response_context.dart';
import 'server.dart';
import 'service.dart';
final RegExp _straySlashes = new RegExp(r'(^/+)|(/+$)');
@ -16,7 +17,7 @@ final RegExp _straySlashes = new RegExp(r'(^/+)|(/+$)');
typedef Future<bool> RequestMiddleware(RequestContext req, ResponseContext res);
/// A function that receives an incoming [RequestContext] and responds to it.
typedef Future RequestHandler(RequestContext req, ResponseContext res);
typedef FutureOr RequestHandler(RequestContext req, ResponseContext res);
/// Sequentially runs a list of [handlers] of middleware, and returns early if any does not
/// return `true`. Works well with [Router].chain.
@ -31,8 +32,9 @@ RequestMiddleware waterfall(List handlers) {
runPipeline = () => req.app.executeHandler(handler, req, res);
else {
var current = runPipeline;
runPipeline = () => current().then((result) =>
!result ? result : req.app.executeHandler(handler, req, res));
runPipeline = () => current().then((result) => !result
? new Future.value(result)
: req.app.executeHandler(handler, req, res));
}
}
@ -97,7 +99,8 @@ class Routable extends Router {
handlerSequence.addAll(middleware ?? []);
handlerSequence.addAll(handlers);
return super.addRoute(method, path, handler, middleware: handlerSequence);
return super.addRoute(method, path.toString(), handler,
middleware: handlerSequence);
}
/// Mounts the given [router] on this instance.
@ -128,8 +131,8 @@ class Routable extends Router {
if (_router is AngelBase) {
handlers.add((RequestContext req, ResponseContext res) {
req.app = _router;
res.app = _router;
req.app = _router as Angel;
res.app = _router as Angel;
return true;
});
}
@ -140,7 +143,7 @@ class Routable extends Router {
Map copiedMiddleware = new Map.from(router.requestMiddleware);
for (String middlewareName in copiedMiddleware.keys) {
requestMiddleware.putIfAbsent("$middlewarePrefix$middlewareName",
() => copiedMiddleware[middlewareName]);
() => copiedMiddleware[middlewareName] as RequestHandler);
}
// Also copy properties...
@ -154,7 +157,7 @@ class Routable extends Router {
// _router.dumpTree(header: 'Mounting on "$path":');
// root.child(path, debug: debug, handlers: handlers).addChild(router.root);
var mounted = mount(path, _router);
var mounted = mount(path.toString(), _router);
if (_router is Routable) {
// Copy services, too. :)

View file

@ -31,7 +31,7 @@ typedef FutureOr AngelConfigurer(Angel app);
/// A powerful real-time/REST/MVC server class.
class Angel extends AngelBase {
final List<Angel> _children = [];
final Map<String, Tuple3<List, Map, ParseResult<Map<String, String>>>>
final Map<String, Tuple3<List, Map, ParseResult<Map<String, dynamic>>>>
handlerCache = new HashMap();
Router _flattened;
@ -186,7 +186,7 @@ class Angel extends AngelBase {
'This route will be ignored, and no requests will ever reach it.');
}
return super
.mount(path, router, hooked: hooked != false, namespace: namespace);
.mount(path.toString(), router, hooked: hooked != false, namespace: namespace);
}
/// Loads some base dependencies into the service container.

View file

@ -117,7 +117,7 @@ class Service extends Routable {
if (before != null) handlers.addAll(before.handlers);
Middleware indexMiddleware = getAnnotation(service.index, Middleware);
get('/', (req, res) {
get('/', (RequestContext req, res) {
return this.index(mergeMap([
{'query': req.query},
restProvider,
@ -154,7 +154,7 @@ class Service extends Routable {
get(
'/:id',
(req, res) => this.read(
(RequestContext req, res) => this.read(
toId(req.params['id']),
mergeMap([
{'query': req.query},
@ -214,7 +214,7 @@ class Service extends Routable {
Middleware removeMiddleware = getAnnotation(service.remove, Middleware);
delete(
'/',
(req, res) => this.remove(
(RequestContext req, res) => this.remove(
null,
mergeMap([
{'query': req.query},
@ -227,7 +227,7 @@ class Service extends Routable {
(removeMiddleware == null) ? [] : removeMiddleware.handlers));
delete(
'/:id',
(req, res) => this.remove(
(RequestContext req, res) => this.remove(
toId(req.params['id']),
mergeMap([
{'query': req.query},

View file

@ -37,15 +37,15 @@ class TypedService<T> extends Service {
Model result = god.deserializeDatum(data, outputType: T);
if (data['createdAt'] is DateTime) {
result.createdAt = data['createdAt'];
result.createdAt = data['createdAt'] as DateTime;
} else if (data['created_at'] is DateTime) {
result.createdAt = data['created_at'];
result.createdAt = data['created_at'] as DateTime;
}
if (data['updatedAt'] is DateTime) {
result.updatedAt = data['updatedAt'];
result.updatedAt = data['updatedAt'] as DateTime;
} else if (data['updated_at'] is DateTime) {
result.updatedAt = data['updated_at'];
result.updatedAt = data['updated_at'] as DateTime;
}
// print('x: $x\nresult: $result');

View file

@ -112,7 +112,7 @@ class AngelHttp {
var path = req.path;
if (path == '/') path = '';
Tuple3<List, Map, ParseResult<Map<String, String>>> resolveTuple() {
Tuple3<List, Map, ParseResult<Map<String, dynamic>>> resolveTuple() {
Router r = app.optimizedRouter;
var resolved =
r.resolveAbsolute(path, method: req.method, strip: false);
@ -147,7 +147,7 @@ class AngelHttp {
else {
var current = runPipeline;
runPipeline = () => current().then((result) =>
!result ? result : app.executeHandler(handler, req, res));
!result ? new Future.value(result) : app.executeHandler(handler, req, res));
}
}
@ -157,7 +157,7 @@ class AngelHttp {
}
if (useZone == false) {
return handle().catchError((e, st) {
return handle().catchError((e, StackTrace st) {
if (e is FormatException)
throw new AngelHttpException.badRequest(message: e.message)
..stackTrace = st;
@ -196,7 +196,7 @@ class AngelHttp {
}
return handleAngelHttpException(e, trace, req, res, request);
}).catchError((e, st) {
}).catchError((e, StackTrace st) {
var trace = new Trace.from(st ?? StackTrace.current).terse;
request.response.close();
// Ideally, we won't be in a position where an absolutely fatal error occurs,
@ -353,7 +353,7 @@ class AngelHttp {
Future<ResponseContext> createResponseContext(HttpResponse response,
[RequestContext correspondingRequest]) =>
new Future<ResponseContext>.value(
new HttpResponseContextImpl(response, app, correspondingRequest)
new HttpResponseContextImpl(response, app, correspondingRequest as HttpRequestContextImpl)
..serializer = (app.serializer ?? god.serialize)
..encoders.addAll(app.encoders ?? {}));

View file

@ -27,7 +27,7 @@ class Controller {
Controller({this.debug: false, this.injectSingleton: true});
@mustCallSuper
Future configureServer(Angel app) {
Future configureServer(Angel app) {
_app = app;
if (injectSingleton != false) _app.container.singleton(this);
@ -59,7 +59,7 @@ class Controller {
return new Future.value();
}
Function _routeBuilder(
void Function(Symbol, MethodMirror) _routeBuilder(
InstanceMirror instanceMirror, Routable routable, List handlers) {
return (Symbol methodName, MethodMirror method) {
if (method.isRegularMethod &&
@ -74,7 +74,8 @@ class Controller {
if (exposeDecl == null) return;
var reflectedMethod = instanceMirror.getField(methodName).reflectee;
var reflectedMethod =
instanceMirror.getField(methodName).reflectee as Function;
var middleware = []..addAll(handlers)..addAll(exposeDecl.middleware);
String name = exposeDecl.as?.isNotEmpty == true
? exposeDecl.as
@ -86,9 +87,10 @@ class Controller {
method.parameters[1].type.reflectedType == ResponseContext) {
// Create a regular route
routeMappings[name] = routable
.addRoute(exposeDecl.method, exposeDecl.path, (req, res) {
var result = reflectedMethod(req, res);
return result is RequestHandler ? result(req, res) : result;
.addRoute(exposeDecl.method, exposeDecl.path,
(RequestContext req, ResponseContext res) {
var result = reflectedMethod(req, res);
return result is RequestHandler ? result(req, res) : result;
}, middleware: middleware);
return;
}
@ -112,5 +114,5 @@ class Controller {
Expose findExpose() => reflectClass(runtimeType)
.metadata
.map((m) => m.reflectee)
.firstWhere((r) => r is Expose, orElse: () => null);
.firstWhere((r) => r is Expose, orElse: () => null) as Expose;
}

View file

@ -27,7 +27,7 @@ class HttpRequestContextImpl extends RequestContext {
@override
String get hostname {
return io.headers.value(HttpHeaders.HOST);
return io.headers.value('host');
}
/// The underlying [HttpRequest] instance underneath this context.

View file

@ -68,7 +68,7 @@ class HttpResponseContextImpl extends ResponseContext {
if (encoders.isNotEmpty && correspondingRequest != null) {
var allowedEncodings = correspondingRequest.headers
.value(HttpHeaders.ACCEPT_ENCODING)
.value('accept-encoding')
?.split(',')
?.map((s) => s.trim())
?.where((s) => s.isNotEmpty)
@ -92,7 +92,7 @@ class HttpResponseContextImpl extends ResponseContext {
if (encoder != null) {
if (firstStream) {
io.headers.set(HttpHeaders.CONTENT_ENCODING, key);
io.headers.set('content-encoding', key);
}
output = encoders[key].bind(output);

View file

@ -1,118 +0,0 @@
import 'dart:async';
import 'dart:io';
import '../core/core.dart';
import '../http/http.dart';
import 'stats.dart';
@deprecated
class AngelMetrics extends Angel {
Angel _inner;
StreamSubscription<HttpRequest> _sub;
AngelMetrics() : super() {
get('/metrics', (req, res) {
res.contentType = ContentType.HTML;
var rows = stats.all.map((stat) {
return '''
<tr>
<td>${stat.name}</td>
<td>${stat.iterations}</td>
<td>${stat.sum}ms</td>
<td>${stat.average.toStringAsFixed(2)}ms</td>
</tr>''';
}).join();
res.write('''
<!DOCTYPE html>
<html>
<head>
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Metrics</title>
</head>
<body>
<h1>Metrics</h1>
<i>Updated every 5 seconds</i>
<table>
<thead>
<tr>
<th>Stat</th>
<th># Iterations</th>
<th>Total (ms)</th>
<th>Average (ms)</th>
</tr>
</thead>
<tbody>$rows</tbody>
</table>
<script>
window.setTimeout(function() {
window.location.reload();
}, 5000);
</script>
</body>
</html>
''');
});
}
final AngelMetricsStats stats = new AngelMetricsStats._();
@override
Future<HttpServer> close() {
_sub?.cancel();
_inner.close();
return super.close();
}
@override
Iterable<RoutingResult> resolveAll(String absolute, String relative,
{String method: 'GET', bool strip: true}) {
return stats.resolveAll.run(() =>
_inner.resolveAll(absolute, relative, method: method, strip: strip));
}
@override
Future<bool> executeHandler(
handler, RequestContext req, ResponseContext res) {
return stats.executeHandler
.run<bool>(() => super.executeHandler(handler, req, res));
}
@override
Future getHandlerResult(handler, RequestContext req, ResponseContext res) {
return stats.getHandlerResult
.run(() => super.getHandlerResult(handler, req, res));
}
@override
Future runContained(
Function handler, RequestContext req, ResponseContext res) {
return stats.runContained.run(() => super.runContained(handler, req, res));
}
}
class AngelMetricsStats {
AngelMetricsStats._() {
all = [
resolveAll,
executeHandler,
getHandlerResult,
runContained,
];
}
final Stats resolveAll = new Stats('resolveAll');
final Stats executeHandler = new Stats('executeHandler');
final Stats getHandlerResult = new Stats('getHandlerResult');
final Stats runContained = new Stats('runContained');
List<Stats> all;
void add(Stats stats) {
all.add(stats);
}
void log() {
all.forEach((s) => s.log());
}
}

View file

@ -1,53 +0,0 @@
/// Computes averages progressively.
import 'dart:async';
class Stats {
final String name;
int _total = 0, _count = 0;
double _average = 0.0;
Stats(this.name);
double get average => _average ?? (_total / _count);
int get iterations => _count;
int get sum => _total;
void log() {
print('$name: $average avg.');
}
void add(int value) {
_average = null;
_total += value;
_count++;
}
FutureOr<T> run<T>(FutureOr<T> f()) {
var sw = new Stopwatch();
//print('--- $name START');
sw.start();
void whenDone() {
sw.stop();
var ms = sw.elapsedMilliseconds;
add(ms);
//print('--- $name DONE after ${ms}ms');
}
var r = f();
if (r is Future) {
return (r as Future).then((x) {
whenDone();
return x;
});
}
whenDone();
return r;
}
}

View file

@ -20,7 +20,7 @@ getAnnotation(obj, Type T) {
MethodMirror methodMirror = (reflect(obj) as ClosureMirror).function;
return matchingAnnotation(methodMirror.metadata, T);
} else {
ClassMirror classMirror = reflectClass(obj.runtimeType);
ClassMirror classMirror = reflectClass(obj.runtimeType as Type);
return matchingAnnotation(classMirror.metadata, T);
}
}

View file

@ -1,5 +1,5 @@
name: angel_framework
version: 1.1.4+4
version: 1.1.4+5
description: A high-powered HTTP server with DI, routing and more.
author: Tobe O <thosakwe@gmail.com>
homepage: https://github.com/angel-dart/angel_framework

View file

@ -1,5 +1,4 @@
import 'dart:async';
import 'dart:io';
import 'package:angel_framework/angel_framework.dart';
import 'package:mock_request/mock_request.dart';
import 'package:test/test.dart';
@ -10,34 +9,36 @@ main() {
test('no content type', () async {
var req = await acceptContentTypes();
expect(req.acceptsAll, isFalse);
expect(req.accepts(ContentType.JSON), isFalse);
//expect(req.accepts(ContentType.JSON), isFalse);
expect(req.accepts('application/json'), isFalse);
expect(req.accepts(ContentType.HTML), isFalse);
//expect(req.accepts(ContentType.HTML), isFalse);
expect(req.accepts('text/html'), isFalse);
});
test('wildcard', () async {
var req = await acceptContentTypes(['*/*']);
expect(req.acceptsAll, isTrue);
expect(req.accepts(ContentType.JSON), isTrue);
//expect(req.accepts(ContentType.JSON), isTrue);
expect(req.accepts('application/json'), isTrue);
expect(req.accepts(ContentType.HTML), isTrue);
//expect(req.accepts(ContentType.HTML), isTrue);
expect(req.accepts('text/html'), isTrue);
});
test('specific type', () async {
var req = await acceptContentTypes(['text/html']);
expect(req.acceptsAll, isFalse);
expect(req.accepts(ContentType.JSON), isFalse);
//expect(req.accepts(ContentType.JSON), isFalse);
expect(req.accepts('application/json'), isFalse);
expect(req.accepts(ContentType.HTML), isTrue);
//expect(req.accepts(ContentType.HTML), isTrue);
expect(req.accepts('text/html'), isTrue);
});
test('strict', () async {
var req = await acceptContentTypes(['text/html', "*/*"]);
expect(req.accepts(ContentType.HTML), isTrue);
expect(req.accepts(ContentType.JSON, strict: true), isFalse);
expect(req.accepts('text/html'), isTrue);
//expect(req.accepts(ContentType.HTML), isTrue);
//expect(req.accepts(ContentType.JSON, strict: true), isFalse);
expect(req.accepts('application/json', strict: true), isFalse);
});
group('disallow null', () {
@ -57,7 +58,7 @@ Future<RequestContext> acceptContentTypes(
[Iterable<String> contentTypes = const []]) {
var headerString = contentTypes.isEmpty ? null : contentTypes.join(',');
var rq = new MockHttpRequest('GET', ENDPOINT);
rq.headers.set(HttpHeaders.ACCEPT, headerString);
rq.headers.set('accept', headerString);
rq.close();
var app = new Angel();
var http = new AngelHttp(app);

View file

@ -100,7 +100,7 @@ main() {
test('optional name', () async {
var app = new Angel();
await app.configure(new NamedController().configureServer);
expect(app.controllers['foo'], new isInstanceOf<NamedController>());
expect(app.controllers['foo'], const TypeMatcher<NamedController>());
});
test("middleware", () async {

View file

@ -61,7 +61,7 @@ main() {
}
void validateTodoSingleton(response) {
Map todo = json.decode(response.body);
Map todo = json.decode(response.body.toString());
expect(todo["id"], equals(null));
expect(todo["text"], equals(TEXT));
expect(todo["over"], equals(OVER));

View file

@ -1,4 +1,3 @@
import 'dart:io';
import 'package:angel_framework/angel_framework.dart';
import 'package:dart2_constant/convert.dart';
import 'package:matcher/matcher.dart';
@ -7,29 +6,29 @@ import 'package:test/test.dart';
main() {
test('named constructors', () {
expect(new AngelHttpException.badRequest(),
isException(HttpStatus.BAD_REQUEST, '400 Bad Request'));
isException(400, '400 Bad Request'));
expect(new AngelHttpException.notAuthenticated(),
isException(HttpStatus.UNAUTHORIZED, '401 Not Authenticated'));
isException(401, '401 Not Authenticated'));
expect(new AngelHttpException.paymentRequired(),
isException(HttpStatus.PAYMENT_REQUIRED, '402 Payment Required'));
isException(402, '402 Payment Required'));
expect(new AngelHttpException.forbidden(),
isException(HttpStatus.FORBIDDEN, '403 Forbidden'));
isException(403, '403 Forbidden'));
expect(new AngelHttpException.notFound(),
isException(HttpStatus.NOT_FOUND, '404 Not Found'));
isException(404, '404 Not Found'));
expect(new AngelHttpException.methodNotAllowed(),
isException(HttpStatus.METHOD_NOT_ALLOWED, '405 Method Not Allowed'));
isException(405, '405 Method Not Allowed'));
expect(new AngelHttpException.notAcceptable(),
isException(HttpStatus.NOT_ACCEPTABLE, '406 Not Acceptable'));
isException(406, '406 Not Acceptable'));
expect(new AngelHttpException.methodTimeout(),
isException(HttpStatus.REQUEST_TIMEOUT, '408 Timeout'));
isException(408, '408 Timeout'));
expect(new AngelHttpException.conflict(),
isException(HttpStatus.CONFLICT, '409 Conflict'));
isException(409, '409 Conflict'));
expect(new AngelHttpException.notProcessable(),
isException(422, '422 Not Processable'));
expect(new AngelHttpException.notImplemented(),
isException(HttpStatus.NOT_IMPLEMENTED, '501 Not Implemented'));
isException(501, '501 Not Implemented'));
expect(new AngelHttpException.unavailable(),
isException(HttpStatus.SERVICE_UNAVAILABLE, '503 Unavailable'));
isException(503, '503 Unavailable'));
});
test('fromMap', () {

View file

@ -22,7 +22,7 @@ main() {
client = new http.Client();
app.use('/todos', new TypedService<Todo>(new MapService()));
app.use('/books', new BookService());
Todos = app.service("todos");
Todos = app.service("todos") as HookedService;
Todos.beforeAllStream().listen((e) {
print('Fired ${e.eventName}! Data: ${e.data}; Params: ${e.params}');
@ -71,7 +71,7 @@ main() {
});
var response = await client.post("$url/todos",
body: god.serialize({"arbitrary": "data"}), headers: headers);
body: god.serialize({"arbitrary": "data"}), headers: headers.cast<String, String>());
print(response.body);
Map result = god.deserialize(response.body);
expect(result["hello"], equals("hooked world"));
@ -97,7 +97,7 @@ main() {
test('metadata', () async {
final service = new HookedService(new IncrementService())..addHooks();
expect(service.inner, isNot(new isInstanceOf<MapService>()));
expect(service.inner, isNot(const TypeMatcher<MapService>()));
IncrementService.TIMES = 0;
await service.index();
expect(IncrementService.TIMES, equals(2));
@ -128,7 +128,7 @@ main() {
print('Params to $type ${e.eventName}: ${e.params}');
expect(e.params, isMap);
expect(e.params.keys, contains('provider'));
expect(e.params['provider'], const isInstanceOf<Providers>());
expect(e.params['provider'], const TypeMatcher<Providers>());
}
svc

View file

@ -1,7 +1,6 @@
import 'dart:async';
import 'package:dart2_constant/convert.dart';
import 'package:angel_framework/angel_framework.dart';
import 'package:logging/logging.dart';
import 'package:mock_request/mock_request.dart';
import 'package:test/test.dart';

View file

@ -18,7 +18,7 @@ main() {
'/num/parsed/:num',
waterfall([
(RequestContext req) {
req.params['n'] = num.parse(req.params['num']);
req.params['n'] = num.parse(req.params['num'].toString());
return true;
},
(num n) => n,

View file

@ -118,7 +118,7 @@ main() {
var response = await client.get('$url/name/HELLO/last/WORLD');
print('Response: ${response.body}');
var json_ = json.decode(response.body);
expect(json_, new isInstanceOf<Map<String, String>>());
expect(json_, const TypeMatcher<Map>());
expect(json_['first'], equals('HELLO'));
expect(json_['last'], equals('WORLD'));
});
@ -157,7 +157,7 @@ main() {
Map headers = {'Content-Type': 'application/json'};
String postData = json.encode({'it': 'works'});
var response =
await client.post("$url/lambda", headers: headers, body: postData);
await client.post("$url/lambda", headers: headers.cast<String, String>(), body: postData);
print('Response: ${response.body}');
expect(json.decode(response.body)['it'], equals('works'));
});

View file

@ -15,7 +15,7 @@ main() {
..get(
'/bar',
(req, ResponseContext res) =>
res.serialize({'hello': 'world'}, contentType: ContentType.HTML));
res.serialize({'hello': 'world'}, contentType: 'text/html'));
client = new http.Client();
server = await new AngelHttp(app).startServer();
@ -33,12 +33,10 @@ main() {
test("correct content-type", () async {
var response = await client.get('$url/foo');
print('Response: ${response.body}');
expect(response.headers[HttpHeaders.CONTENT_TYPE],
contains(ContentType.JSON.mimeType));
expect(response.headers['content-type'], contains('application/json'));
response = await client.get('$url/bar');
print('Response: ${response.body}');
expect(response.headers[HttpHeaders.CONTENT_TYPE],
contains(ContentType.HTML.mimeType));
expect(response.headers['content-type'], contains('text/html'));
});
}

View file

@ -47,8 +47,8 @@ main() {
await app.errorHandler(e, req, res);
await http.sendResponse(rq, req, res);
expect(
ContentType.parse(rs.headers.value(HttpHeaders.CONTENT_TYPE)).mimeType,
ContentType.HTML.mimeType,
ContentType.parse(rs.headers.value('content-type')).mimeType,
'text/html',
);
expect(rs.statusCode, e.statusCode);
var body = await rs.transform(utf8.decoder).join();
@ -169,35 +169,35 @@ main() {
test('can send json', () async {
var rq = new MockHttpRequest('GET', new Uri(path: 'wtf'))
..headers.set(HttpHeaders.ACCEPT, ContentType.JSON.toString());
..headers.set('accept', 'application/json');
rq.close();
http.handleRequest(rq);
await rq.response.toList();
expect(rq.response.statusCode, HttpStatus.FORBIDDEN);
expect(rq.response.statusCode, 403);
expect(
rq.response.headers.contentType.mimeType, ContentType.JSON.mimeType);
rq.response.headers.contentType.mimeType, 'application/json');
});
test('can throw in finalizer', () async {
var rq = new MockHttpRequest('GET', new Uri(path: 'wtf'))
..headers.set(HttpHeaders.ACCEPT, ContentType.JSON.toString());
..headers.set('accept', 'application/json');
rq.close();
http.handleRequest(rq);
await rq.response.toList();
expect(rq.response.statusCode, HttpStatus.FORBIDDEN);
expect(rq.response.statusCode, 403);
expect(
rq.response.headers.contentType.mimeType, ContentType.JSON.mimeType);
rq.response.headers.contentType.mimeType, 'application/json');
});
test('can send html', () async {
var rq = new MockHttpRequest('GET', new Uri(path: 'wtf2'));
rq.headers.set(HttpHeaders.ACCEPT, ContentType.HTML.toString());
rq.headers.set('accept', 'text/html');
rq.close();
http.handleRequest(rq);
await rq.response.toList();
expect(rq.response.statusCode, HttpStatus.FORBIDDEN);
expect(rq.response.statusCode, 403);
expect(
rq.response.headers.contentType?.mimeType, ContentType.HTML.mimeType);
rq.response.headers.contentType?.mimeType, 'text/html');
});
});
}

View file

@ -52,7 +52,7 @@ main() {
test('can create data', () async {
String postData = god.serialize({'text': 'Hello, world!'});
var response =
await client.post("$url/todos", headers: headers, body: postData);
await client.post("$url/todos", headers: headers.cast<String, String>(), body: postData);
expect(response.statusCode, 201);
var json = god.deserialize(response.body);
print(json);
@ -61,7 +61,7 @@ main() {
test('can fetch data', () async {
String postData = god.serialize({'text': 'Hello, world!'});
await client.post("$url/todos", headers: headers, body: postData);
await client.post("$url/todos", headers: headers.cast<String, String>(), body: postData);
var response = await client.get("$url/todos/0");
expect(response.statusCode, 200);
var json = god.deserialize(response.body);
@ -71,10 +71,10 @@ main() {
test('can modify data', () async {
String postData = god.serialize({'text': 'Hello, world!'});
await client.post("$url/todos", headers: headers, body: postData);
await client.post("$url/todos", headers: headers.cast<String, String>(), body: postData);
postData = god.serialize({'text': 'modified'});
var response =
await client.patch("$url/todos/0", headers: headers, body: postData);
await client.patch("$url/todos/0", headers: headers.cast<String, String>(), body: postData);
expect(response.statusCode, 200);
var json = god.deserialize(response.body);
print(json);
@ -83,10 +83,10 @@ main() {
test('can overwrite data', () async {
String postData = god.serialize({'text': 'Hello, world!'});
await client.post("$url/todos", headers: headers, body: postData);
await client.post("$url/todos", headers: headers.cast<String, String>(), body: postData);
postData = god.serialize({'over': 'write'});
var response =
await client.post("$url/todos/0", headers: headers, body: postData);
await client.post("$url/todos/0", headers: headers.cast<String, String>(), body: postData);
expect(response.statusCode, 200);
var json = god.deserialize(response.body);
print(json);
@ -97,7 +97,7 @@ main() {
test('can delete data', () async {
String postData = god.serialize({'text': 'Hello, world!'});
var created = await client
.post("$url/todos", headers: headers, body: postData)
.post("$url/todos", headers: headers.cast<String, String>(), body: postData)
.then((r) => json.decode(r.body));
var response = await client.delete("$url/todos/${created['id']}");
expect(response.statusCode, 200);

View file

@ -29,7 +29,7 @@ main() {
},
);
app.get('/hello', (res) {
app.get('/hello', (ResponseContext res) {
new Stream<List<int>>.fromIterable(['Hello, world!'.codeUnits]).pipe(res);
});
@ -48,7 +48,7 @@ main() {
await res.close();
});
app.get('/overwrite', (res) async {
app.get('/overwrite', (ResponseContext res) async {
res.statusCode = 32;
await new Stream<List<int>>.fromIterable(['Hello, world!'.codeUnits])
.pipe(res);

View file

@ -24,7 +24,7 @@ main() {
new Todo(text: 'a', completed: false, createdAt: now, updatedAt: now);
var m = svc.serialize(t);
print(m);
expect(m, {
expect(m..remove('_identityHashCode'), {
'id': null,
'createdAt': now.toIso8601String(),
'updatedAt': now.toIso8601String(),
@ -39,7 +39,7 @@ main() {
'createdAt': now.toIso8601String(),
'updatedAt': now.toIso8601String()
});
expect(m, new isInstanceOf<Todo>());
expect(m, const TypeMatcher<Todo>());
var t = m as Todo;
expect(t.createdAt.millisecondsSinceEpoch, now.millisecondsSinceEpoch);
});
@ -50,7 +50,7 @@ main() {
'created_at': now.toIso8601String(),
'updated_at': now.toIso8601String()
});
expect(m, new isInstanceOf<Todo>());
expect(m, const TypeMatcher<Todo>());
var t = m as Todo;
expect(t.createdAt.millisecondsSinceEpoch, now.millisecondsSinceEpoch);
});