This commit is contained in:
Tobe O 2019-08-09 10:53:38 -04:00
parent 67c11b5384
commit 6568dc2305
4 changed files with 24 additions and 21 deletions

View file

@ -5,7 +5,6 @@ import 'package:angel_framework/angel_framework.dart';
import 'package:angel_framework/http.dart'; import 'package:angel_framework/http.dart';
import 'package:angel_wings/angel_wings.dart'; import 'package:angel_wings/angel_wings.dart';
import 'package:io/ansi.dart'; import 'package:io/ansi.dart';
import 'package:pedantic/pedantic.dart';
import 'package:tuple/tuple.dart'; import 'package:tuple/tuple.dart';
Future<Process> _runWrk( Future<Process> _runWrk(
@ -89,10 +88,11 @@ void _angelIsolate(Tuple2<AngelBenchmark, String> args) {
var app = Angel(); var app = Angel();
Driver driver; Driver driver;
if (args.item2 == 'angel_http') if (args.item2 == 'angel_http') {
driver = AngelHttp.custom(app, startShared); driver = AngelHttp.custom(app, startShared);
else if (args.item2 == 'angel_wings') } else if (args.item2 == 'angel_wings') {
driver = AngelWings.custom(app, startSharedWings); driver = AngelWings.custom(app, startSharedWings);
}
await app.configure(args.item1.setupAngel); await app.configure(args.item1.setupAngel);
await driver.startServer(InternetAddress.loopbackIPv4, testPort); await driver.startServer(InternetAddress.loopbackIPv4, testPort);

View file

@ -22,14 +22,14 @@ void prettyLog(LogRecord record) {
/// Chooses a color based on the logger [level]. /// Chooses a color based on the logger [level].
AnsiCode chooseLogColor(Level level) { AnsiCode chooseLogColor(Level level) {
if (level == Level.SHOUT) if (level == Level.SHOUT) {
return backgroundRed; return backgroundRed;
else if (level == Level.SEVERE) } else if (level == Level.SEVERE) {
return red; return red;
else if (level == Level.WARNING) } else if (level == Level.WARNING) {
return yellow; return yellow;
else if (level == Level.INFO) } else if (level == Level.INFO) {
return cyan; return cyan;
else if (level == Level.FINER || level == Level.FINEST) return lightGray; } else if (level == Level.FINER || level == Level.FINEST) return lightGray;
return resetAll; return resetAll;
} }

View file

@ -9,7 +9,7 @@ import 'wings_socket.dart';
enum _ParseState { method, url, headerField, headerValue, body } enum _ParseState { method, url, headerField, headerValue, body }
final RegExp _straySlashes = new RegExp(r'(^/+)|(/+$)'); final RegExp _straySlashes = RegExp(r'(^/+)|(/+$)');
class WingsRequestContext extends RequestContext<WingsClientSocket> { class WingsRequestContext extends RequestContext<WingsClientSocket> {
final WingsClientSocket rawRequest; final WingsClientSocket rawRequest;
@ -91,7 +91,7 @@ class WingsRequestContext extends RequestContext<WingsClientSocket> {
case PURGE: case PURGE:
return 'PURGE'; return 'PURGE';
default: default:
throw new ArgumentError('Unknown method $method.'); throw ArgumentError('Unknown method $method.');
} }
} }

View file

@ -57,8 +57,9 @@ class WingsResponseContext extends ResponseContext<int> {
} }
} }
if (contentType != null) if (contentType != null) {
outHeaders['content-type'] = contentType.toString(); outHeaders['content-type'] = contentType.toString();
}
if (encoders.isNotEmpty && correspondingRequest != null) { if (encoders.isNotEmpty && correspondingRequest != null) {
if (_allowedEncodings != null) { if (_allowedEncodings != null) {
@ -66,9 +67,9 @@ class WingsResponseContext extends ResponseContext<int> {
Converter<List<int>, List<int>> encoder; Converter<List<int>, List<int>> encoder;
String key = encodingName; String key = encodingName;
if (encoders.containsKey(encodingName)) if (encoders.containsKey(encodingName)) {
encoder = encoders[encodingName]; encoder = encoders[encodingName];
else if (encodingName == '*') { } else if (encodingName == '*') {
encoder = encoders[key = encoders.keys.first]; encoder = encoders[key = encoders.keys.first];
} }
@ -116,9 +117,9 @@ class WingsResponseContext extends ResponseContext<int> {
Converter<List<int>, List<int>> encoder; Converter<List<int>, List<int>> encoder;
String key = encodingName; String key = encodingName;
if (encoders.containsKey(encodingName)) if (encoders.containsKey(encodingName)) {
encoder = encoders[encodingName]; encoder = encoders[encodingName];
else if (encodingName == '*') { } else if (encodingName == '*') {
encoder = encoders[key = encoders.keys.first]; encoder = encoders[key = encoders.keys.first];
} }
@ -131,17 +132,18 @@ class WingsResponseContext extends ResponseContext<int> {
} }
return output.forEach((buf) { return output.forEach((buf) {
if (!_isClosed) if (!_isClosed) {
writeToNativeSocket( writeToNativeSocket(
rawResponse, buf is Uint8List ? buf : Uint8List.fromList(buf)); rawResponse, buf is Uint8List ? buf : Uint8List.fromList(buf));
}
}); });
} }
@override @override
void add(List<int> data) { void add(List<int> data) {
if (_isClosed && isBuffered) if (_isClosed && isBuffered) {
throw ResponseContext.closed(); throw ResponseContext.closed();
else if (!isBuffered) { } else if (!isBuffered) {
if (!_isClosed) { if (!_isClosed) {
_openStream(); _openStream();
@ -151,9 +153,9 @@ class WingsResponseContext extends ResponseContext<int> {
Converter<List<int>, List<int>> encoder; Converter<List<int>, List<int>> encoder;
String key = encodingName; String key = encodingName;
if (encoders.containsKey(encodingName)) if (encoders.containsKey(encodingName)) {
encoder = encoders[encodingName]; encoder = encoders[encodingName];
else if (encodingName == '*') { } else if (encodingName == '*') {
encoder = encoders[key = encoders.keys.first]; encoder = encoders[key = encoders.keys.first];
} }
@ -168,8 +170,9 @@ class WingsResponseContext extends ResponseContext<int> {
writeToNativeSocket( writeToNativeSocket(
rawResponse, data is Uint8List ? data : Uint8List.fromList(data)); rawResponse, data is Uint8List ? data : Uint8List.fromList(data));
} }
} else } else {
buffer.add(data); buffer.add(data);
}
} }
@override @override