Bump to 2.1.2

This commit is contained in:
Tobe O 2019-05-02 19:19:30 -04:00
parent 67303b82aa
commit 49ea99ed6c
8 changed files with 55 additions and 46 deletions

View file

@ -1,3 +1,6 @@
# 2.1.2
* Apply lints.
# 2.1.1
* Update for framework@2.0.0-alpha.15

View file

@ -1,3 +1,8 @@
include: package:pedantic/analysis_options.yaml
analyzer:
strong-mode:
implicit-casts: false
linter:
rules:
- unnecessary_const
- unnecessary_new

View file

@ -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);

View file

@ -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<bool>.value(true);
return Future<bool>.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<BytesBuilder>(new BytesBuilder(), (bb, buf) => bb..add(buf))
.fold<BytesBuilder>(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<String, String>.from(rs.headers)
var proxiedHeaders = Map<String, String>.from(rs.headers)
..remove(
HttpHeaders.contentEncodingHeader) // drop, http.Client has decoded
..remove(

View file

@ -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 <thosakwe@gmail.com>
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

View file

@ -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);

View file

@ -6,7 +6,7 @@ import 'package:angel_framework/http.dart';
import 'package:logging/logging.dart';
Future<HttpServer> 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<HttpServer> startTestServer() {
return body;
});
app.logger = new Logger('testApp');
app.logger = Logger('testApp');
var server = AngelHttp(app);
app.dumpTree();

View file

@ -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);