dartfmt (with 1.23.0-dev.10.0)
diff --git a/lib/shelf_io.dart b/lib/shelf_io.dart
index d66bbe0..93cb26d 100644
--- a/lib/shelf_io.dart
+++ b/lib/shelf_io.dart
@@ -65,8 +65,8 @@
try {
shelfRequest = _fromHttpRequest(request);
} catch (error, stackTrace) {
- var response = _logTopLevelError(
- 'Error parsing request.\n$error', stackTrace);
+ var response =
+ _logTopLevelError('Error parsing request.\n$error', stackTrace);
await _writeResponse(response, request.response);
return;
}
@@ -81,18 +81,15 @@
if (!shelfRequest.canHijack) return;
// If the request wasn't hijacked, we shouldn't be seeing this exception.
- response = _logError(
- shelfRequest,
- "Caught HijackException, but the request wasn't hijacked.",
- stackTrace);
+ response = _logError(shelfRequest,
+ "Caught HijackException, but the request wasn't hijacked.", stackTrace);
} catch (error, stackTrace) {
- response = _logError(
- shelfRequest, 'Error thrown by handler.\n$error', stackTrace);
+ response =
+ _logError(shelfRequest, 'Error thrown by handler.\n$error', stackTrace);
}
if (response == null) {
- await _writeResponse(
- _logError(shelfRequest, 'null response from handler.'),
+ await _writeResponse(_logError(shelfRequest, 'null response from handler.'),
request.response);
return;
} else if (shelfRequest.canHijack) {
@@ -104,8 +101,7 @@
..writeln("Got a response for hijacked request "
"${shelfRequest.method} ${shelfRequest.requestedUri}:")
..writeln(response.statusCode);
- response.headers
- .forEach((key, value) => message.writeln("${key}: ${value}"));
+ response.headers.forEach((key, value) => message.writeln("${key}: ${value}"));
throw new Exception(message.toString().trim());
}
@@ -158,8 +154,8 @@
// otherwise `dart:io` will try to add another layer of chunking.
//
// TODO(nweiz): Do this more cleanly when sdk#27886 is fixed.
- response = response.change(
- body: chunkedCoding.decoder.bind(response.read()));
+ response =
+ response.change(body: chunkedCoding.decoder.bind(response.read()));
httpResponse.headers.set(HttpHeaders.TRANSFER_ENCODING, 'chunked');
} else if (response.statusCode >= 200 &&
response.statusCode != 204 &&
@@ -205,7 +201,8 @@
chain = new Chain.forTrace(stackTrace);
}
chain = chain
- .foldFrames((frame) => frame.isCore || frame.package == 'shelf').terse;
+ .foldFrames((frame) => frame.isCore || frame.package == 'shelf')
+ .terse;
stderr.writeln('ERROR - ${new DateTime.now()}');
stderr.writeln(message);
diff --git a/lib/src/cascade.dart b/lib/src/cascade.dart
index 1f3b167..37e531b 100644
--- a/lib/src/cascade.dart
+++ b/lib/src/cascade.dart
@@ -80,8 +80,8 @@
/// Computes the [Cascade._shouldCascade] function based on the user's
/// parameters.
-_ShouldCascade _computeShouldCascade(Iterable<int> statusCodes,
- bool shouldCascade(Response response)) {
+_ShouldCascade _computeShouldCascade(
+ Iterable<int> statusCodes, bool shouldCascade(Response response)) {
if (shouldCascade != null) return shouldCascade;
if (statusCodes == null) statusCodes = [404, 405];
statusCodes = statusCodes.toSet();
diff --git a/lib/src/message.dart b/lib/src/message.dart
index 1f474fd..0f13e85 100644
--- a/lib/src/message.dart
+++ b/lib/src/message.dart
@@ -17,7 +17,8 @@
/// The default set of headers for a message created with no body and no
/// explicit headers.
final _defaultHeaders = new ShelfUnmodifiableMap<String>(
- {"content-length": "0"}, ignoreKeyCase: true);
+ {"content-length": "0"},
+ ignoreKeyCase: true);
/// Represents logic shared between [Request] and [Response].
abstract class Message {
@@ -61,16 +62,19 @@
/// If [encoding] is passed, the "encoding" field of the Content-Type header
/// in [headers] will be set appropriately. If there is no existing
/// Content-Type header, it will be set to "application/octet-stream".
- Message(body, {Encoding encoding, Map<String, String> headers,
+ Message(body,
+ {Encoding encoding,
+ Map<String, String> headers,
Map<String, Object> context})
: this._(new Body(body, encoding), headers, context);
Message._(Body body, Map<String, String> headers, Map<String, Object> context)
: _body = body,
headers = new ShelfUnmodifiableMap<String>(
- _adjustHeaders(headers, body), ignoreKeyCase: true),
- context = new ShelfUnmodifiableMap<Object>(context,
- ignoreKeyCase: false);
+ _adjustHeaders(headers, body),
+ ignoreKeyCase: true),
+ context =
+ new ShelfUnmodifiableMap<Object>(context, ignoreKeyCase: false);
/// The contents of the content-length field in [headers].
///
@@ -81,6 +85,7 @@
_contentLengthCache = int.parse(headers['content-length']);
return _contentLengthCache;
}
+
int _contentLengthCache;
/// The MIME type of the message.
@@ -118,6 +123,7 @@
_contentTypeCache = new MediaType.parse(headers['content-type']);
return _contentTypeCache;
}
+
MediaType _contentTypeCache;
/// Returns a [Stream] representing the body.
@@ -140,20 +146,18 @@
/// Creates a new [Message] by copying existing values and applying specified
/// changes.
- Message change({Map<String, String> headers, Map<String, Object> context,
- body});
+ Message change(
+ {Map<String, String> headers, Map<String, Object> context, body});
}
/// Adds information about [encoding] to [headers].
///
/// Returns a new map without modifying [headers].
-Map<String, String> _adjustHeaders(
- Map<String, String> headers, Body body) {
+Map<String, String> _adjustHeaders(Map<String, String> headers, Body body) {
var sameEncoding = _sameEncoding(headers, body);
if (sameEncoding) {
if (body.contentLength == null ||
- getHeader(headers, 'content-length') ==
- body.contentLength.toString()) {
+ getHeader(headers, 'content-length') == body.contentLength.toString()) {
return headers ?? const ShelfUnmodifiableMap.empty();
} else if (body.contentLength == 0 &&
(headers == null || headers.isEmpty)) {
diff --git a/lib/src/middleware.dart b/lib/src/middleware.dart
index 3eac69f..a270b4e 100644
--- a/lib/src/middleware.dart
+++ b/lib/src/middleware.dart
@@ -46,7 +46,8 @@
/// does not receive errors thrown by [requestHandler] or [responseHandler], nor
/// does it receive [HijackException]s. It can either return a new response or
/// throw an error.
-Middleware createMiddleware({requestHandler(Request request),
+Middleware createMiddleware(
+ {requestHandler(Request request),
responseHandler(Response response),
errorHandler(error, StackTrace stackTrace)}) {
if (requestHandler == null) requestHandler = (request) => null;
@@ -66,8 +67,8 @@
return new Future.sync(() => requestHandler(request)).then((response) {
if (response != null) return response;
- return new Future.sync(() => innerHandler(request)).then(
- (response) => responseHandler(response), onError: onError);
+ return new Future.sync(() => innerHandler(request))
+ .then((response) => responseHandler(response), onError: onError);
});
};
};
diff --git a/lib/src/middleware/logger.dart b/lib/src/middleware/logger.dart
index 98866d5..b127315 100644
--- a/lib/src/middleware/logger.dart
+++ b/lib/src/middleware/logger.dart
@@ -21,31 +21,31 @@
/// If [logger] is not passed, the message is just passed to [print].
Middleware logRequests({void logger(String msg, bool isError)}) =>
(innerHandler) {
- if (logger == null) logger = _defaultLogger;
+ if (logger == null) logger = _defaultLogger;
- return (request) {
- var startTime = new DateTime.now();
- var watch = new Stopwatch()..start();
+ return (request) {
+ var startTime = new DateTime.now();
+ var watch = new Stopwatch()..start();
- return new Future.sync(() => innerHandler(request)).then((response) {
- var msg = _getMessage(startTime, response.statusCode,
- request.requestedUri, request.method, watch.elapsed);
+ return new Future.sync(() => innerHandler(request)).then((response) {
+ var msg = _getMessage(startTime, response.statusCode,
+ request.requestedUri, request.method, watch.elapsed);
- logger(msg, false);
+ logger(msg, false);
- return response;
- }, onError: (error, stackTrace) {
- if (error is HijackException) throw error;
+ return response;
+ }, onError: (error, stackTrace) {
+ if (error is HijackException) throw error;
- var msg = _getErrorMessage(startTime, request.requestedUri,
- request.method, watch.elapsed, error, stackTrace);
+ var msg = _getErrorMessage(startTime, request.requestedUri,
+ request.method, watch.elapsed, error, stackTrace);
- logger(msg, true);
+ logger(msg, true);
- throw error;
- });
- };
-};
+ throw error;
+ });
+ };
+ };
String _formatQuery(String query) {
return query == '' ? '' : '?$query';
@@ -62,7 +62,8 @@
var chain = new Chain.current();
if (stack != null) {
chain = new Chain.forTrace(stack)
- .foldFrames((frame) => frame.isCore || frame.package == 'shelf').terse;
+ .foldFrames((frame) => frame.isCore || frame.package == 'shelf')
+ .terse;
}
var msg = '${requestTime}\t$elapsedTime\t$method\t${requestedUri.path}'
diff --git a/lib/src/request.dart b/lib/src/request.dart
index 0d0154d..b297879 100644
--- a/lib/src/request.dart
+++ b/lib/src/request.dart
@@ -85,6 +85,7 @@
_ifModifiedSinceCache = parseHttpDate(headers['if-modified-since']);
return _ifModifiedSinceCache;
}
+
DateTime _ifModifiedSinceCache;
/// Creates a new [Request].
@@ -133,20 +134,25 @@
///
/// See also [hijack].
// TODO(kevmoo) finish documenting the rest of the arguments.
- Request(String method, Uri requestedUri, {String protocolVersion,
- Map<String, String> headers, String handlerPath, Uri url, body,
- Encoding encoding, Map<String, Object> context,
- void onHijack(void hijack(
- Stream<List<int>> stream, StreamSink<List<int>> sink))})
+ Request(String method, Uri requestedUri,
+ {String protocolVersion,
+ Map<String, String> headers,
+ String handlerPath,
+ Uri url,
+ body,
+ Encoding encoding,
+ Map<String, Object> context,
+ void onHijack(
+ void hijack(Stream<List<int>> stream, StreamSink<List<int>> sink))})
: this._(method, requestedUri,
- protocolVersion: protocolVersion,
- headers: headers,
- url: url,
- handlerPath: handlerPath,
- body: body,
- encoding: encoding,
- context: context,
- onHijack: onHijack == null ? null : new _OnHijack(onHijack));
+ protocolVersion: protocolVersion,
+ headers: headers,
+ url: url,
+ handlerPath: handlerPath,
+ body: body,
+ encoding: encoding,
+ context: context,
+ onHijack: onHijack == null ? null : new _OnHijack(onHijack));
/// This constructor has the same signature as [new Request] except that
/// accepts [onHijack] as [_OnHijack].
@@ -154,13 +160,18 @@
/// Any [Request] created by calling [change] will pass [_onHijack] from the
/// source [Request] to ensure that [hijack] can only be called once, even
/// from a changed [Request].
- Request._(this.method, Uri requestedUri, {String protocolVersion,
- Map<String, String> headers, String handlerPath, Uri url, body,
- Encoding encoding, Map<String, Object> context, _OnHijack onHijack})
+ Request._(this.method, Uri requestedUri,
+ {String protocolVersion,
+ Map<String, String> headers,
+ String handlerPath,
+ Uri url,
+ body,
+ Encoding encoding,
+ Map<String, Object> context,
+ _OnHijack onHijack})
: this.requestedUri = requestedUri,
- this.protocolVersion = protocolVersion == null
- ? '1.1'
- : protocolVersion,
+ this.protocolVersion =
+ protocolVersion == null ? '1.1' : protocolVersion,
this.url = _computeUrl(requestedUri, handlerPath, url),
this.handlerPath = _computeHandlerPath(requestedUri, handlerPath, url),
this._onHijack = onHijack,
@@ -207,8 +218,11 @@
/// request = request.change(path: "dir");
/// print(request.handlerPath); // => /static/dir/
/// print(request.url); // => file.html
- Request change({Map<String, String> headers, Map<String, Object> context,
- String path, body}) {
+ Request change(
+ {Map<String, String> headers,
+ Map<String, Object> context,
+ String path,
+ body}) {
headers = updateMap(this.headers, headers);
context = updateMap(this.context, context);
diff --git a/lib/src/response.dart b/lib/src/response.dart
index a06bba9..67e028e 100644
--- a/lib/src/response.dart
+++ b/lib/src/response.dart
@@ -25,6 +25,7 @@
_expiresCache = parseHttpDate(headers['expires']);
return _expiresCache;
}
+
DateTime _expiresCache;
/// The date and time the source of the response's data was last modified.
@@ -37,6 +38,7 @@
_lastModifiedCache = parseHttpDate(headers['last-modified']);
return _lastModifiedCache;
}
+
DateTime _lastModifiedCache;
/// Constructs a 200 OK response.
@@ -57,10 +59,12 @@
/// If [encoding] is passed, the "encoding" field of the Content-Type header
/// in [headers] will be set appropriately. If there is no existing
/// Content-Type header, it will be set to "application/octet-stream".
- Response.ok(body, {Map<String, String> headers, Encoding encoding,
- Map<String, Object> context})
- : this(200, body: body, headers: headers, encoding: encoding,
- context: context);
+ Response.ok(body,
+ {Map<String, String> headers,
+ Encoding encoding,
+ Map<String, Object> context})
+ : this(200,
+ body: body, headers: headers, encoding: encoding, context: context);
/// Constructs a 301 Moved Permanently response.
///
@@ -82,10 +86,13 @@
/// If [encoding] is passed, the "encoding" field of the Content-Type header
/// in [headers] will be set appropriately. If there is no existing
/// Content-Type header, it will be set to "application/octet-stream".
- Response.movedPermanently(location, {body, Map<String, String> headers,
- Encoding encoding, Map<String, Object> context})
+ Response.movedPermanently(location,
+ {body,
+ Map<String, String> headers,
+ Encoding encoding,
+ Map<String, Object> context})
: this._redirect(301, location, body, headers, encoding,
- context: context);
+ context: context);
/// Constructs a 302 Found response.
///
@@ -107,10 +114,13 @@
/// If [encoding] is passed, the "encoding" field of the Content-Type header
/// in [headers] will be set appropriately. If there is no existing
/// Content-Type header, it will be set to "application/octet-stream".
- Response.found(location, {body, Map<String, String> headers,
- Encoding encoding, Map<String, Object> context})
+ Response.found(location,
+ {body,
+ Map<String, String> headers,
+ Encoding encoding,
+ Map<String, Object> context})
: this._redirect(302, location, body, headers, encoding,
- context: context);
+ context: context);
/// Constructs a 303 See Other response.
///
@@ -133,20 +143,23 @@
/// If [encoding] is passed, the "encoding" field of the Content-Type header
/// in [headers] will be set appropriately. If there is no existing
/// Content-Type header, it will be set to "application/octet-stream".
- Response.seeOther(location, {body, Map<String, String> headers,
- Encoding encoding, Map<String, Object> context})
+ Response.seeOther(location,
+ {body,
+ Map<String, String> headers,
+ Encoding encoding,
+ Map<String, Object> context})
: this._redirect(303, location, body, headers, encoding,
- context: context);
+ context: context);
/// Constructs a helper constructor for redirect responses.
Response._redirect(int statusCode, location, body,
Map<String, String> headers, Encoding encoding,
- { Map<String, Object> context })
+ {Map<String, Object> context})
: this(statusCode,
body: body,
encoding: encoding,
- headers: addHeader(
- headers, 'location', _locationToString(location)),
+ headers:
+ addHeader(headers, 'location', _locationToString(location)),
context: context);
/// Constructs a 304 Not Modified response.
@@ -155,10 +168,11 @@
/// information used to determine whether the requested resource has changed
/// since the last request. It indicates that the resource has not changed and
/// the old value should be used.
- Response.notModified({Map<String, String> headers,
- Map<String, Object> context})
- : this(304, headers: addHeader(
- headers, 'date', formatHttpDate(new DateTime.now())),
+ Response.notModified(
+ {Map<String, String> headers, Map<String, Object> context})
+ : this(304,
+ headers:
+ addHeader(headers, 'date', formatHttpDate(new DateTime.now())),
context: context);
/// Constructs a 403 Forbidden response.
@@ -179,12 +193,14 @@
/// If [encoding] is passed, the "encoding" field of the Content-Type header
/// in [headers] will be set appropriately. If there is no existing
/// Content-Type header, it will be set to "application/octet-stream".
- Response.forbidden(body, {Map<String, String> headers,
- Encoding encoding, Map<String, Object> context})
+ Response.forbidden(body,
+ {Map<String, String> headers,
+ Encoding encoding,
+ Map<String, Object> context})
: this(403,
- headers: body == null ? _adjustErrorHeaders(headers) : headers,
- body: body == null ? 'Forbidden' : body,
- context: context);
+ headers: body == null ? _adjustErrorHeaders(headers) : headers,
+ body: body == null ? 'Forbidden' : body,
+ context: context);
/// Constructs a 404 Not Found response.
///
@@ -205,12 +221,14 @@
/// If [encoding] is passed, the "encoding" field of the Content-Type header
/// in [headers] will be set appropriately. If there is no existing
/// Content-Type header, it will be set to "application/octet-stream".
- Response.notFound(body, {Map<String, String> headers, Encoding encoding,
- Map<String, Object> context})
+ Response.notFound(body,
+ {Map<String, String> headers,
+ Encoding encoding,
+ Map<String, Object> context})
: this(404,
- headers: body == null ? _adjustErrorHeaders(headers) : headers,
- body: body == null ? 'Not Found' : body,
- context: context);
+ headers: body == null ? _adjustErrorHeaders(headers) : headers,
+ body: body == null ? 'Not Found' : body,
+ context: context);
/// Constructs a 500 Internal Server Error response.
///
@@ -231,8 +249,11 @@
/// If [encoding] is passed, the "encoding" field of the Content-Type header
/// in [headers] will be set appropriately. If there is no existing
/// Content-Type header, it will be set to "application/octet-stream".
- Response.internalServerError({body, Map<String, String> headers,
- Encoding encoding, Map<String, Object> context})
+ Response.internalServerError(
+ {body,
+ Map<String, String> headers,
+ Encoding encoding,
+ Map<String, Object> context})
: this(500,
headers: body == null ? _adjustErrorHeaders(headers) : headers,
body: body == null ? 'Internal Server Error' : body,
@@ -256,8 +277,11 @@
/// If [encoding] is passed, the "encoding" field of the Content-Type header
/// in [headers] will be set appropriately. If there is no existing
/// Content-Type header, it will be set to "application/octet-stream".
- Response(this.statusCode, {body, Map<String, String> headers,
- Encoding encoding, Map<String, Object> context})
+ Response(this.statusCode,
+ {body,
+ Map<String, String> headers,
+ Encoding encoding,
+ Map<String, Object> context})
: super(body, encoding: encoding, headers: headers, context: context) {
if (statusCode < 100) {
throw new ArgumentError("Invalid status code: $statusCode.");
@@ -286,8 +310,8 @@
if (body == null) body = getBody(this);
- return new Response(this.statusCode, body: body, headers: headers,
- context: context);
+ return new Response(this.statusCode,
+ body: body, headers: headers, context: context);
}
}
diff --git a/lib/src/server_handler.dart b/lib/src/server_handler.dart
index fbe765a..eb5f6fd 100644
--- a/lib/src/server_handler.dart
+++ b/lib/src/server_handler.dart
@@ -82,7 +82,7 @@
}
Future close() => _closeMemo.runOnce(() {
- return _onClose == null ? null : _onClose();
- });
+ return _onClose == null ? null : _onClose();
+ });
final _closeMemo = new AsyncMemoizer();
}
diff --git a/lib/src/util.dart b/lib/src/util.dart
index fcf66d8..0ebf839 100644
--- a/lib/src/util.dart
+++ b/lib/src/util.dart
@@ -32,8 +32,8 @@
/// [updates] is used.
///
/// If [updates] is `null` or empty, [original] is returned unchanged.
-Map/*<K, V>*/ updateMap/*<K, V>*/(Map/*<K, V>*/ original,
- Map/*<K, V>*/ updates) {
+Map/*<K, V>*/ updateMap/*<K, V>*/(
+ Map/*<K, V>*/ original, Map/*<K, V>*/ updates) {
if (updates == null || updates.isEmpty) return original;
return new Map.from(original)..addAll(updates);
diff --git a/test/add_chunked_encoding_test.dart b/test/add_chunked_encoding_test.dart
index d854c8f..ad12d73 100644
--- a/test/add_chunked_encoding_test.dart
+++ b/test/add_chunked_encoding_test.dart
@@ -30,36 +30,36 @@
});
test("doesn't add chunked encoding with status 1xx", () async {
- var response = await _chunkResponse(
- new Response(123, body: new Stream.empty()));
+ var response =
+ await _chunkResponse(new Response(123, body: new Stream.empty()));
expect(response.headers, isNot(contains('transfer-encoding')));
expect(response.read().toList(), completion(isEmpty));
});
test("doesn't add chunked encoding with status 204", () async {
- var response = await _chunkResponse(
- new Response(204, body: new Stream.empty()));
+ var response =
+ await _chunkResponse(new Response(204, body: new Stream.empty()));
expect(response.headers, isNot(contains('transfer-encoding')));
expect(response.read().toList(), completion(isEmpty));
});
test("doesn't add chunked encoding with status 304", () async {
- var response = await _chunkResponse(
- new Response(204, body: new Stream.empty()));
+ var response =
+ await _chunkResponse(new Response(204, body: new Stream.empty()));
expect(response.headers, isNot(contains('transfer-encoding')));
expect(response.read().toList(), completion(isEmpty));
});
test("doesn't add chunked encoding with status 204", () async {
- var response = await _chunkResponse(
- new Response(204, body: new Stream.empty()));
+ var response =
+ await _chunkResponse(new Response(204, body: new Stream.empty()));
expect(response.headers, isNot(contains('transfer-encoding')));
expect(response.read().toList(), completion(isEmpty));
});
test("doesn't add chunked encoding with status 204", () async {
- var response = await _chunkResponse(
- new Response(204, body: new Stream.empty()));
+ var response =
+ await _chunkResponse(new Response(204, body: new Stream.empty()));
expect(response.headers, isNot(contains('transfer-encoding')));
expect(response.read().toList(), completion(isEmpty));
});
diff --git a/test/cascade_test.dart b/test/cascade_test.dart
index d636cbd..e935472 100644
--- a/test/cascade_test.dart
+++ b/test/cascade_test.dart
@@ -40,7 +40,8 @@
expect(response.readAsString(), completion(equals('handler 1')));
});
- test("the second response should be returned if it matches and the first "
+ test(
+ "the second response should be returned if it matches and the first "
"doesn't", () {
return new Future.sync(() {
return handler(
@@ -51,7 +52,8 @@
});
});
- test("the third response should be returned if it matches and the first "
+ test(
+ "the third response should be returned if it matches and the first "
"two don't", () {
return new Future.sync(() {
return handler(new Request('GET', LOCALHOST_URI,
@@ -112,13 +114,13 @@
});
test('[shouldCascade] controls which responses cause cascading', () {
- var handler = new Cascade(
- shouldCascade: (response) => response.statusCode % 2 == 1)
- .add((_) => new Response.movedPermanently('/'))
- .add((_) => new Response.forbidden('handler 2'))
- .add((_) => new Response.notFound('handler 3'))
- .add((_) => new Response.ok('handler 4'))
- .handler;
+ var handler =
+ new Cascade(shouldCascade: (response) => response.statusCode % 2 == 1)
+ .add((_) => new Response.movedPermanently('/'))
+ .add((_) => new Response.forbidden('handler 2'))
+ .add((_) => new Response.notFound('handler 3'))
+ .add((_) => new Response.ok('handler 4'))
+ .handler;
return makeSimpleRequest(handler).then((response) {
expect(response.statusCode, equals(404));
@@ -133,7 +135,8 @@
test('passing [statusCodes] and [shouldCascade] at the same time fails',
() {
- expect(() =>
+ expect(
+ () =>
new Cascade(statusCodes: [404, 405], shouldCascade: (_) => false),
throwsArgumentError);
});
diff --git a/test/create_middleware_test.dart b/test/create_middleware_test.dart
index 2ec5488..bb4b245 100644
--- a/test/create_middleware_test.dart
+++ b/test/create_middleware_test.dart
@@ -147,9 +147,11 @@
});
test('throw from responseHandler does not hit error handler', () {
- var middleware = createMiddleware(responseHandler: (response) {
- throw 'middleware error';
- }, errorHandler: (e, s) => fail('should never get here'));
+ var middleware = createMiddleware(
+ responseHandler: (response) {
+ throw 'middleware error';
+ },
+ errorHandler: (e, s) => fail('should never get here'));
var handler =
const Pipeline().addMiddleware(middleware).addHandler(syncHandler);
@@ -158,9 +160,11 @@
});
test('requestHandler throw does not hit errorHandlers', () {
- var middleware = createMiddleware(requestHandler: (request) {
- throw 'middleware error';
- }, errorHandler: (e, s) => fail('should never get here'));
+ var middleware = createMiddleware(
+ requestHandler: (request) {
+ throw 'middleware error';
+ },
+ errorHandler: (e, s) => fail('should never get here'));
var handler =
const Pipeline().addMiddleware(middleware).addHandler(syncHandler);
@@ -174,9 +178,8 @@
return _middlewareResponse;
});
- var handler = const Pipeline()
- .addMiddleware(middleware)
- .addHandler((request) {
+ var handler =
+ const Pipeline().addMiddleware(middleware).addHandler((request) {
throw 'bad handler';
});
@@ -191,22 +194,21 @@
throw error;
});
- var handler = const Pipeline()
- .addMiddleware(middleware)
- .addHandler((request) {
+ var handler =
+ const Pipeline().addMiddleware(middleware).addHandler((request) {
throw 'bad handler';
});
expect(makeSimpleRequest(handler), throwsA('bad handler'));
});
- test('error thrown by inner handler without a middleware errorHandler is '
+ test(
+ 'error thrown by inner handler without a middleware errorHandler is '
'rethrown', () {
var middleware = createMiddleware();
- var handler = const Pipeline()
- .addMiddleware(middleware)
- .addHandler((request) {
+ var handler =
+ const Pipeline().addMiddleware(middleware).addHandler((request) {
throw 'bad handler';
});
diff --git a/test/hijack_test.dart b/test/hijack_test.dart
index 69edeb0..4b24ea8 100644
--- a/test/hijack_test.dart
+++ b/test/hijack_test.dart
@@ -15,7 +15,8 @@
throwsStateError);
});
- test('hijacking a hijackable request throws a HijackException and calls '
+ test(
+ 'hijacking a hijackable request throws a HijackException and calls '
'onHijack', () {
var request = new Request('GET', LOCALHOST_URI,
onHijack: expectAsync1((void callback(a, b)) {
@@ -29,11 +30,13 @@
callback(streamController.stream, sinkController);
}));
- expect(() => request.hijack(expectAsync1((channel) {
- expect(channel.stream.first, completion(equals([1, 2, 3])));
- channel.sink.add([4, 5, 6]);
- channel.sink.close();
- })), throwsA(new isInstanceOf<HijackException>()));
+ expect(
+ () => request.hijack(expectAsync1((channel) {
+ expect(channel.stream.first, completion(equals([1, 2, 3])));
+ channel.sink.add([4, 5, 6]);
+ channel.sink.close();
+ })),
+ throwsA(new isInstanceOf<HijackException>()));
});
test('hijacking a hijackable request twice throws a StateError', () {
@@ -54,7 +57,8 @@
expect(() => newRequest.hijack((_) => null), throwsStateError);
});
- test('hijacking a hijackable request throws a HijackException and calls '
+ test(
+ 'hijacking a hijackable request throws a HijackException and calls '
'onHijack', () {
var request = new Request('GET', LOCALHOST_URI,
onHijack: expectAsync1((callback(a, b)) {
@@ -70,14 +74,17 @@
var newRequest = request.change();
- expect(() => newRequest.hijack(expectAsync1((channel) {
- expect(channel.stream.first, completion(equals([1, 2, 3])));
- channel.sink.add([4, 5, 6]);
- channel.sink.close();
- })), throwsA(new isInstanceOf<HijackException>()));
+ expect(
+ () => newRequest.hijack(expectAsync1((channel) {
+ expect(channel.stream.first, completion(equals([1, 2, 3])));
+ channel.sink.add([4, 5, 6]);
+ channel.sink.close();
+ })),
+ throwsA(new isInstanceOf<HijackException>()));
});
- test('hijacking the original request after calling change throws a '
+ test(
+ 'hijacking the original request after calling change throws a '
'StateError', () {
// Assert that the [onHijack] callback is only called once.
var request = new Request('GET', LOCALHOST_URI,
diff --git a/test/log_middleware_test.dart b/test/log_middleware_test.dart
index dd81e6b..641af1f 100644
--- a/test/log_middleware_test.dart
+++ b/test/log_middleware_test.dart
@@ -43,8 +43,8 @@
});
test('logs a request with an asynchronous error response', () {
- var handler = const Pipeline()
- .addMiddleware(logRequests(logger: (msg, isError) {
+ var handler =
+ const Pipeline().addMiddleware(logRequests(logger: (msg, isError) {
expect(gotLog, isFalse);
gotLog = true;
expect(isError, isTrue);
@@ -62,8 +62,10 @@
.addMiddleware(logRequests(logger: logger))
.addHandler((request) => throw const HijackException());
- expect(makeSimpleRequest(handler).whenComplete(() {
- expect(gotLog, isFalse);
- }), throwsA(new isInstanceOf<HijackException>()));
+ expect(
+ makeSimpleRequest(handler).whenComplete(() {
+ expect(gotLog, isFalse);
+ }),
+ throwsA(new isInstanceOf<HijackException>()));
});
}
diff --git a/test/message_change_test.dart b/test/message_change_test.dart
index 638f9dc..fec0d9b 100644
--- a/test/message_change_test.dart
+++ b/test/message_change_test.dart
@@ -15,8 +15,8 @@
void main() {
group('Request', () {
_testChange(({body, headers, context}) {
- return new Request('GET', LOCALHOST_URI, body: body,
- headers: headers, context: context);
+ return new Request('GET', LOCALHOST_URI,
+ body: body, headers: headers, context: context);
});
});
@@ -29,8 +29,9 @@
/// Shared test method used by [Request] and [Response] tests to validate
/// the behavior of `change` with different `headers` and `context` values.
-void _testChange(Message factory(
- {body, Map<String, String> headers, Map<String, Object> context})) {
+void _testChange(
+ Message factory(
+ {body, Map<String, String> headers, Map<String, Object> context})) {
group('body', () {
test('with String', () async {
var request = factory(body: 'Hello, world');
@@ -45,7 +46,7 @@
var request = factory(body: 'Hello, world');
var copy = request.change(
body: new Stream.fromIterable(['Goodbye, world'])
- .transform(UTF8.encoder));
+ .transform(UTF8.encoder));
var newBody = await copy.readAsString();
@@ -71,11 +72,8 @@
var request = factory(headers: {'test': 'test value'});
var copy = request.change(headers: {'test2': 'test2 value'});
- expect(copy.headers, {
- 'test': 'test value',
- 'test2': 'test2 value',
- 'content-length': '0'
- });
+ expect(copy.headers,
+ {'test': 'test value', 'test2': 'test2 value', 'content-length': '0'});
});
test('existing header values are overwritten', () {
diff --git a/test/message_test.dart b/test/message_test.dart
index efd5798..ac120ce 100644
--- a/test/message_test.dart
+++ b/test/message_test.dart
@@ -15,14 +15,17 @@
Encoding encoding)
: super(body, headers: headers, context: context, encoding: encoding);
- Message change({Map<String, String> headers, Map<String, Object> context,
- body}) {
+ Message change(
+ {Map<String, String> headers, Map<String, Object> context, body}) {
throw new UnimplementedError();
}
}
-Message _createMessage({Map<String, String> headers,
- Map<String, Object> context, body, Encoding encoding}) {
+Message _createMessage(
+ {Map<String, String> headers,
+ Map<String, Object> context,
+ body,
+ Encoding encoding}) {
return new _TestMessage(headers, context, body, encoding);
}
@@ -91,21 +94,28 @@
});
test("defaults to UTF-8", () {
- var request = _createMessage(body: new Stream.fromIterable([[195, 168]]));
+ var request = _createMessage(
+ body: new Stream.fromIterable([
+ [195, 168]
+ ]));
expect(request.readAsString(), completion(equals("è")));
});
test("the content-type header overrides the default", () {
var request = _createMessage(
headers: {'content-type': 'text/plain; charset=iso-8859-1'},
- body: new Stream.fromIterable([[195, 168]]));
+ body: new Stream.fromIterable([
+ [195, 168]
+ ]));
expect(request.readAsString(), completion(equals("è")));
});
test("an explicit encoding overrides the content-type header", () {
var request = _createMessage(
headers: {'content-type': 'text/plain; charset=iso-8859-1'},
- body: new Stream.fromIterable([[195, 168]]));
+ body: new Stream.fromIterable([
+ [195, 168]
+ ]));
expect(request.readAsString(LATIN1), completion(equals("è")));
});
});
@@ -132,8 +142,7 @@
test("supports a List<int> body", () {
var request = _createMessage(body: HELLO_BYTES);
- expect(request.read().toList(),
- completion(equals([HELLO_BYTES])));
+ expect(request.read().toList(), completion(equals([HELLO_BYTES])));
});
test("throws when calling read()/readAsString() multiple times", () {
@@ -193,8 +202,8 @@
});
test("real body length takes precedence over content-length header", () {
- var request = _createMessage(
- body: [1, 2, 3], headers: {'content-length': '42'});
+ var request =
+ _createMessage(body: [1, 2, 3], headers: {'content-length': '42'});
expect(request.contentLength, 3);
});
@@ -228,10 +237,11 @@
});
test("doesn't include parameters", () {
- expect(_createMessage(
- headers: {
- 'content-type': 'text/plain; foo=bar; bar=baz'
- }).mimeType, equals('text/plain'));
+ expect(
+ _createMessage(
+ headers: {'content-type': 'text/plain; foo=bar; bar=baz'})
+ .mimeType,
+ equals('text/plain'));
});
});
@@ -246,34 +256,43 @@
});
test("is null with an unrecognized charset parameter", () {
- expect(_createMessage(
+ expect(
+ _createMessage(
headers: {'content-type': 'text/plain; charset=fblthp'}).encoding,
isNull);
});
test("comes from the content-type charset parameter", () {
- expect(_createMessage(
- headers: {
- 'content-type': 'text/plain; charset=iso-8859-1'
- }).encoding, equals(LATIN1));
+ expect(
+ _createMessage(
+ headers: {'content-type': 'text/plain; charset=iso-8859-1'})
+ .encoding,
+ equals(LATIN1));
});
test("comes from the content-type charset parameter with a different case",
() {
- expect(_createMessage(
- headers: {
- 'Content-Type': 'text/plain; charset=iso-8859-1'
- }).encoding, equals(LATIN1));
+ expect(
+ _createMessage(
+ headers: {'Content-Type': 'text/plain; charset=iso-8859-1'})
+ .encoding,
+ equals(LATIN1));
});
test("defaults to encoding a String as UTF-8", () {
- expect(_createMessage(body: "è").read().toList(),
- completion(equals([[195, 168]])));
+ expect(
+ _createMessage(body: "è").read().toList(),
+ completion(equals([
+ [195, 168]
+ ])));
});
test("uses the explicit encoding if available", () {
- expect(_createMessage(body: "è", encoding: LATIN1).read().toList(),
- completion(equals([[232]])));
+ expect(
+ _createMessage(body: "è", encoding: LATIN1).read().toList(),
+ completion(equals([
+ [232]
+ ])));
});
test("adds an explicit encoding to the content-type", () {
@@ -291,11 +310,14 @@
containsPair('Content-Type', 'text/plain; charset=iso-8859-1'));
});
- test("sets an absent content-type to application/octet-stream in order to "
+ test(
+ "sets an absent content-type to application/octet-stream in order to "
"set the charset", () {
var request = _createMessage(body: "è", encoding: LATIN1);
- expect(request.headers, containsPair(
- 'content-type', 'application/octet-stream; charset=iso-8859-1'));
+ expect(
+ request.headers,
+ containsPair(
+ 'content-type', 'application/octet-stream; charset=iso-8859-1'));
});
test("overwrites an existing charset if given an explicit encoding", () {
diff --git a/test/request_test.dart b/test/request_test.dart
index 6701355..2d371fc 100644
--- a/test/request_test.dart
+++ b/test/request_test.dart
@@ -49,8 +49,7 @@
});
test("may be empty", () {
- var request = new Request(
- 'GET', Uri.parse("http://localhost/foo/bar"),
+ var request = new Request('GET', Uri.parse("http://localhost/foo/bar"),
url: Uri.parse(""));
expect(request.url, equals(Uri.parse("")));
});
@@ -168,8 +167,7 @@
test('must be the requestedUri path if url is empty', () {
expect(() {
new Request('GET', Uri.parse('http://localhost/test'),
- handlerPath: '/',
- url: Uri.parse(''));
+ handlerPath: '/', url: Uri.parse(''));
}, throwsArgumentError);
});
});
diff --git a/test/response_test.dart b/test/response_test.dart
index 7b22a21..17e73e3 100644
--- a/test/response_test.dart
+++ b/test/response_test.dart
@@ -38,8 +38,7 @@
});
test('preserves content-type parameters', () {
- var response = new Response.internalServerError(
- headers: {
+ var response = new Response.internalServerError(headers: {
'content-type': 'application/octet-stream; param=whatever'
});
expect(response.headers,
@@ -65,10 +64,10 @@
});
test("comes from the Expires header", () {
- expect(new Response.ok("okay!",
- headers: {
- 'expires': 'Sun, 06 Nov 1994 08:49:37 GMT'
- }).expires, equals(DateTime.parse("1994-11-06 08:49:37z")));
+ expect(
+ new Response.ok("okay!",
+ headers: {'expires': 'Sun, 06 Nov 1994 08:49:37 GMT'}).expires,
+ equals(DateTime.parse("1994-11-06 08:49:37z")));
});
});
@@ -78,10 +77,11 @@
});
test("comes from the Last-Modified header", () {
- expect(new Response.ok("okay!",
- headers: {
- 'last-modified': 'Sun, 06 Nov 1994 08:49:37 GMT'
- }).lastModified, equals(DateTime.parse("1994-11-06 08:49:37z")));
+ expect(
+ new Response.ok("okay!",
+ headers: {'last-modified': 'Sun, 06 Nov 1994 08:49:37 GMT'})
+ .lastModified,
+ equals(DateTime.parse("1994-11-06 08:49:37z")));
});
});
@@ -111,7 +111,6 @@
});
});
-
test("allows the original response to be read", () {
var response = new Response.ok(null);
var changed = response.change();
diff --git a/test/shelf_io_test.dart b/test/shelf_io_test.dart
index 7c13692..3d4c606 100644
--- a/test/shelf_io_test.dart
+++ b/test/shelf_io_test.dart
@@ -95,8 +95,8 @@
return syncHandler(request);
});
- return schedule(() => http.get('http://localhost:$_serverPort$path')).then(
- (response) {
+ return schedule(() => http.get('http://localhost:$_serverPort$path'))
+ .then((response) {
expect(response.statusCode, HttpStatus.OK);
expect(response.body, 'Hello from /foo/bar');
});
@@ -107,7 +107,11 @@
expect(request.contentLength, isNull);
expect(request.method, 'POST');
expect(request.headers, isNot(contains(HttpHeaders.TRANSFER_ENCODING)));
- expect(request.read().toList(), completion(equals([[1, 2, 3, 4]])));
+ expect(
+ request.read().toList(),
+ completion(equals([
+ [1, 2, 3, 4]
+ ])));
return new Response.ok(null);
}));
@@ -213,10 +217,11 @@
expect(stream.first, completion(equals("Hello".codeUnits)));
sink.add(("HTTP/1.1 404 Not Found\r\n"
- "Date: Mon, 23 May 2005 22:38:34 GMT\r\n"
- "Content-Length: 13\r\n"
- "\r\n"
- "Hello, world!").codeUnits);
+ "Date: Mon, 23 May 2005 22:38:34 GMT\r\n"
+ "Content-Length: 13\r\n"
+ "\r\n"
+ "Hello, world!")
+ .codeUnits);
sink.close();
}));
});
@@ -359,7 +364,9 @@
group('is added when the transfer-encoding header is', () {
test('unset', () {
_scheduleServer((request) {
- return new Response.ok(new Stream.fromIterable([[1, 2, 3, 4]]));
+ return new Response.ok(new Stream.fromIterable([
+ [1, 2, 3, 4]
+ ]));
});
return _scheduleGet().then((response) {
@@ -371,7 +378,10 @@
test('"identity"', () {
_scheduleServer((request) {
- return new Response.ok(new Stream.fromIterable([[1, 2, 3, 4]]),
+ return new Response.ok(
+ new Stream.fromIterable([
+ [1, 2, 3, 4]
+ ]),
headers: {HttpHeaders.TRANSFER_ENCODING: 'identity'});
});
@@ -400,13 +410,16 @@
group('is not added when', () {
test('content-length is set', () {
_scheduleServer((request) {
- return new Response.ok(new Stream.fromIterable([[1, 2, 3, 4]]),
+ return new Response.ok(
+ new Stream.fromIterable([
+ [1, 2, 3, 4]
+ ]),
headers: {HttpHeaders.CONTENT_LENGTH: '4'});
});
return _scheduleGet().then((response) {
- expect(response.headers,
- isNot(contains(HttpHeaders.TRANSFER_ENCODING)));
+ expect(
+ response.headers, isNot(contains(HttpHeaders.TRANSFER_ENCODING)));
expect(response.bodyBytes, equals([1, 2, 3, 4]));
});
});
@@ -417,8 +430,8 @@
});
return _scheduleGet().then((response) {
- expect(response.headers,
- isNot(contains(HttpHeaders.TRANSFER_ENCODING)));
+ expect(
+ response.headers, isNot(contains(HttpHeaders.TRANSFER_ENCODING)));
expect(response.body, isEmpty);
});
});
@@ -429,8 +442,8 @@
});
return _scheduleGet().then((response) {
- expect(response.headers,
- isNot(contains(HttpHeaders.TRANSFER_ENCODING)));
+ expect(
+ response.headers, isNot(contains(HttpHeaders.TRANSFER_ENCODING)));
expect(response.body, isEmpty);
});
});
@@ -441,8 +454,8 @@
});
return _scheduleGet().then((response) {
- expect(response.headers,
- isNot(contains(HttpHeaders.TRANSFER_ENCODING)));
+ expect(
+ response.headers, isNot(contains(HttpHeaders.TRANSFER_ENCODING)));
expect(response.body, isEmpty);
});
});
@@ -459,8 +472,8 @@
});
schedule(() {
- var request = new http.Request(
- "GET", Uri.parse('http://localhost:$_serverPort/'));
+ var request =
+ new http.Request("GET", Uri.parse('http://localhost:$_serverPort/'));
return request.send().then((response) {
var stream = new ScheduledStream(UTF8.decoder.bind(response.stream));
@@ -483,13 +496,13 @@
Future _scheduleServer(Handler handler) {
return schedule(() => shelf_io.serve(handler, 'localhost', 0).then((server) {
- currentSchedule.onComplete.schedule(() {
- _serverPort = null;
- return server.close(force: true);
- });
+ currentSchedule.onComplete.schedule(() {
+ _serverPort = null;
+ return server.close(force: true);
+ });
- _serverPort = server.port;
- }));
+ _serverPort = server.port;
+ }));
}
Future<http.Response> _scheduleGet({Map<String, String> headers}) {