apply pkg:pedantic lints
This commit is contained in:
parent
3a9bd27d6d
commit
1c07aa5243
13 changed files with 78 additions and 59 deletions
|
@ -2,8 +2,6 @@ include: package:pedantic/analysis_options.yaml
|
||||||
analyzer:
|
analyzer:
|
||||||
strong-mode:
|
strong-mode:
|
||||||
implicit-casts: false
|
implicit-casts: false
|
||||||
errors:
|
|
||||||
unawaited_futures: ignore
|
|
||||||
linter:
|
linter:
|
||||||
rules:
|
rules:
|
||||||
- avoid_slow_async_io
|
- avoid_slow_async_io
|
||||||
|
|
|
@ -4,6 +4,7 @@ import 'dart:io';
|
||||||
import 'package:angel_framework/angel_framework.dart' hide Header;
|
import 'package:angel_framework/angel_framework.dart' hide Header;
|
||||||
import 'package:http2/transport.dart';
|
import 'package:http2/transport.dart';
|
||||||
import 'package:mock_request/mock_request.dart';
|
import 'package:mock_request/mock_request.dart';
|
||||||
|
import 'package:pedantic/pedantic.dart';
|
||||||
import 'http2_request_context.dart';
|
import 'http2_request_context.dart';
|
||||||
import 'http2_response_context.dart';
|
import 'http2_response_context.dart';
|
||||||
import 'package:uuid/uuid.dart';
|
import 'package:uuid/uuid.dart';
|
||||||
|
@ -148,7 +149,7 @@ class _FakeServerSocket extends Stream<Socket> implements ServerSocket {
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Future<ServerSocket> close() async {
|
Future<ServerSocket> close() async {
|
||||||
_ctrl.close();
|
unawaited(_ctrl.close());
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -202,9 +203,9 @@ class _AngelHttp2ServerSocket extends Stream<SecureSocket>
|
||||||
int get port => socket.port;
|
int get port => socket.port;
|
||||||
|
|
||||||
Future<SecureServerSocket> close() async {
|
Future<SecureServerSocket> close() async {
|
||||||
_sub?.cancel();
|
unawaited(_sub?.cancel());
|
||||||
_fake.close();
|
unawaited(_fake.close());
|
||||||
_ctrl.close();
|
unawaited(_ctrl.close());
|
||||||
return await socket.close();
|
return await socket.close();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -23,6 +23,7 @@ dependencies:
|
||||||
mime: ^0.9.3
|
mime: ^0.9.3
|
||||||
mock_request: ^1.0.0
|
mock_request: ^1.0.0
|
||||||
path: ^1.0.0
|
path: ^1.0.0
|
||||||
|
pedantic: ^1.0.0
|
||||||
quiver_hashcode: ^2.0.0
|
quiver_hashcode: ^2.0.0
|
||||||
stack_trace: ^1.0.0
|
stack_trace: ^1.0.0
|
||||||
tuple: ^1.0.0
|
tuple: ^1.0.0
|
||||||
|
@ -30,5 +31,4 @@ dependencies:
|
||||||
dev_dependencies:
|
dev_dependencies:
|
||||||
http: ^0.11.3
|
http: ^0.11.3
|
||||||
io: ^0.3.0
|
io: ^0.3.0
|
||||||
pedantic: ^1.0.0
|
|
||||||
test: ^1.0.0
|
test: ^1.0.0
|
||||||
|
|
|
@ -14,9 +14,8 @@ void main() {
|
||||||
app.get('/detach', (req, res) async {
|
app.get('/detach', (req, res) async {
|
||||||
if (res is HttpResponseContext) {
|
if (res is HttpResponseContext) {
|
||||||
var io = await res.detach();
|
var io = await res.detach();
|
||||||
io
|
io..write('Hey!');
|
||||||
..write('Hey!')
|
await io.close();
|
||||||
..close();
|
|
||||||
} else {
|
} else {
|
||||||
throw new StateError('This endpoint only supports HTTP/1.1.');
|
throw new StateError('This endpoint only supports HTTP/1.1.');
|
||||||
}
|
}
|
||||||
|
@ -26,7 +25,8 @@ void main() {
|
||||||
tearDown(() => http.close());
|
tearDown(() => http.close());
|
||||||
|
|
||||||
test('detach response', () async {
|
test('detach response', () async {
|
||||||
var rq = new MockHttpRequest('GET', Uri.parse('/detach'))..close();
|
var rq = new MockHttpRequest('GET', Uri.parse('/detach'));
|
||||||
|
await rq.close();
|
||||||
var rs = rq.response;
|
var rs = rq.response;
|
||||||
await http.handleRequest(rq);
|
await http.handleRequest(rq);
|
||||||
var body = await rs.transform(utf8.decoder).join();
|
var body = await rs.transform(utf8.decoder).join();
|
||||||
|
|
|
@ -62,7 +62,8 @@ main() {
|
||||||
return app.runContained((Todo t) => t.text, req, res, c);
|
return app.runContained((Todo t) => t.text, req, res, c);
|
||||||
});
|
});
|
||||||
|
|
||||||
var rq = new MockHttpRequest('GET', new Uri(path: '/'))..close();
|
var rq = new MockHttpRequest('GET', new Uri(path: '/'));
|
||||||
|
await rq.close();
|
||||||
var rs = rq.response;
|
var rs = rq.response;
|
||||||
await new AngelHttp(app).handleRequest(rq);
|
await new AngelHttp(app).handleRequest(rq);
|
||||||
var text = await rs.transform(utf8.decoder).join();
|
var text = await rs.transform(utf8.decoder).join();
|
||||||
|
|
|
@ -51,7 +51,8 @@ void encodingTests(Angel getApp()) {
|
||||||
});
|
});
|
||||||
|
|
||||||
test('sends plaintext if no accept-encoding', () async {
|
test('sends plaintext if no accept-encoding', () async {
|
||||||
var rq = new MockHttpRequest('GET', Uri.parse('/hello'))..close();
|
var rq = new MockHttpRequest('GET', Uri.parse('/hello'));
|
||||||
|
await rq.close();
|
||||||
var rs = rq.response;
|
var rs = rq.response;
|
||||||
await http.handleRequest(rq);
|
await http.handleRequest(rq);
|
||||||
|
|
||||||
|
@ -61,8 +62,8 @@ void encodingTests(Angel getApp()) {
|
||||||
|
|
||||||
test('encodes if wildcard', () async {
|
test('encodes if wildcard', () async {
|
||||||
var rq = new MockHttpRequest('GET', Uri.parse('/hello'))
|
var rq = new MockHttpRequest('GET', Uri.parse('/hello'))
|
||||||
..headers.set('accept-encoding', '*')
|
..headers.set('accept-encoding', '*');
|
||||||
..close();
|
await rq.close();
|
||||||
var rs = rq.response;
|
var rs = rq.response;
|
||||||
await http.handleRequest(rq);
|
await http.handleRequest(rq);
|
||||||
|
|
||||||
|
@ -74,8 +75,8 @@ void encodingTests(Angel getApp()) {
|
||||||
|
|
||||||
test('encodes if wildcard + multiple', () async {
|
test('encodes if wildcard + multiple', () async {
|
||||||
var rq = new MockHttpRequest('GET', Uri.parse('/hello'))
|
var rq = new MockHttpRequest('GET', Uri.parse('/hello'))
|
||||||
..headers.set('accept-encoding', ['foo', 'bar', '*'])
|
..headers.set('accept-encoding', ['foo', 'bar', '*']);
|
||||||
..close();
|
await rq.close();
|
||||||
var rs = rq.response;
|
var rs = rq.response;
|
||||||
await http.handleRequest(rq);
|
await http.handleRequest(rq);
|
||||||
|
|
||||||
|
|
|
@ -76,13 +76,11 @@ void main() {
|
||||||
res.write('ok');
|
res.write('ok');
|
||||||
|
|
||||||
if (res is Http2ResponseContext && res.canPush) {
|
if (res is Http2ResponseContext && res.canPush) {
|
||||||
res.push('a')
|
var a = res.push('a')..write('a');
|
||||||
..write('a')
|
await a.close();
|
||||||
..close();
|
|
||||||
|
|
||||||
res.push('b')
|
var b = res.push('b')..write('b');
|
||||||
..write('b')
|
await b.close();
|
||||||
..close();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
await res.close();
|
await res.close();
|
||||||
|
|
|
@ -3,6 +3,7 @@ import 'dart:convert';
|
||||||
import 'dart:io';
|
import 'dart:io';
|
||||||
import 'package:http/http.dart';
|
import 'package:http/http.dart';
|
||||||
import 'package:http2/transport.dart';
|
import 'package:http2/transport.dart';
|
||||||
|
import 'package:pedantic/pedantic.dart';
|
||||||
|
|
||||||
/// Simple HTTP/2 client
|
/// Simple HTTP/2 client
|
||||||
class Http2Client extends BaseClient {
|
class Http2Client extends BaseClient {
|
||||||
|
@ -46,7 +47,7 @@ class Http2Client extends BaseClient {
|
||||||
if (body.isNotEmpty) {
|
if (body.isNotEmpty) {
|
||||||
stream.sendData(body, endStream: true);
|
stream.sendData(body, endStream: true);
|
||||||
} else {
|
} else {
|
||||||
stream.outgoingMessages.close();
|
unawaited(stream.outgoingMessages.close());
|
||||||
}
|
}
|
||||||
|
|
||||||
return stream;
|
return stream;
|
||||||
|
|
|
@ -5,6 +5,7 @@ import 'package:angel_container/mirrors.dart';
|
||||||
import 'package:angel_framework/angel_framework.dart';
|
import 'package:angel_framework/angel_framework.dart';
|
||||||
import 'package:angel_framework/http.dart';
|
import 'package:angel_framework/http.dart';
|
||||||
import 'package:mock_request/mock_request.dart';
|
import 'package:mock_request/mock_request.dart';
|
||||||
|
import 'package:pedantic/pedantic.dart';
|
||||||
import 'package:test/test.dart';
|
import 'package:test/test.dart';
|
||||||
|
|
||||||
Future<String> readResponse(MockHttpResponse rs) {
|
Future<String> readResponse(MockHttpResponse rs) {
|
||||||
|
@ -68,19 +69,20 @@ parameterMetaTests() {
|
||||||
|
|
||||||
test('injects header or throws', () async {
|
test('injects header or throws', () async {
|
||||||
// Invalid request
|
// Invalid request
|
||||||
var rq = new MockHttpRequest('GET', Uri.parse('/header'))..close();
|
var rq = new MockHttpRequest('GET', Uri.parse('/header'));
|
||||||
|
unawaited(rq.close());
|
||||||
var rs = rq.response;
|
var rs = rq.response;
|
||||||
http.handleRequest(rq);
|
unawaited(http.handleRequest(rq));
|
||||||
|
|
||||||
await printResponse(rs);
|
await printResponse(rs);
|
||||||
expect(rs.statusCode, 400);
|
expect(rs.statusCode, 400);
|
||||||
|
|
||||||
// Valid request
|
// Valid request
|
||||||
rq = new MockHttpRequest('GET', Uri.parse('/header'))
|
rq = new MockHttpRequest('GET', Uri.parse('/header'))
|
||||||
..headers.add('x-foo', 'bar')
|
..headers.add('x-foo', 'bar');
|
||||||
..close();
|
unawaited(rq.close());
|
||||||
rs = rq.response;
|
rs = rq.response;
|
||||||
await http.handleRequest(rq);
|
await unawaited(http.handleRequest(rq));
|
||||||
|
|
||||||
var body = await readResponse(rs);
|
var body = await readResponse(rs);
|
||||||
print('Body: $body');
|
print('Body: $body');
|
||||||
|
@ -90,21 +92,22 @@ parameterMetaTests() {
|
||||||
|
|
||||||
test('injects session or throws', () async {
|
test('injects session or throws', () async {
|
||||||
// Invalid request
|
// Invalid request
|
||||||
var rq = new MockHttpRequest('GET', Uri.parse('/session'))..close();
|
var rq = new MockHttpRequest('GET', Uri.parse('/session'));
|
||||||
|
unawaited(rq.close());
|
||||||
var rs = rq.response;
|
var rs = rq.response;
|
||||||
http
|
unawaited(http
|
||||||
.handleRequest(rq)
|
.handleRequest(rq)
|
||||||
.timeout(const Duration(seconds: 5))
|
.timeout(const Duration(seconds: 5))
|
||||||
.catchError((_) => null);
|
.catchError((_) => null));
|
||||||
|
|
||||||
await printResponse(rs);
|
await printResponse(rs);
|
||||||
expect(rs.statusCode, 500);
|
expect(rs.statusCode, 500);
|
||||||
|
|
||||||
rq = new MockHttpRequest('GET', Uri.parse('/session'));
|
rq = new MockHttpRequest('GET', Uri.parse('/session'));
|
||||||
rq.session['foo'] = 'bar';
|
rq.session['foo'] = 'bar';
|
||||||
rq.close();
|
unawaited(rq.close());
|
||||||
rs = rq.response;
|
rs = rq.response;
|
||||||
http.handleRequest(rq);
|
unawaited(http.handleRequest(rq));
|
||||||
|
|
||||||
await printResponse(rs);
|
await printResponse(rs);
|
||||||
expect(rs.statusCode, 200);
|
expect(rs.statusCode, 200);
|
||||||
|
@ -115,26 +118,29 @@ parameterMetaTests() {
|
||||||
// they will all function the same way.
|
// they will all function the same way.
|
||||||
|
|
||||||
test('pattern matching', () async {
|
test('pattern matching', () async {
|
||||||
var rq = new MockHttpRequest('GET', Uri.parse('/match?mode=pos'))..close();
|
var rq = new MockHttpRequest('GET', Uri.parse('/match?mode=pos'));
|
||||||
|
unawaited(rq.close());
|
||||||
var rs = rq.response;
|
var rs = rq.response;
|
||||||
http.handleRequest(rq);
|
unawaited(http.handleRequest(rq));
|
||||||
var body = await readResponse(rs);
|
var body = await readResponse(rs);
|
||||||
print('Body: $body');
|
print('Body: $body');
|
||||||
expect(rs.statusCode, 200);
|
expect(rs.statusCode, 200);
|
||||||
expect(body, json.encode('YES pos'));
|
expect(body, json.encode('YES pos'));
|
||||||
|
|
||||||
rq = new MockHttpRequest('GET', Uri.parse('/match?mode=neg'))..close();
|
rq = new MockHttpRequest('GET', Uri.parse('/match?mode=neg'));
|
||||||
|
unawaited(rq.close());
|
||||||
rs = rq.response;
|
rs = rq.response;
|
||||||
http.handleRequest(rq);
|
unawaited(http.handleRequest(rq));
|
||||||
body = await readResponse(rs);
|
body = await readResponse(rs);
|
||||||
print('Body: $body');
|
print('Body: $body');
|
||||||
expect(rs.statusCode, 200);
|
expect(rs.statusCode, 200);
|
||||||
expect(body, json.encode('NO neg'));
|
expect(body, json.encode('NO neg'));
|
||||||
|
|
||||||
// Fallback
|
// Fallback
|
||||||
rq = new MockHttpRequest('GET', Uri.parse('/match?mode=ambi'))..close();
|
rq = new MockHttpRequest('GET', Uri.parse('/match?mode=ambi'));
|
||||||
|
unawaited(rq.close());
|
||||||
rs = rq.response;
|
rs = rq.response;
|
||||||
http.handleRequest(rq);
|
unawaited(http.handleRequest(rq));
|
||||||
body = await readResponse(rs);
|
body = await readResponse(rs);
|
||||||
print('Body: $body');
|
print('Body: $body');
|
||||||
expect(rs.statusCode, 200);
|
expect(rs.statusCode, 200);
|
||||||
|
|
|
@ -4,6 +4,7 @@ import 'package:angel_container/mirrors.dart';
|
||||||
import 'package:angel_framework/angel_framework.dart';
|
import 'package:angel_framework/angel_framework.dart';
|
||||||
import 'package:angel_framework/http.dart';
|
import 'package:angel_framework/http.dart';
|
||||||
import 'package:mock_request/mock_request.dart';
|
import 'package:mock_request/mock_request.dart';
|
||||||
|
import 'package:pedantic/pedantic.dart';
|
||||||
import 'package:test/test.dart';
|
import 'package:test/test.dart';
|
||||||
|
|
||||||
main() {
|
main() {
|
||||||
|
@ -16,7 +17,7 @@ main() {
|
||||||
expect(app.preContained.keys, contains(echoAppFoo));
|
expect(app.preContained.keys, contains(echoAppFoo));
|
||||||
|
|
||||||
var rq = new MockHttpRequest('GET', new Uri(path: '/foo'));
|
var rq = new MockHttpRequest('GET', new Uri(path: '/foo'));
|
||||||
rq.close();
|
unawaited(rq.close());
|
||||||
await new AngelHttp(app).handleRequest(rq);
|
await new AngelHttp(app).handleRequest(rq);
|
||||||
var rs = rq.response;
|
var rs = rq.response;
|
||||||
var body = await rs.transform(utf8.decoder).join();
|
var body = await rs.transform(utf8.decoder).join();
|
||||||
|
|
|
@ -5,6 +5,7 @@ import 'package:angel_container/mirrors.dart';
|
||||||
import 'package:angel_framework/angel_framework.dart';
|
import 'package:angel_framework/angel_framework.dart';
|
||||||
import 'package:angel_framework/http.dart';
|
import 'package:angel_framework/http.dart';
|
||||||
import 'package:mock_request/mock_request.dart';
|
import 'package:mock_request/mock_request.dart';
|
||||||
|
import 'package:pedantic/pedantic.dart';
|
||||||
import 'package:test/test.dart';
|
import 'package:test/test.dart';
|
||||||
|
|
||||||
main() {
|
main() {
|
||||||
|
@ -38,21 +39,24 @@ main() {
|
||||||
tearDown(() => app.close());
|
tearDown(() => app.close());
|
||||||
|
|
||||||
test('String type annotation', () async {
|
test('String type annotation', () async {
|
||||||
var rq = new MockHttpRequest('GET', Uri.parse('/string/hello'))..close();
|
var rq = new MockHttpRequest('GET', Uri.parse('/string/hello'));
|
||||||
|
unawaited(rq.close());
|
||||||
await http.handleRequest(rq);
|
await http.handleRequest(rq);
|
||||||
var rs = await rq.response.transform(utf8.decoder).join();
|
var rs = await rq.response.transform(utf8.decoder).join();
|
||||||
expect(rs, json.encode('hello'));
|
expect(rs, json.encode('hello'));
|
||||||
});
|
});
|
||||||
|
|
||||||
test('Primitive after parsed param injection', () async {
|
test('Primitive after parsed param injection', () async {
|
||||||
var rq = new MockHttpRequest('GET', Uri.parse('/num/parsed/24'))..close();
|
var rq = new MockHttpRequest('GET', Uri.parse('/num/parsed/24'));
|
||||||
|
unawaited(rq.close());
|
||||||
await http.handleRequest(rq);
|
await http.handleRequest(rq);
|
||||||
var rs = await rq.response.transform(utf8.decoder).join();
|
var rs = await rq.response.transform(utf8.decoder).join();
|
||||||
expect(rs, json.encode(24));
|
expect(rs, json.encode(24));
|
||||||
});
|
});
|
||||||
|
|
||||||
test('globally-injected primitive', () async {
|
test('globally-injected primitive', () async {
|
||||||
var rq = new MockHttpRequest('GET', Uri.parse('/num/global'))..close();
|
var rq = new MockHttpRequest('GET', Uri.parse('/num/global'));
|
||||||
|
unawaited(rq.close());
|
||||||
await http.handleRequest(rq);
|
await http.handleRequest(rq);
|
||||||
var rs = await rq.response.transform(utf8.decoder).join();
|
var rs = await rq.response.transform(utf8.decoder).join();
|
||||||
expect(rs, json.encode(305));
|
expect(rs, json.encode(305));
|
||||||
|
@ -60,8 +64,8 @@ main() {
|
||||||
|
|
||||||
test('unparsed primitive throws error', () async {
|
test('unparsed primitive throws error', () async {
|
||||||
try {
|
try {
|
||||||
var rq = new MockHttpRequest('GET', Uri.parse('/num/unparsed/32'))
|
var rq = new MockHttpRequest('GET', Uri.parse('/num/unparsed/32'));
|
||||||
..close();
|
unawaited(rq.close());
|
||||||
var req = await http.createRequestContext(rq, rq.response);
|
var req = await http.createRequestContext(rq, rq.response);
|
||||||
var res = await http.createResponseContext(rq, rq.response, req);
|
var res = await http.createResponseContext(rq, rq.response, req);
|
||||||
await app.runContained((num unparsed) => unparsed, req, res);
|
await app.runContained((num unparsed) => unparsed, req, res);
|
||||||
|
|
|
@ -7,6 +7,7 @@ import 'package:angel_framework/angel_framework.dart';
|
||||||
import 'package:angel_framework/http.dart';
|
import 'package:angel_framework/http.dart';
|
||||||
import 'package:matcher/matcher.dart';
|
import 'package:matcher/matcher.dart';
|
||||||
import 'package:mock_request/mock_request.dart';
|
import 'package:mock_request/mock_request.dart';
|
||||||
|
import 'package:pedantic/pedantic.dart';
|
||||||
import 'package:test/test.dart';
|
import 'package:test/test.dart';
|
||||||
|
|
||||||
final Uri $foo = Uri.parse('http://localhost:3000/foo');
|
final Uri $foo = Uri.parse('http://localhost:3000/foo');
|
||||||
|
@ -42,7 +43,7 @@ main() {
|
||||||
var app = new Angel(reflector: MirrorsReflector());
|
var app = new Angel(reflector: MirrorsReflector());
|
||||||
var http = new AngelHttp(app);
|
var http = new AngelHttp(app);
|
||||||
var rq = new MockHttpRequest('GET', $foo);
|
var rq = new MockHttpRequest('GET', $foo);
|
||||||
rq.close();
|
unawaited(rq.close());
|
||||||
var rs = rq.response;
|
var rs = rq.response;
|
||||||
var req = await http.createRequestContext(rq, rs);
|
var req = await http.createRequestContext(rq, rs);
|
||||||
var res = await http.createResponseContext(rq, rs);
|
var res = await http.createResponseContext(rq, rs);
|
||||||
|
@ -94,7 +95,8 @@ main() {
|
||||||
..configuration['a'] = 'b';
|
..configuration['a'] = 'b';
|
||||||
var http = new AngelHttp(app);
|
var http = new AngelHttp(app);
|
||||||
app.get('/', ioc((String a) => a));
|
app.get('/', ioc((String a) => a));
|
||||||
var rq = new MockHttpRequest('GET', Uri.parse('/'))..close();
|
var rq = new MockHttpRequest('GET', Uri.parse('/'));
|
||||||
|
unawaited(rq.close());
|
||||||
await http.handleRequest(rq);
|
await http.handleRequest(rq);
|
||||||
var body = await rq.response.transform(utf8.decoder).join();
|
var body = await rq.response.transform(utf8.decoder).join();
|
||||||
expect(body, json.encode('b'));
|
expect(body, json.encode('b'));
|
||||||
|
@ -104,7 +106,8 @@ main() {
|
||||||
var app = new Angel(reflector: MirrorsReflector())..serializer = (_) => 'x';
|
var app = new Angel(reflector: MirrorsReflector())..serializer = (_) => 'x';
|
||||||
var http = new AngelHttp(app);
|
var http = new AngelHttp(app);
|
||||||
app.get($foo.path, (req, ResponseContext res) => res.serialize(null));
|
app.get($foo.path, (req, ResponseContext res) => res.serialize(null));
|
||||||
var rq = new MockHttpRequest('GET', $foo)..close();
|
var rq = new MockHttpRequest('GET', $foo);
|
||||||
|
unawaited(rq.close());
|
||||||
await http.handleRequest(rq);
|
await http.handleRequest(rq);
|
||||||
var body = await rq.response.transform(utf8.decoder).join();
|
var body = await rq.response.transform(utf8.decoder).join();
|
||||||
expect(body, 'x');
|
expect(body, 'x');
|
||||||
|
@ -119,7 +122,8 @@ main() {
|
||||||
ResponseContext res;
|
ResponseContext res;
|
||||||
|
|
||||||
setUp(() async {
|
setUp(() async {
|
||||||
var rq = new MockHttpRequest('GET', $foo)..close();
|
var rq = new MockHttpRequest('GET', $foo);
|
||||||
|
unawaited(rq.close());
|
||||||
req = await http.createRequestContext(rq, rq.response);
|
req = await http.createRequestContext(rq, rq.response);
|
||||||
res = await http.createResponseContext(rq, rq.response);
|
res = await http.createResponseContext(rq, rq.response);
|
||||||
});
|
});
|
||||||
|
@ -176,8 +180,8 @@ main() {
|
||||||
test('can send json', () async {
|
test('can send json', () async {
|
||||||
var rq = new MockHttpRequest('GET', new Uri(path: 'wtf'))
|
var rq = new MockHttpRequest('GET', new Uri(path: 'wtf'))
|
||||||
..headers.set('accept', 'application/json');
|
..headers.set('accept', 'application/json');
|
||||||
rq.close();
|
unawaited(rq.close());
|
||||||
http.handleRequest(rq);
|
unawaited(http.handleRequest(rq));
|
||||||
await rq.response.toList();
|
await rq.response.toList();
|
||||||
expect(rq.response.statusCode, 403);
|
expect(rq.response.statusCode, 403);
|
||||||
expect(rq.response.headers.contentType.mimeType, 'application/json');
|
expect(rq.response.headers.contentType.mimeType, 'application/json');
|
||||||
|
@ -186,8 +190,8 @@ main() {
|
||||||
test('can throw in finalizer', () async {
|
test('can throw in finalizer', () async {
|
||||||
var rq = new MockHttpRequest('GET', new Uri(path: 'wtf'))
|
var rq = new MockHttpRequest('GET', new Uri(path: 'wtf'))
|
||||||
..headers.set('accept', 'application/json');
|
..headers.set('accept', 'application/json');
|
||||||
rq.close();
|
unawaited(rq.close());
|
||||||
http.handleRequest(rq);
|
unawaited(http.handleRequest(rq));
|
||||||
await rq.response.toList();
|
await rq.response.toList();
|
||||||
expect(rq.response.statusCode, 403);
|
expect(rq.response.statusCode, 403);
|
||||||
expect(rq.response.headers.contentType.mimeType, 'application/json');
|
expect(rq.response.headers.contentType.mimeType, 'application/json');
|
||||||
|
@ -196,8 +200,8 @@ main() {
|
||||||
test('can send html', () async {
|
test('can send html', () async {
|
||||||
var rq = new MockHttpRequest('GET', new Uri(path: 'wtf2'));
|
var rq = new MockHttpRequest('GET', new Uri(path: 'wtf2'));
|
||||||
rq.headers.set('accept', 'text/html');
|
rq.headers.set('accept', 'text/html');
|
||||||
rq.close();
|
unawaited(rq.close());
|
||||||
http.handleRequest(rq);
|
unawaited(http.handleRequest(rq));
|
||||||
await rq.response.toList();
|
await rq.response.toList();
|
||||||
expect(rq.response.statusCode, 403);
|
expect(rq.response.statusCode, 403);
|
||||||
expect(rq.response.headers.contentType?.mimeType, 'text/html');
|
expect(rq.response.headers.contentType?.mimeType, 'text/html');
|
||||||
|
|
|
@ -8,6 +8,7 @@ import 'package:angel_framework/angel_framework.dart';
|
||||||
import 'package:angel_framework/http.dart';
|
import 'package:angel_framework/http.dart';
|
||||||
import 'package:logging/logging.dart';
|
import 'package:logging/logging.dart';
|
||||||
import 'package:mock_request/mock_request.dart';
|
import 'package:mock_request/mock_request.dart';
|
||||||
|
import 'package:pedantic/pedantic.dart';
|
||||||
import 'package:test/test.dart';
|
import 'package:test/test.dart';
|
||||||
|
|
||||||
import 'encoders_buffer_test.dart' show encodingTests;
|
import 'encoders_buffer_test.dart' show encodingTests;
|
||||||
|
@ -76,7 +77,8 @@ main() {
|
||||||
tearDown(() => http.close());
|
tearDown(() => http.close());
|
||||||
|
|
||||||
_expectHelloBye(String path) async {
|
_expectHelloBye(String path) async {
|
||||||
var rq = new MockHttpRequest('GET', Uri.parse(path))..close();
|
var rq = new MockHttpRequest('GET', Uri.parse(path));
|
||||||
|
unawaited(rq.close());
|
||||||
await http.handleRequest(rq);
|
await http.handleRequest(rq);
|
||||||
var body = await rq.response.transform(utf8.decoder).join();
|
var body = await rq.response.transform(utf8.decoder).join();
|
||||||
expect(body, 'Hello, world!bye');
|
expect(body, 'Hello, world!bye');
|
||||||
|
@ -88,7 +90,8 @@ main() {
|
||||||
|
|
||||||
test('cannot write after close', () async {
|
test('cannot write after close', () async {
|
||||||
try {
|
try {
|
||||||
var rq = new MockHttpRequest('GET', Uri.parse('/overwrite'))..close();
|
var rq = new MockHttpRequest('GET', Uri.parse('/overwrite'));
|
||||||
|
unawaited(rq.close());
|
||||||
await http.handleRequest(rq);
|
await http.handleRequest(rq);
|
||||||
var body = await rq.response.transform(utf8.decoder).join();
|
var body = await rq.response.transform(utf8.decoder).join();
|
||||||
|
|
||||||
|
@ -101,7 +104,8 @@ main() {
|
||||||
|
|
||||||
test('res => addError', () async {
|
test('res => addError', () async {
|
||||||
try {
|
try {
|
||||||
var rq = new MockHttpRequest('GET', Uri.parse('/error'))..close();
|
var rq = new MockHttpRequest('GET', Uri.parse('/error'));
|
||||||
|
unawaited(rq.close());
|
||||||
await http.handleRequest(rq);
|
await http.handleRequest(rq);
|
||||||
var body = await rq.response.transform(utf8.decoder).join();
|
var body = await rq.response.transform(utf8.decoder).join();
|
||||||
throw 'addError should throw error; response: $body';
|
throw 'addError should throw error; response: $body';
|
||||||
|
|
Loading…
Reference in a new issue