Removed debug property

This commit is contained in:
Tobe O 2018-08-20 16:53:30 -04:00
parent bf9e297a92
commit 81745ebef5
10 changed files with 41 additions and 70 deletions

View file

@ -42,4 +42,7 @@ take routes in the form of `FutureOr myFunc(RequestContext, ResponseContext res)
* `@Expose.middleware` now takes `Iterable<RequestHandler>`, instead of just `List`.
* `createDynamicHandler` was renamed to `ioc`, and is now used to run IoC-aware handlers in a
type-safe manner.
* `RequestContext.params` is now a `Map<String, dynamic>`, rather than just a `Map`.
* `RequestContext.params` is now a `Map<String, dynamic>`, rather than just a `Map`.
* Removed `RequestContext.grab`.
* Removed `RequestContext.properties`.
* Removed the defunct `debug` property where it still existed.

View file

@ -1,12 +1,11 @@
part of angel_framework.http.request_context;
const List<Type> _primitiveTypes = [String, int, num, double, Null];
const List<Type> _primitiveTypes = [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 ioc(Function handler,
{Iterable<String> optional: const []}) {
RequestHandler ioc(Function handler, {Iterable<String> optional: const []}) {
var injection = preInject(handler);
injection.optional.addAll(optional ?? []);
return handleContained(handler, injection);
@ -29,11 +28,7 @@ resolveInjection(requirement, InjectionRequest injection, RequestContext req,
} else if (requirement is String) {
if (req.params.containsKey(requirement)) {
return req.params[requirement];
} else if (req._injections.containsKey(requirement))
return req._injections[requirement];
else if (req.properties.containsKey(requirement))
return req.properties[requirement];
else if ((propFromApp = req.app.findProperty(requirement)) != null)
} else if ((propFromApp = req.app.findProperty(requirement)) != null)
return propFromApp;
else if (injection.optional.contains(requirement))
return null;
@ -48,18 +43,13 @@ resolveInjection(requirement, InjectionRequest injection, RequestContext req,
String key = requirement.first;
Type type = requirement.last;
if (req.params.containsKey(key) ||
req._injections.containsKey(key) ||
req.properties.containsKey(key) ||
req.app.configuration.containsKey(key) ||
_primitiveTypes.contains(type)) {
return resolveInjection(key, injection, req, res, throwOnUnresolved);
} else
return resolveInjection(type, injection, req, res, throwOnUnresolved);
} else if (requirement is Type && requirement != dynamic) {
if (req._injections.containsKey(requirement))
return req._injections[requirement];
else
return req.app.container.make(requirement);
return req.app.container.make(requirement);
} else if (throwOnUnresolved) {
throw new ArgumentError(
'$requirement cannot be injected into a request handler.');

View file

@ -24,8 +24,6 @@ abstract class RequestContext<RawRequest> {
BodyParseResult _body;
Map _provisionalQuery;
final Map properties = {};
/// The underlying [RawRequest] provided by the driver.
RawRequest get rawRequest;
@ -87,31 +85,6 @@ abstract class RequestContext<RawRequest> {
/// Includes the leading `.`, if there is one.
String get extension => _extensionCache ??= p.extension(uri.path);
/// Grabs an object by key or type from [params], [_injections], or
/// [app].container. Use this to perform dependency injection
/// within a service hook.
T grab<T>(key) {
if (params.containsKey(key))
return params[key] as T;
else if (_injections.containsKey(key))
return _injections[key] as T;
else if (properties.containsKey(key))
return properties[key] as T;
else {
var prop = app?.findProperty(key);
if (prop != null)
return prop as T;
else if (key is Type) {
try {
return app.container.make(key) as T;
} catch (e) {
return null;
}
} else
return null;
}
}
/// Returns `true` if the client's `Accept` header indicates that the given [contentType] is considered a valid response.
///
/// You cannot provide a `null` [contentType].
@ -148,7 +121,8 @@ abstract class RequestContext<RawRequest> {
Future<Map> parseBody() => parse().then((b) => b.body);
/// Retrieves a list of all uploaded files if it has already been parsed, or lazy-parses it before returning the files.
Future<List<FileUploadInfo>> parseUploadedFiles() => parse().then((b) => b.files);
Future<List<FileUploadInfo>> parseUploadedFiles() =>
parse().then((b) => b.files);
/// Retrieves the original request buffer if it has already been parsed, or lazy-parses it before returning the buffer..
///
@ -185,8 +159,6 @@ abstract class RequestContext<RawRequest> {
_acceptsAllCache = null;
_acceptHeaderCache = null;
_provisionalQuery?.clear();
properties.clear();
_injections.clear();
serviceParams.clear();
params.clear();
return new Future.value();

View file

@ -9,7 +9,6 @@ import 'package:angel_route/angel_route.dart';
import 'package:file/file.dart';
import 'package:http_parser/http_parser.dart';
import 'package:mime/mime.dart';
import 'package:pool/pool.dart';
import '../http/http.dart';
import 'request_context.dart';
@ -18,7 +17,8 @@ import 'server.dart' show Angel;
final RegExp _straySlashes = new RegExp(r'(^/+)|(/+$)');
/// A convenience wrapper around an outgoing HTTP request.
abstract class ResponseContext<RawResponse> implements StreamSink<List<int>>, StringSink {
abstract class ResponseContext<RawResponse>
implements StreamSink<List<int>>, StringSink {
final Map properties = {};
final BytesBuilder _buffer = new _LockableBytesBuilder();
final Map<String, String> _headers = {'server': 'angel'};
@ -313,12 +313,9 @@ abstract class ResponseContext<RawResponse> implements StreamSink<List<int>>, St
/// Releases critical resources from the [correspondingRequest].
void releaseCorrespondingRequest() {
if (correspondingRequest?.injections?.containsKey(Stopwatch) == true) {
(correspondingRequest.injections[Stopwatch] as Stopwatch).stop();
}
if (correspondingRequest?.injections?.containsKey(PoolResource) == true) {
(correspondingRequest.injections[PoolResource] as PoolResource).release();
if (!correspondingRequest.app.isProduction &&
correspondingRequest.app.logger != null) {
correspondingRequest.container.make<Stopwatch>().stop();
}
}

View file

@ -34,7 +34,8 @@ class Angel extends Routable {
(String view, [Map data]) => 'No view engine has been configured yet.';
final List<Angel> _children = [];
final Map<String, Tuple3<List, Map, ParseResult<Map<String, dynamic>>>>
final Map<String,
Tuple3<List, Map<String, dynamic>, ParseResult<Map<String, dynamic>>>>
handlerCache = new HashMap();
Router _flattened;

View file

@ -8,7 +8,6 @@ import 'package:merge_map/merge_map.dart';
import '../util.dart';
import 'hooked_service.dart' show HookedService;
import 'metadata.dart';
import 'request_context.dart';
import 'response_context.dart';
import 'routable.dart';
import 'server.dart';

View file

@ -8,14 +8,16 @@ import 'dart:io'
HttpServer,
Platform,
SecurityContext;
import 'package:angel_http_exception/angel_http_exception.dart';
import 'package:angel_route/angel_route.dart';
import 'package:combinator/combinator.dart';
import 'package:stack_trace/stack_trace.dart';
import 'package:tuple/tuple.dart';
import '../core/core.dart';
import 'http_request_context.dart';
import 'http_response_context.dart';
import '../core/core.dart';
final RegExp _straySlashes = new RegExp(r'(^/+)|(/+$)');
@ -60,7 +62,7 @@ class AngelHttp {
/// the server.
factory AngelHttp.secure(
Angel app, String certificateChainPath, String serverKeyPath,
{bool debug: false, String password, bool useZone: true}) {
{ String password, bool useZone: true}) {
var certificateChain =
Platform.script.resolve(certificateChainPath).toFilePath();
var serverKey = Platform.script.resolve(serverKeyPath).toFilePath();
@ -107,14 +109,16 @@ class AngelHttp {
var path = req.path;
if (path == '/') path = '';
Tuple3<List, Map, ParseResult<Map<String, dynamic>>> resolveTuple() {
Tuple3<List, Map<String, dynamic>, ParseResult<Map<String, dynamic>>>
resolveTuple() {
Router r = app.optimizedRouter;
var resolved =
r.resolveAbsolute(path, method: req.method, strip: false);
return new Tuple3(
new MiddlewarePipeline(resolved).handlers,
resolved.fold<Map>({}, (out, r) => out..addAll(r.allParams)),
resolved.fold<Map<String, dynamic>>(
<String, dynamic>{}, (out, r) => out..addAll(r.allParams)),
resolved.isEmpty ? null : resolved.first.parseResult,
);
}
@ -125,10 +129,15 @@ class AngelHttp {
: resolveTuple();
req.params.addAll(tuple.item2);
req.inject(ParseResult, tuple.item3);
if (!app.isProduction && app.logger != null)
req.inject(Stopwatch, new Stopwatch()..start());
req.container.registerSingleton<ParseResult<Map<String, dynamic>>>(
tuple.item3);
req.container.registerSingleton<ParseResult>(tuple.item3);
if (!app.isProduction && app.logger != null) {
req.container
.registerSingleton<Stopwatch>(new Stopwatch()..start());
}
var pipeline = tuple.item1;
@ -215,8 +224,9 @@ class AngelHttp {
);
var zone = Zone.current.fork(specification: zoneSpec);
req.inject(Zone, zone);
req.inject(ZoneSpecification, zoneSpec);
req.container.registerSingleton<Zone>(zone);
req.container.registerSingleton<ZoneSpecification>(zoneSpec);
return zone.run(handle).whenComplete(() {
res.dispose();
});
@ -321,7 +331,7 @@ class AngelHttp {
return request.response.close().then((_) {
if (!app.isProduction && app.logger != null) {
var sw = req.grab<Stopwatch>(Stopwatch);
var sw = req.container.make<Stopwatch>();
if (sw.isRunning) {
sw?.stop();

View file

@ -15,8 +15,6 @@ class Controller {
/// The [Angel] application powering this controller.
Angel get app => _app;
final bool debug;
/// If `true` (default), this class will inject itself as a singleton into the [app]'s container when bootstrapped.
final bool injectSingleton;
@ -26,7 +24,7 @@ class Controller {
/// A mapping of route paths to routes, produced from the [Expose] annotations on this class.
Map<String, Route> routeMappings = {};
Controller({this.debug: false, this.injectSingleton: true});
Controller({this.injectSingleton: true});
@mustCallSuper
Future configureServer(Angel app) {

View file

@ -12,7 +12,7 @@ main() {
setUp(() {
app = new Angel(reflector: MirrorsReflector())
..inject('global', 305); // Pitbull!
..configuration['global'] = 305; // Pitbull!
http = new AngelHttp(app);
app.get('/string/:string', ioc((String string) => string));

View file

@ -89,7 +89,8 @@ main() {
});
test('global injection added to injection map', () async {
var app = new Angel(reflector: MirrorsReflector())..inject('a', 'b');
var app = new Angel(reflector: MirrorsReflector())
..configuration['a'] = 'b';
var http = new AngelHttp(app);
app.get('/', ioc((String a) => a));
var rq = new MockHttpRequest('GET', Uri.parse('/'))..close();