From 49ea99ed6c34f32d6c6e84dbee7e7756d8b3a9b3 Mon Sep 17 00:00:00 2001 From: Tobe O Date: Thu, 2 May 2019 19:19:30 -0400 Subject: [PATCH] Bump to 2.1.2 --- CHANGELOG.md | 3 +++ analysis_options.yaml | 7 ++++++- example/main.dart | 14 +++++++------- lib/src/proxy_layer.dart | 37 ++++++++++++++++++------------------- pubspec.yaml | 3 ++- test/basic_test.dart | 14 +++++++------- test/common.dart | 4 ++-- test/pub_serve_test.dart | 19 ++++++++++--------- 8 files changed, 55 insertions(+), 46 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 1babb6a6..05759311 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,6 @@ +# 2.1.2 +* Apply lints. + # 2.1.1 * Update for framework@2.0.0-alpha.15 diff --git a/analysis_options.yaml b/analysis_options.yaml index eae1e42a..085be64d 100644 --- a/analysis_options.yaml +++ b/analysis_options.yaml @@ -1,3 +1,8 @@ +include: package:pedantic/analysis_options.yaml analyzer: strong-mode: - implicit-casts: false \ No newline at end of file + implicit-casts: false +linter: + rules: + - unnecessary_const + - unnecessary_new \ No newline at end of file diff --git a/example/main.dart b/example/main.dart index 7aa38279..2d850aa3 100644 --- a/example/main.dart +++ b/example/main.dart @@ -5,15 +5,15 @@ import 'package:angel_proxy/angel_proxy.dart'; import 'package:http/io_client.dart' as http; import 'package:logging/logging.dart'; -final Duration timeout = new Duration(seconds: 5); +final Duration timeout = Duration(seconds: 5); main() async { - var app = new Angel(); - var client = new http.IOClient(); + var app = Angel(); + var client = http.IOClient(); // Forward any /api requests to pub. // By default, if the host throws a 404, the request will fall through to the next handler. - var pubProxy = new Proxy( + var pubProxy = Proxy( client, Uri.parse('https://pub.dartlang.org'), publicPath: '/pub', @@ -24,7 +24,7 @@ main() async { // Surprise! We can also proxy WebSockets. // // Play around with this at http://www.websocket.org/echo.html. - var echoProxy = new Proxy( + var echoProxy = Proxy( client, Uri.parse('http://echo.websocket.org'), publicPath: '/echo', @@ -39,7 +39,7 @@ main() async { }); // Anything else should fall through to dartlang.org. - var dartlangProxy = new Proxy( + var dartlangProxy = Proxy( client, Uri.parse('https://dartlang.org'), timeout: timeout, @@ -51,7 +51,7 @@ main() async { app.fallback( (req, res) => res.write('Couldn\'t connect to Pub or dartlang.')); - app.logger = new Logger('angel') + app.logger = Logger('angel') ..onRecord.listen( (rec) { print(rec); diff --git a/lib/src/proxy_layer.dart b/lib/src/proxy_layer.dart index 5b4b7090..ca672c6d 100644 --- a/lib/src/proxy_layer.dart +++ b/lib/src/proxy_layer.dart @@ -7,7 +7,7 @@ import 'package:http_parser/http_parser.dart'; import 'package:http/http.dart' as http; import 'package:path/path.dart' as p; -final RegExp _straySlashes = new RegExp(r'(^/+)|(/+$)'); +final RegExp _straySlashes = RegExp(r'(^/+)|(/+$)'); final MediaType _fallbackMediaType = MediaType('application', 'octet-stream'); class Proxy { @@ -27,18 +27,18 @@ class Proxy { Proxy( this.httpClient, this.baseUrl, { - this.publicPath: '/', - this.recoverFromDead: true, - this.recoverFrom404: true, + this.publicPath = '/', + this.recoverFromDead = true, + this.recoverFrom404 = true, this.timeout, }) { if (!baseUrl.hasScheme || !baseUrl.hasAuthority) - throw new ArgumentError( + throw ArgumentError( 'Invalid `baseUrl`. URI must have both a scheme and authority.'); if (this.recoverFromDead == null) - throw new ArgumentError.notNull("recoverFromDead"); + throw ArgumentError.notNull("recoverFromDead"); if (this.recoverFrom404 == null) - throw new ArgumentError.notNull("recoverFrom404"); + throw ArgumentError.notNull("recoverFrom404"); _prefix = publicPath?.replaceAll(_straySlashes, '') ?? ''; } @@ -51,7 +51,7 @@ class Proxy { if (_prefix.isNotEmpty) { if (!p.isWithin(_prefix, path) && !p.equals(_prefix, path)) { - return new Future.value(true); + return Future.value(true); } path = p.relative(path, from: _prefix); @@ -77,11 +77,11 @@ class Proxy { var local = await WebSocketTransformer.upgrade(req.rawRequest); var remote = await WebSocket.connect(uri.toString()); - local.pipe(remote); - remote.pipe(local); + scheduleMicrotask(() => local.pipe(remote)); + scheduleMicrotask(() => remote.pipe(local)); return false; } catch (e, st) { - throw new AngelHttpException(e, + throw AngelHttpException(e, message: 'Could not connect WebSocket', stackTrace: st); } } @@ -107,14 +107,14 @@ class Proxy { if (!req.hasParsedBody) { body = await req.body - .fold(new BytesBuilder(), (bb, buf) => bb..add(buf)) + .fold(BytesBuilder(), (bb, buf) => bb..add(buf)) .then((bb) => bb.takeBytes()); } - var rq = new http.Request(req.method, uri); + var rq = http.Request(req.method, uri); rq.headers.addAll(headers); rq.headers['host'] = rq.url.host; - rq.encoding = new Utf8Codec(allowMalformed: true); + rq.encoding = Utf8Codec(allowMalformed: true); if (body != null) rq.bodyBytes = body; @@ -127,7 +127,7 @@ class Proxy { } on TimeoutException catch (e, st) { if (recoverFromDead) return true; - throw new AngelHttpException( + throw AngelHttpException( e, stackTrace: st, statusCode: 504, @@ -145,12 +145,11 @@ class Proxy { MediaType mediaType; if (rs.headers.containsKey(HttpHeaders.contentTypeHeader)) { try { - mediaType = - new MediaType.parse(rs.headers[HttpHeaders.contentTypeHeader]); + mediaType = MediaType.parse(rs.headers[HttpHeaders.contentTypeHeader]); } on FormatException catch (e, st) { if (recoverFromDead) return true; - throw new AngelHttpException( + throw AngelHttpException( e, stackTrace: st, statusCode: 504, @@ -168,7 +167,7 @@ class Proxy { rs.headers[HttpHeaders.contentEncodingHeader]?.isNotEmpty == true || rs.headers[HttpHeaders.transferEncodingHeader]?.isNotEmpty == true; - var proxiedHeaders = new Map.from(rs.headers) + var proxiedHeaders = Map.from(rs.headers) ..remove( HttpHeaders.contentEncodingHeader) // drop, http.Client has decoded ..remove( diff --git a/pubspec.yaml b/pubspec.yaml index 57b27905..f439dd04 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -1,6 +1,6 @@ name: angel_proxy description: Angel middleware to forward requests to another server (i.e. pub serve). -version: 2.1.1 +version: 2.1.2 author: Tobe O homepage: https://github.com/angel-dart/proxy environment: @@ -14,5 +14,6 @@ dev_dependencies: angel_test: ^2.0.0-alpha logging: mock_request: + pedantic: ^1.0.0 test: ^1.0.0 diff --git a/test/basic_test.dart b/test/basic_test.dart index 46973e63..cb93c3aa 100644 --- a/test/basic_test.dart +++ b/test/basic_test.dart @@ -10,27 +10,27 @@ import 'common.dart'; main() { Angel app; - var client = new http.IOClient(); + var client = http.IOClient(); HttpServer server, testServer; String url; setUp(() async { - app = new Angel(); + app = Angel(); var appHttp = AngelHttp(app); - var httpClient = new http.IOClient(); + var httpClient = http.IOClient(); testServer = await startTestServer(); - var proxy1 = new Proxy( + var proxy1 = Proxy( httpClient, - new Uri( + Uri( scheme: 'http', host: testServer.address.address, port: testServer.port), publicPath: '/proxy', ); - var proxy2 = new Proxy(httpClient, proxy1.baseUrl.replace(path: '/foo')); + var proxy2 = Proxy(httpClient, proxy1.baseUrl.replace(path: '/foo')); print('Proxy 1 on: ${proxy1.baseUrl}'); print('Proxy 2 on: ${proxy2.baseUrl}'); @@ -46,7 +46,7 @@ main() { httpClient.close(); }); - app.logger = new Logger('angel'); + app.logger = Logger('angel'); Logger.root.onRecord.listen((rec) { print(rec); diff --git a/test/common.dart b/test/common.dart index 86f0df50..c437361c 100644 --- a/test/common.dart +++ b/test/common.dart @@ -6,7 +6,7 @@ import 'package:angel_framework/http.dart'; import 'package:logging/logging.dart'; Future startTestServer() { - final app = new Angel(); + final app = Angel(); app.get('/hello', (req, res) => res.write('world')); app.get('/foo/bar', (req, res) => res.write('baz')); @@ -16,7 +16,7 @@ Future startTestServer() { return body; }); - app.logger = new Logger('testApp'); + app.logger = Logger('testApp'); var server = AngelHttp(app); app.dumpTree(); diff --git a/test/pub_serve_test.dart b/test/pub_serve_test.dart index 72f633cc..b0a23940 100644 --- a/test/pub_serve_test.dart +++ b/test/pub_serve_test.dart @@ -15,7 +15,7 @@ main() { Proxy layer; setUp(() async { - testApp = new Angel(); + testApp = Angel(); testApp.get('/foo', (req, res) async { res.useBuffer(); res.write('pub serve'); @@ -23,25 +23,25 @@ main() { testApp.get('/empty', (req, res) => res.close()); testApp.responseFinalizers.add((req, res) async { - print('OUTGOING: ' + new String.fromCharCodes(res.buffer.toBytes())); + print('OUTGOING: ' + String.fromCharCodes(res.buffer.toBytes())); }); testApp.encoders.addAll({'gzip': gzip.encoder}); var server = await AngelHttp(testApp).startServer(); - app = new Angel(); + app = Angel(); app.fallback((req, res) { res.useBuffer(); return true; }); app.get('/bar', (req, res) => res.write('normal')); - var httpClient = new http.IOClient(); + var httpClient = http.IOClient(); - layer = new Proxy( + layer = Proxy( httpClient, - new Uri(scheme: 'http', host: server.address.address, port: server.port), + Uri(scheme: 'http', host: server.address.address, port: server.port), publicPath: '/proxy', ); @@ -49,7 +49,7 @@ main() { app.responseFinalizers.add((req, res) async { print('Normal. Buf: ' + - new String.fromCharCodes(res.buffer.toBytes()) + + String.fromCharCodes(res.buffer.toBytes()) + ', headers: ${res.headers}'); }); @@ -57,7 +57,7 @@ main() { client = await connectTo(app); - app.logger = testApp.logger = new Logger('proxy') + app.logger = testApp.logger = Logger('proxy') ..onRecord.listen((rec) { print(rec); if (rec.error != null) print(rec.error); @@ -74,7 +74,8 @@ main() { }); test('proxied', () async { - var rq = new MockHttpRequest('GET', Uri.parse('/proxy/foo'))..close(); + var rq = MockHttpRequest('GET', Uri.parse('/proxy/foo')); + await rq.close(); var rqc = await HttpRequestContext.from(rq, app, '/proxy/foo'); var rsc = HttpResponseContext(rq.response, app); await app.executeHandler(layer.handleRequest, rqc, rsc);