Enable and fix lints, tweak SDK range and description (#272)
diff --git a/.travis.yml b/.travis.yml
index 79a9c47..a7a9ec1 100644
--- a/.travis.yml
+++ b/.travis.yml
@@ -9,7 +9,13 @@
# No parallelism on Firefox (-j 1)
# Causes flakiness – need to investigate
- test: --platform firefox -j 1
- - dartanalyzer
+ - dartanalyzer: --fatal-infos --fatal-warnings .
+
+matrix:
+ include:
+ # Only validate formatting using the dev release
+ - dart: dev
+ dart_task: dartfmt
# Only building master means that we don't run two builds for each pull request.
branches:
diff --git a/analysis_options.yaml b/analysis_options.yaml
index 108d105..9da47a9 100644
--- a/analysis_options.yaml
+++ b/analysis_options.yaml
@@ -1 +1,6 @@
include: package:pedantic/analysis_options.yaml
+linter:
+ rules:
+ - prefer_generic_function_type_aliases
+ - unnecessary_const
+ - unnecessary_new
diff --git a/lib/http.dart b/lib/http.dart
index e682ed1..bb4dd73 100644
--- a/lib/http.dart
+++ b/lib/http.dart
@@ -161,7 +161,7 @@
_withClient((client) => client.readBytes(url, headers: headers));
Future<T> _withClient<T>(Future<T> fn(Client client)) async {
- var client = new Client();
+ var client = Client();
try {
return await fn(client);
} finally {
diff --git a/lib/src/base_client.dart b/lib/src/base_client.dart
index 2a1f246..ff5b23d 100644
--- a/lib/src/base_client.dart
+++ b/lib/src/base_client.dart
@@ -150,7 +150,7 @@
String method, url, Map<String, String> headers,
[body, Encoding encoding]) async {
if (url is String) url = Uri.parse(url);
- var request = new Request(method, url);
+ var request = Request(method, url);
if (headers != null) request.headers.addAll(headers);
if (encoding != null) request.encoding = encoding;
@@ -162,7 +162,7 @@
} else if (body is Map) {
request.bodyFields = body.cast<String, String>();
} else {
- throw new ArgumentError('Invalid request body "$body".');
+ throw ArgumentError('Invalid request body "$body".');
}
}
@@ -177,7 +177,7 @@
message = "$message: ${response.reasonPhrase}";
}
if (url is String) url = Uri.parse(url);
- throw new ClientException("$message.", url);
+ throw ClientException("$message.", url);
}
/// Closes the client and cleans up any resources associated with it. It's
diff --git a/lib/src/base_request.dart b/lib/src/base_request.dart
index e03d9e8..0492724 100644
--- a/lib/src/base_request.dart
+++ b/lib/src/base_request.dart
@@ -34,7 +34,7 @@
set contentLength(int value) {
if (value != null && value < 0) {
- throw new ArgumentError("Invalid content length $value.");
+ throw ArgumentError("Invalid content length $value.");
}
_checkFinalized();
_contentLength = value;
@@ -83,7 +83,7 @@
/// Creates a new HTTP request.
BaseRequest(this.method, this.url)
- : headers = new LinkedHashMap(
+ : headers = LinkedHashMap(
equals: (key1, key2) => key1.toLowerCase() == key2.toLowerCase(),
hashCode: (key) => key.toLowerCase().hashCode);
@@ -98,7 +98,7 @@
/// change after the request headers are sent.
ByteStream finalize() {
// TODO(nweiz): freeze headers
- if (finalized) throw new StateError("Can't finalize a finalized Request.");
+ if (finalized) throw StateError("Can't finalize a finalized Request.");
_finalized = true;
return null;
}
@@ -110,12 +110,12 @@
/// the same server, you should use a single [Client] for all of those
/// requests.
Future<StreamedResponse> send() async {
- var client = new Client();
+ var client = Client();
try {
var response = await client.send(this);
var stream = onDone(response.stream, client.close);
- return new StreamedResponse(new ByteStream(stream), response.statusCode,
+ return StreamedResponse(ByteStream(stream), response.statusCode,
contentLength: response.contentLength,
request: response.request,
headers: response.headers,
@@ -131,7 +131,7 @@
// Throws an error if this request has been finalized.
void _checkFinalized() {
if (!finalized) return;
- throw new StateError("Can't modify a finalized Request.");
+ throw StateError("Can't modify a finalized Request.");
}
String toString() => "$method $url";
diff --git a/lib/src/base_response.dart b/lib/src/base_response.dart
index 46f72d5..7c44eea 100644
--- a/lib/src/base_response.dart
+++ b/lib/src/base_response.dart
@@ -44,9 +44,9 @@
this.persistentConnection = true,
this.reasonPhrase}) {
if (statusCode < 100) {
- throw new ArgumentError("Invalid status code $statusCode.");
+ throw ArgumentError("Invalid status code $statusCode.");
} else if (contentLength != null && contentLength < 0) {
- throw new ArgumentError("Invalid content length $contentLength.");
+ throw ArgumentError("Invalid content length $contentLength.");
}
}
}
diff --git a/lib/src/boundary_characters.dart b/lib/src/boundary_characters.dart
index b9b7969..5f7ab38 100644
--- a/lib/src/boundary_characters.dart
+++ b/lib/src/boundary_characters.dart
@@ -9,7 +9,7 @@
///
/// [RFC 2046]: http://tools.ietf.org/html/rfc2046#section-5.1.1.
/// [RFC 1521]: https://tools.ietf.org/html/rfc1521#section-4
-const List<int> BOUNDARY_CHARACTERS = const <int>[
+const List<int> BOUNDARY_CHARACTERS = <int>[
43,
95,
45,
diff --git a/lib/src/browser_client.dart b/lib/src/browser_client.dart
index 08225c2..d64d7e6 100644
--- a/lib/src/browser_client.dart
+++ b/lib/src/browser_client.dart
@@ -29,7 +29,7 @@
/// The currently active XHRs.
///
/// These are aborted if the client is closed.
- final _xhrs = new Set<HttpRequest>();
+ final _xhrs = Set<HttpRequest>();
/// Creates a new HTTP client.
BrowserClient();
@@ -43,24 +43,24 @@
/// Sends an HTTP request and asynchronously returns the response.
Future<StreamedResponse> send(BaseRequest request) async {
var bytes = await request.finalize().toBytes();
- var xhr = new HttpRequest();
+ var xhr = HttpRequest();
_xhrs.add(xhr);
_openHttpRequest(xhr, request.method, request.url.toString(), asynch: true);
xhr.responseType = 'blob';
xhr.withCredentials = withCredentials;
request.headers.forEach(xhr.setRequestHeader);
- var completer = new Completer<StreamedResponse>();
+ var completer = Completer<StreamedResponse>();
unawaited(xhr.onLoad.first.then((_) {
// TODO(nweiz): Set the response type to "arraybuffer" when issue 18542
// is fixed.
- var blob = xhr.response == null ? new Blob([]) : xhr.response;
- var reader = new FileReader();
+ var blob = xhr.response == null ? Blob([]) : xhr.response;
+ var reader = FileReader();
reader.onLoad.first.then((_) {
var body = reader.result as Uint8List;
- completer.complete(new StreamedResponse(
- new ByteStream.fromBytes(body), xhr.status,
+ completer.complete(StreamedResponse(
+ ByteStream.fromBytes(body), xhr.status,
contentLength: body.length,
request: request,
headers: xhr.responseHeaders,
@@ -69,8 +69,7 @@
reader.onError.first.then((error) {
completer.completeError(
- new ClientException(error.toString(), request.url),
- StackTrace.current);
+ ClientException(error.toString(), request.url), StackTrace.current);
});
reader.readAsArrayBuffer(blob);
@@ -80,7 +79,7 @@
// Unfortunately, the underlying XMLHttpRequest API doesn't expose any
// specific information about the error itself.
completer.completeError(
- new ClientException("XMLHttpRequest error.", request.url),
+ ClientException("XMLHttpRequest error.", request.url),
StackTrace.current);
}));
diff --git a/lib/src/byte_stream.dart b/lib/src/byte_stream.dart
index 2fbd2a3..0191a05 100644
--- a/lib/src/byte_stream.dart
+++ b/lib/src/byte_stream.dart
@@ -13,13 +13,13 @@
/// Returns a single-subscription byte stream that will emit the given bytes
/// in a single chunk.
factory ByteStream.fromBytes(List<int> bytes) =>
- new ByteStream(new Stream.fromIterable([bytes]));
+ ByteStream(Stream.fromIterable([bytes]));
/// Collects the data of this stream in a [Uint8List].
Future<Uint8List> toBytes() {
- var completer = new Completer<Uint8List>();
- var sink = new ByteConversionSink.withCallback(
- (bytes) => completer.complete(new Uint8List.fromList(bytes)));
+ var completer = Completer<Uint8List>();
+ var sink = ByteConversionSink.withCallback(
+ (bytes) => completer.complete(Uint8List.fromList(bytes)));
listen(sink.add,
onError: completer.completeError,
onDone: sink.close,
diff --git a/lib/src/io_client.dart b/lib/src/io_client.dart
index 53054f8..c5cdbba 100644
--- a/lib/src/io_client.dart
+++ b/lib/src/io_client.dart
@@ -23,7 +23,7 @@
HttpClient _inner;
/// Creates a new HTTP client.
- IOClient([HttpClient inner]) : _inner = inner ?? new HttpClient();
+ IOClient([HttpClient inner]) : _inner = inner ?? HttpClient();
/// Sends an HTTP request and asynchronously returns the response.
Future<StreamedResponse> send(BaseRequest request) async {
@@ -49,9 +49,9 @@
headers[key] = values.join(',');
});
- return new StreamedResponse(
+ return StreamedResponse(
DelegatingStream.typed<List<int>>(response).handleError(
- (error) => throw new ClientException(error.message, error.uri),
+ (error) => throw ClientException(error.message, error.uri),
test: (error) => error is HttpException),
response.statusCode,
contentLength:
@@ -62,7 +62,7 @@
persistentConnection: response.persistentConnection,
reasonPhrase: response.reasonPhrase);
} on HttpException catch (error) {
- throw new ClientException(error.message, error.uri);
+ throw ClientException(error.message, error.uri);
}
}
diff --git a/lib/src/mock_client.dart b/lib/src/mock_client.dart
index 039390b..2051911 100644
--- a/lib/src/mock_client.dart
+++ b/lib/src/mock_client.dart
@@ -30,7 +30,7 @@
MockClient(MockClientHandler fn)
: this._((baseRequest, bodyStream) {
return bodyStream.toBytes().then((bodyBytes) {
- var request = new Request(baseRequest.method, baseRequest.url)
+ var request = Request(baseRequest.method, baseRequest.url)
..persistentConnection = baseRequest.persistentConnection
..followRedirects = baseRequest.followRedirects
..maxRedirects = baseRequest.maxRedirects
@@ -40,9 +40,8 @@
return fn(request);
}).then((response) {
- return new StreamedResponse(
- new ByteStream.fromBytes(response.bodyBytes),
- response.statusCode,
+ return StreamedResponse(
+ ByteStream.fromBytes(response.bodyBytes), response.statusCode,
contentLength: response.contentLength,
request: baseRequest,
headers: response.headers,
@@ -57,7 +56,7 @@
MockClient.streaming(MockClientStreamHandler fn)
: this._((request, bodyStream) {
return fn(request, bodyStream).then((response) {
- return new StreamedResponse(response.stream, response.statusCode,
+ return StreamedResponse(response.stream, response.statusCode,
contentLength: response.contentLength,
request: request,
headers: response.headers,
@@ -76,9 +75,9 @@
/// A handler function that receives [StreamedRequest]s and sends
/// [StreamedResponse]s. Note that [request] will be finalized.
-typedef Future<StreamedResponse> MockClientStreamHandler(
+typedef MockClientStreamHandler = Future<StreamedResponse> Function(
BaseRequest request, ByteStream bodyStream);
/// A handler function that receives [Request]s and sends [Response]s. Note that
/// [request] will be finalized.
-typedef Future<Response> MockClientHandler(Request request);
+typedef MockClientHandler = Future<Response> Function(Request request);
diff --git a/lib/src/multipart_file.dart b/lib/src/multipart_file.dart
index a173f67..a3ca7fa 100644
--- a/lib/src/multipart_file.dart
+++ b/lib/src/multipart_file.dart
@@ -49,7 +49,7 @@
: this._stream = toByteStream(stream),
this.contentType = contentType != null
? contentType
- : new MediaType("application", "octet-stream");
+ : MediaType("application", "octet-stream");
/// Creates a new [MultipartFile] from a byte array.
///
@@ -57,8 +57,8 @@
/// future may be inferred from [filename].
factory MultipartFile.fromBytes(String field, List<int> value,
{String filename, MediaType contentType}) {
- var stream = new ByteStream.fromBytes(value);
- return new MultipartFile(field, stream, value.length,
+ var stream = ByteStream.fromBytes(value);
+ return MultipartFile(field, stream, value.length,
filename: filename, contentType: contentType);
}
@@ -71,11 +71,11 @@
factory MultipartFile.fromString(String field, String value,
{String filename, MediaType contentType}) {
contentType =
- contentType == null ? new MediaType("text", "plain") : contentType;
+ contentType == null ? MediaType("text", "plain") : contentType;
var encoding = encodingForCharset(contentType.parameters['charset'], utf8);
contentType = contentType.change(parameters: {'charset': encoding.name});
- return new MultipartFile.fromBytes(field, encoding.encode(value),
+ return MultipartFile.fromBytes(field, encoding.encode(value),
filename: filename, contentType: contentType);
}
@@ -98,7 +98,7 @@
// of the file. The stream may be closed to indicate an empty file.
ByteStream finalize() {
if (isFinalized) {
- throw new StateError("Can't finalize a finalized MultipartFile.");
+ throw StateError("Can't finalize a finalized MultipartFile.");
}
_isFinalized = true;
return _stream;
diff --git a/lib/src/multipart_file_io.dart b/lib/src/multipart_file_io.dart
index c49998a..fb63ab0 100644
--- a/lib/src/multipart_file_io.dart
+++ b/lib/src/multipart_file_io.dart
@@ -15,9 +15,9 @@
Future<MultipartFile> multipartFileFromPath(String field, String filePath,
{String filename, MediaType contentType}) async {
if (filename == null) filename = p.basename(filePath);
- var file = new File(filePath);
+ var file = File(filePath);
var length = await file.length();
- var stream = new ByteStream(DelegatingStream.typed(file.openRead()));
- return new MultipartFile(field, stream, length,
+ var stream = ByteStream(DelegatingStream.typed(file.openRead()));
+ return MultipartFile(field, stream, length,
filename: filename, contentType: contentType);
}
diff --git a/lib/src/multipart_request.dart b/lib/src/multipart_request.dart
index 00f410f..e2a9714 100644
--- a/lib/src/multipart_request.dart
+++ b/lib/src/multipart_request.dart
@@ -12,7 +12,7 @@
import 'multipart_file.dart';
import 'utils.dart';
-final _newlineRegExp = new RegExp(r"\r\n|\r|\n");
+final _newlineRegExp = RegExp(r"\r\n|\r|\n");
/// A `multipart/form-data` request. Such a request has both string [fields],
/// which function as normal form fields, and (potentially streamed) binary
@@ -36,7 +36,7 @@
/// can't be longer than 70.
static const int _BOUNDARY_LENGTH = 70;
- static final Random _random = new Random();
+ static final Random _random = Random();
/// The form fields to send for this request.
final Map<String, String> fields;
@@ -80,7 +80,7 @@
}
set contentLength(int value) {
- throw new UnsupportedError("Cannot set the contentLength property of "
+ throw UnsupportedError("Cannot set the contentLength property of "
"multipart requests.");
}
@@ -92,7 +92,7 @@
headers['content-type'] = 'multipart/form-data; boundary=$boundary';
super.finalize();
- var controller = new StreamController<List<int>>(sync: true);
+ var controller = StreamController<List<int>>(sync: true);
void writeAscii(String string) {
controller.add(utf8.encode(string));
@@ -120,7 +120,7 @@
controller.close();
});
- return new ByteStream(controller.stream);
+ return ByteStream(controller.stream);
}
/// Returns the header string for a field. The return value is guaranteed to
@@ -161,11 +161,11 @@
/// Returns a randomly-generated multipart boundary string
String _boundaryString() {
var prefix = "dart-http-boundary-";
- var list = new List<int>.generate(
+ var list = List<int>.generate(
_BOUNDARY_LENGTH - prefix.length,
(index) =>
BOUNDARY_CHARACTERS[_random.nextInt(BOUNDARY_CHARACTERS.length)],
growable: false);
- return "$prefix${new String.fromCharCodes(list)}";
+ return "$prefix${String.fromCharCodes(list)}";
}
}
diff --git a/lib/src/request.dart b/lib/src/request.dart
index 8c638b1..f18959d 100644
--- a/lib/src/request.dart
+++ b/lib/src/request.dart
@@ -21,7 +21,7 @@
int get contentLength => bodyBytes.length;
set contentLength(int value) {
- throw new UnsupportedError("Cannot set the contentLength property of "
+ throw UnsupportedError("Cannot set the contentLength property of "
"non-streaming Request objects.");
}
@@ -85,7 +85,7 @@
bodyBytes = encoding.encode(value);
var contentType = _contentType;
if (contentType == null) {
- _contentType = new MediaType("text", "plain", {'charset': encoding.name});
+ _contentType = MediaType("text", "plain", {'charset': encoding.name});
} else if (!contentType.parameters.containsKey('charset')) {
_contentType = contentType.change(parameters: {'charset': encoding.name});
}
@@ -109,7 +109,7 @@
var contentType = _contentType;
if (contentType == null ||
contentType.mimeType != "application/x-www-form-urlencoded") {
- throw new StateError('Cannot access the body fields of a Request without '
+ throw StateError('Cannot access the body fields of a Request without '
'content-type "application/x-www-form-urlencoded".');
}
@@ -119,9 +119,9 @@
set bodyFields(Map<String, String> fields) {
var contentType = _contentType;
if (contentType == null) {
- _contentType = new MediaType("application", "x-www-form-urlencoded");
+ _contentType = MediaType("application", "x-www-form-urlencoded");
} else if (contentType.mimeType != "application/x-www-form-urlencoded") {
- throw new StateError('Cannot set the body fields of a Request with '
+ throw StateError('Cannot set the body fields of a Request with '
'content-type "${contentType.mimeType}".');
}
@@ -131,14 +131,14 @@
/// Creates a new HTTP request.
Request(String method, Uri url)
: _defaultEncoding = utf8,
- _bodyBytes = new Uint8List(0),
+ _bodyBytes = Uint8List(0),
super(method, url);
/// Freezes all mutable fields and returns a single-subscription [ByteStream]
/// containing the request body.
ByteStream finalize() {
super.finalize();
- return new ByteStream.fromBytes(bodyBytes);
+ return ByteStream.fromBytes(bodyBytes);
}
/// The `Content-Type` header of the request (if it exists) as a
@@ -146,7 +146,7 @@
MediaType get _contentType {
var contentType = headers['content-type'];
if (contentType == null) return null;
- return new MediaType.parse(contentType);
+ return MediaType.parse(contentType);
}
set _contentType(MediaType value) {
@@ -156,6 +156,6 @@
/// Throw an error if this request has been finalized.
void _checkFinalized() {
if (!finalized) return;
- throw new StateError("Can't modify a finalized Request.");
+ throw StateError("Can't modify a finalized Request.");
}
}
diff --git a/lib/src/response.dart b/lib/src/response.dart
index cb43d80..bdc39d1 100644
--- a/lib/src/response.dart
+++ b/lib/src/response.dart
@@ -60,7 +60,7 @@
/// available from a [StreamedResponse].
static Future<Response> fromStream(StreamedResponse response) {
return response.stream.toBytes().then((body) {
- return new Response.bytes(body, response.statusCode,
+ return Response.bytes(body, response.statusCode,
request: response.request,
headers: response.headers,
isRedirect: response.isRedirect,
@@ -81,6 +81,6 @@
/// Defaults to `application/octet-stream`.
MediaType _contentTypeForHeaders(Map<String, String> headers) {
var contentType = headers['content-type'];
- if (contentType != null) return new MediaType.parse(contentType);
- return new MediaType("application", "octet-stream");
+ if (contentType != null) return MediaType.parse(contentType);
+ return MediaType("application", "octet-stream");
}
diff --git a/lib/src/streamed_request.dart b/lib/src/streamed_request.dart
index 289046a..ba6ebc4 100644
--- a/lib/src/streamed_request.dart
+++ b/lib/src/streamed_request.dart
@@ -28,7 +28,7 @@
/// Creates a new streaming request.
StreamedRequest(String method, Uri url)
- : _controller = new StreamController<List<int>>(sync: true),
+ : _controller = StreamController<List<int>>(sync: true),
super(method, url);
/// Freezes all mutable fields other than [stream] and returns a
@@ -36,6 +36,6 @@
/// [sink].
ByteStream finalize() {
super.finalize();
- return new ByteStream(_controller.stream);
+ return ByteStream(_controller.stream);
}
}
diff --git a/lib/src/utils.dart b/lib/src/utils.dart
index 3f3e318..07c64c3 100644
--- a/lib/src/utils.dart
+++ b/lib/src/utils.dart
@@ -53,12 +53,12 @@
Encoding requiredEncodingForCharset(String charset) {
var encoding = Encoding.getByName(charset);
if (encoding != null) return encoding;
- throw new FormatException('Unsupported encoding "$charset".');
+ throw FormatException('Unsupported encoding "$charset".');
}
/// A regular expression that matches strings that are composed entirely of
/// ASCII-compatible characters.
-final RegExp _ASCII_ONLY = new RegExp(r"^[\x00-\x7F]+$");
+final RegExp _ASCII_ONLY = RegExp(r"^[\x00-\x7F]+$");
/// Returns whether [string] is composed entirely of ASCII-compatible
/// characters.
@@ -71,23 +71,23 @@
if (input is Uint8List) return input;
if (input is TypedData) {
// TODO(nweiz): remove "as" when issue 11080 is fixed.
- return new Uint8List.view((input as TypedData).buffer);
+ return Uint8List.view((input as TypedData).buffer);
}
- return new Uint8List.fromList(input);
+ return Uint8List.fromList(input);
}
/// If [stream] is already a [ByteStream], returns it. Otherwise, wraps it in a
/// [ByteStream].
ByteStream toByteStream(Stream<List<int>> stream) {
if (stream is ByteStream) return stream;
- return new ByteStream(stream);
+ return ByteStream(stream);
}
/// Calls [onDone] once [stream] (a single-subscription [Stream]) is finished.
/// The return value, also a single-subscription [Stream] should be used in
/// place of [stream] after calling this method.
Stream<T> onDone<T>(Stream<T> stream, void onDone()) =>
- stream.transform(new StreamTransformer.fromHandlers(handleDone: (sink) {
+ stream.transform(StreamTransformer.fromHandlers(handleDone: (sink) {
sink.close();
onDone();
}));
@@ -96,7 +96,7 @@
/// Pipes all data and errors from [stream] into [sink]. When [stream] is done,
/// [sink] is closed and the returned [Future] is completed.
Future store(Stream stream, EventSink sink) {
- var completer = new Completer();
+ var completer = Completer();
stream.listen(sink.add, onError: sink.addError, onDone: () {
sink.close();
completer.complete();
@@ -108,7 +108,7 @@
/// [stream] is done. Unlike [store], [sink] remains open after [stream] is
/// done.
Future writeStreamToSink(Stream stream, EventSink sink) {
- var completer = new Completer();
+ var completer = Completer();
stream.listen(sink.add,
onError: sink.addError, onDone: () => completer.complete());
return completer.future;
diff --git a/pubspec.yaml b/pubspec.yaml
index 49acb74..47c3c48 100644
--- a/pubspec.yaml
+++ b/pubspec.yaml
@@ -2,11 +2,10 @@
version: 0.12.0+2
author: "Dart Team <misc@dartlang.org>"
homepage: https://github.com/dart-lang/http
-description: >-
- A composable, cross-platform, Future-based API for making HTTP requests.
+description: A composable, multi-platform, Future-based API for HTTP requests.
environment:
- sdk: ">=2.0.0-dev.61.0 <3.0.0"
+ sdk: ">=2.0.0 <3.0.0"
dependencies:
async: ">=1.10.0 <3.0.0"
diff --git a/test/html/client_test.dart b/test/html/client_test.dart
index 6fb2c62..8fe1c72 100644
--- a/test/html/client_test.dart
+++ b/test/html/client_test.dart
@@ -12,8 +12,8 @@
void main() {
test('#send a StreamedRequest', () {
- var client = new BrowserClient();
- var request = new http.StreamedRequest("POST", echoUrl);
+ var client = BrowserClient();
+ var request = http.StreamedRequest("POST", echoUrl);
expect(
client.send(request).then((response) {
@@ -26,9 +26,9 @@
}, skip: 'Need to fix server tests for browser');
test('#send with an invalid URL', () {
- var client = new BrowserClient();
+ var client = BrowserClient();
var url = Uri.parse('http://http.invalid');
- var request = new http.StreamedRequest("POST", url);
+ var request = http.StreamedRequest("POST", url);
expect(
client.send(request), throwsClientException("XMLHttpRequest error."));
diff --git a/test/html/streamed_request_test.dart b/test/html/streamed_request_test.dart
index 662c3ba..e28b313 100644
--- a/test/html/streamed_request_test.dart
+++ b/test/html/streamed_request_test.dart
@@ -13,23 +13,23 @@
void main() {
group('contentLength', () {
test("works when it's set", () {
- var request = new http.StreamedRequest('POST', echoUrl);
+ var request = http.StreamedRequest('POST', echoUrl);
request.contentLength = 10;
request.sink.add([1, 2, 3, 4, 5, 6, 7, 8, 9, 10]);
request.sink.close();
- return new BrowserClient().send(request).then((response) {
+ return BrowserClient().send(request).then((response) {
expect(response.stream.toBytes(),
completion(equals([1, 2, 3, 4, 5, 6, 7, 8, 9, 10])));
});
});
test("works when it's not set", () {
- var request = new http.StreamedRequest('POST', echoUrl);
+ var request = http.StreamedRequest('POST', echoUrl);
request.sink.add([1, 2, 3, 4, 5, 6, 7, 8, 9, 10]);
request.sink.close();
- return new BrowserClient().send(request).then((response) {
+ return BrowserClient().send(request).then((response) {
expect(response.stream.toBytes(),
completion(equals([1, 2, 3, 4, 5, 6, 7, 8, 9, 10])));
});
diff --git a/test/io/client_test.dart b/test/io/client_test.dart
index 04fca5c..0301445 100644
--- a/test/io/client_test.dart
+++ b/test/io/client_test.dart
@@ -18,8 +18,8 @@
test('#send a StreamedRequest', () {
expect(
startServer().then((_) {
- var client = new http.Client();
- var request = new http.StreamedRequest("POST", serverUrl);
+ var client = http.Client();
+ var request = http.StreamedRequest("POST", serverUrl);
request.headers[HttpHeaders.contentTypeHeader] =
'application/json; charset=utf-8';
request.headers[HttpHeaders.userAgentHeader] = 'Dart';
@@ -56,9 +56,9 @@
test('#send a StreamedRequest with a custom client', () {
expect(
startServer().then((_) {
- var ioClient = new HttpClient();
- var client = new http_io.IOClient(ioClient);
- var request = new http.StreamedRequest("POST", serverUrl);
+ var ioClient = HttpClient();
+ var client = http_io.IOClient(ioClient);
+ var request = http.StreamedRequest("POST", serverUrl);
request.headers[HttpHeaders.contentTypeHeader] =
'application/json; charset=utf-8';
request.headers[HttpHeaders.userAgentHeader] = 'Dart';
@@ -95,9 +95,9 @@
test('#send with an invalid URL', () {
expect(
startServer().then((_) {
- var client = new http.Client();
+ var client = http.Client();
var url = Uri.parse('http://http.invalid');
- var request = new http.StreamedRequest("POST", url);
+ var request = http.StreamedRequest("POST", url);
request.headers[HttpHeaders.contentTypeHeader] =
'application/json; charset=utf-8';
diff --git a/test/io/http_test.dart b/test/io/http_test.dart
index 9eab1a7..41656a4 100644
--- a/test/io/http_test.dart
+++ b/test/io/http_test.dart
@@ -538,7 +538,7 @@
'X-Random-Header': 'Value',
'X-Other-Header': 'Other Value',
'User-Agent': 'Dart'
- }).then((bytes) => new String.fromCharCodes(bytes));
+ }).then((bytes) => String.fromCharCodes(bytes));
expect(
future,
diff --git a/test/io/multipart_test.dart b/test/io/multipart_test.dart
index 58dbe36..eb42f00 100644
--- a/test/io/multipart_test.dart
+++ b/test/io/multipart_test.dart
@@ -23,12 +23,12 @@
test('with a file from disk', () {
expect(
- new Future.sync(() {
+ Future.sync(() {
var filePath = path.join(tempDir.path, 'test-file');
- new File(filePath).writeAsStringSync('hello');
+ File(filePath).writeAsStringSync('hello');
return http.MultipartFile.fromPath('file', filePath);
}).then((file) {
- var request = new http.MultipartRequest('POST', dummyUrl);
+ var request = http.MultipartRequest('POST', dummyUrl);
request.files.add(file);
expect(request, bodyMatches('''
diff --git a/test/io/request_test.dart b/test/io/request_test.dart
index 3b2d7e0..bdae677 100644
--- a/test/io/request_test.dart
+++ b/test/io/request_test.dart
@@ -13,7 +13,7 @@
test('.send', () {
expect(
startServer().then((_) {
- var request = new http.Request('POST', serverUrl);
+ var request = http.Request('POST', serverUrl);
request.body = "hello";
request.headers['User-Agent'] = 'Dart';
@@ -40,7 +40,7 @@
test('#followRedirects', () {
expect(
startServer().then((_) {
- var request = new http.Request('POST', serverUrl.resolve('/redirect'))
+ var request = http.Request('POST', serverUrl.resolve('/redirect'))
..followRedirects = false;
var future = request.send().then((response) {
expect(response.statusCode, equals(302));
@@ -55,7 +55,7 @@
test('#maxRedirects', () {
expect(
startServer().then((_) {
- var request = new http.Request('POST', serverUrl.resolve('/loop?1'))
+ var request = http.Request('POST', serverUrl.resolve('/loop?1'))
..maxRedirects = 2;
var future = request.send().catchError((error) {
expect(error, isRedirectLimitExceededException);
diff --git a/test/io/streamed_request_test.dart b/test/io/streamed_request_test.dart
index 6609080..2333726 100644
--- a/test/io/streamed_request_test.dart
+++ b/test/io/streamed_request_test.dart
@@ -15,7 +15,7 @@
group('contentLength', () {
test('controls the Content-Length header', () {
return startServer().then((_) {
- var request = new http.StreamedRequest('POST', serverUrl);
+ var request = http.StreamedRequest('POST', serverUrl);
request.contentLength = 10;
request.sink.add([1, 2, 3, 4, 5, 6, 7, 8, 9, 10]);
request.sink.close();
@@ -31,7 +31,7 @@
test('defaults to sending no Content-Length', () {
return startServer().then((_) {
- var request = new http.StreamedRequest('POST', serverUrl);
+ var request = http.StreamedRequest('POST', serverUrl);
request.sink.add([1, 2, 3, 4, 5, 6, 7, 8, 9, 10]);
request.sink.close();
@@ -48,8 +48,8 @@
// Regression test.
test('.send() with a response with no content length', () {
return startServer().then((_) {
- var request = new http.StreamedRequest(
- 'GET', serverUrl.resolve('/no-content-length'));
+ var request =
+ http.StreamedRequest('GET', serverUrl.resolve('/no-content-length'));
request.sink.close();
return request.send();
}).then((response) {
diff --git a/test/io/utils.dart b/test/io/utils.dart
index 56d1b22..50e668b 100644
--- a/test/io/utils.dart
+++ b/test/io/utils.dart
@@ -59,7 +59,7 @@
return;
}
- new ByteStream(request).toBytes().then((requestBodyBytes) {
+ ByteStream(request).toBytes().then((requestBodyBytes) {
var outputEncoding;
var encodingName = request.uri.queryParameters['response-encoding'];
if (encodingName != null) {
@@ -68,8 +68,8 @@
outputEncoding = ascii;
}
- response.headers.contentType = new ContentType("application", "json",
- charset: outputEncoding.name);
+ response.headers.contentType =
+ ContentType("application", "json", charset: outputEncoding.name);
response.headers.set('single', 'value');
var requestBody;
@@ -116,8 +116,7 @@
}
/// A matcher for functions that throw HttpException.
-Matcher get throwsClientException =>
- throwsA(new TypeMatcher<ClientException>());
+Matcher get throwsClientException => throwsA(TypeMatcher<ClientException>());
/// A matcher for RedirectLimitExceededExceptions.
final isRedirectLimitExceededException = const TypeMatcher<RedirectException>()
diff --git a/test/mock_client_test.dart b/test/mock_client_test.dart
index ff0504d..acd1007 100644
--- a/test/mock_client_test.dart
+++ b/test/mock_client_test.dart
@@ -13,9 +13,8 @@
void main() {
test('handles a request', () {
- var client = new MockClient((request) {
- return new Future.value(new http.Response(
- json.encode(request.bodyFields), 200,
+ var client = MockClient((request) {
+ return Future.value(http.Response(json.encode(request.bodyFields), 200,
request: request, headers: {'content-type': 'application/json'}));
});
@@ -28,20 +27,20 @@
});
test('handles a streamed request', () {
- var client = new MockClient.streaming((request, bodyStream) {
+ var client = MockClient.streaming((request, bodyStream) {
return bodyStream.bytesToString().then((bodyString) {
- var controller = new StreamController<List<int>>(sync: true);
- new Future.sync(() {
+ var controller = StreamController<List<int>>(sync: true);
+ Future.sync(() {
controller.add('Request body was "$bodyString"'.codeUnits);
controller.close();
});
- return new http.StreamedResponse(controller.stream, 200);
+ return http.StreamedResponse(controller.stream, 200);
});
});
var uri = Uri.parse("http://example.com/foo");
- var request = new http.Request("POST", uri);
+ var request = http.Request("POST", uri);
request.body = "hello, world";
var future = client
.send(request)
@@ -51,8 +50,8 @@
});
test('handles a request with no body', () {
- var client = new MockClient((request) {
- return new Future.value(new http.Response('you did it', 200));
+ var client = MockClient((request) {
+ return Future.value(http.Response('you did it', 200));
});
expect(client.read("http://example.com/foo"),
diff --git a/test/multipart_test.dart b/test/multipart_test.dart
index 1f67116..8b14197 100644
--- a/test/multipart_test.dart
+++ b/test/multipart_test.dart
@@ -13,27 +13,26 @@
void main() {
test('empty', () {
- var request = new http.MultipartRequest('POST', dummyUrl);
+ var request = http.MultipartRequest('POST', dummyUrl);
expect(request, bodyMatches('''
--{{boundary}}--
'''));
});
test('boundary characters', () {
- var testBoundary = new String.fromCharCodes(BOUNDARY_CHARACTERS);
- var contentType =
- new MediaType.parse('text/plain; boundary=${testBoundary}');
+ var testBoundary = String.fromCharCodes(BOUNDARY_CHARACTERS);
+ var contentType = MediaType.parse('text/plain; boundary=${testBoundary}');
var boundary = contentType.parameters['boundary'];
expect(boundary, testBoundary);
});
test('with fields and files', () {
- var request = new http.MultipartRequest('POST', dummyUrl);
+ var request = http.MultipartRequest('POST', dummyUrl);
request.fields['field1'] = 'value1';
request.fields['field2'] = 'value2';
- request.files.add(new http.MultipartFile.fromString("file1", "contents1",
+ request.files.add(http.MultipartFile.fromString("file1", "contents1",
filename: "filename1.txt"));
- request.files.add(new http.MultipartFile.fromString("file2", "contents2"));
+ request.files.add(http.MultipartFile.fromString("file2", "contents2"));
expect(request, bodyMatches('''
--{{boundary}}
@@ -59,7 +58,7 @@
});
test('with a unicode field name', () {
- var request = new http.MultipartRequest('POST', dummyUrl);
+ var request = http.MultipartRequest('POST', dummyUrl);
request.fields['fïēld'] = 'value';
expect(request, bodyMatches('''
@@ -72,7 +71,7 @@
});
test('with a field name with newlines', () {
- var request = new http.MultipartRequest('POST', dummyUrl);
+ var request = http.MultipartRequest('POST', dummyUrl);
request.fields['foo\nbar\rbaz\r\nbang'] = 'value';
expect(request, bodyMatches('''
@@ -85,7 +84,7 @@
});
test('with a field name with a quote', () {
- var request = new http.MultipartRequest('POST', dummyUrl);
+ var request = http.MultipartRequest('POST', dummyUrl);
request.fields['foo"bar'] = 'value';
expect(request, bodyMatches('''
@@ -98,7 +97,7 @@
});
test('with a unicode field value', () {
- var request = new http.MultipartRequest('POST', dummyUrl);
+ var request = http.MultipartRequest('POST', dummyUrl);
request.fields['field'] = 'vⱥlūe';
expect(request, bodyMatches('''
@@ -113,8 +112,8 @@
});
test('with a unicode filename', () {
- var request = new http.MultipartRequest('POST', dummyUrl);
- request.files.add(new http.MultipartFile.fromString('file', 'contents',
+ var request = http.MultipartRequest('POST', dummyUrl);
+ request.files.add(http.MultipartFile.fromString('file', 'contents',
filename: 'fïlēname.txt'));
expect(request, bodyMatches('''
@@ -128,8 +127,8 @@
});
test('with a filename with newlines', () {
- var request = new http.MultipartRequest('POST', dummyUrl);
- request.files.add(new http.MultipartFile.fromString('file', 'contents',
+ var request = http.MultipartRequest('POST', dummyUrl);
+ request.files.add(http.MultipartFile.fromString('file', 'contents',
filename: 'foo\nbar\rbaz\r\nbang'));
expect(request, bodyMatches('''
@@ -143,9 +142,9 @@
});
test('with a filename with a quote', () {
- var request = new http.MultipartRequest('POST', dummyUrl);
- request.files.add(new http.MultipartFile.fromString('file', 'contents',
- filename: 'foo"bar'));
+ var request = http.MultipartRequest('POST', dummyUrl);
+ request.files.add(
+ http.MultipartFile.fromString('file', 'contents', filename: 'foo"bar'));
expect(request, bodyMatches('''
--{{boundary}}
@@ -158,9 +157,9 @@
});
test('with a string file with a content-type but no charset', () {
- var request = new http.MultipartRequest('POST', dummyUrl);
- var file = new http.MultipartFile.fromString('file', '{"hello": "world"}',
- contentType: new MediaType('application', 'json'));
+ var request = http.MultipartRequest('POST', dummyUrl);
+ var file = http.MultipartFile.fromString('file', '{"hello": "world"}',
+ contentType: MediaType('application', 'json'));
request.files.add(file);
expect(request, bodyMatches('''
@@ -174,10 +173,10 @@
});
test('with a file with a iso-8859-1 body', () {
- var request = new http.MultipartRequest('POST', dummyUrl);
+ var request = http.MultipartRequest('POST', dummyUrl);
// "Ã¥" encoded as ISO-8859-1 and then read as UTF-8 results in "å".
- var file = new http.MultipartFile.fromString('file', 'non-ascii: "Ã¥"',
- contentType: new MediaType('text', 'plain', {'charset': 'iso-8859-1'}));
+ var file = http.MultipartFile.fromString('file', 'non-ascii: "Ã¥"',
+ contentType: MediaType('text', 'plain', {'charset': 'iso-8859-1'}));
request.files.add(file);
expect(request, bodyMatches('''
@@ -191,9 +190,9 @@
});
test('with a stream file', () {
- var request = new http.MultipartRequest('POST', dummyUrl);
- var controller = new StreamController<List<int>>(sync: true);
- request.files.add(new http.MultipartFile('file', controller.stream, 5));
+ var request = http.MultipartRequest('POST', dummyUrl);
+ var controller = StreamController<List<int>>(sync: true);
+ request.files.add(http.MultipartFile('file', controller.stream, 5));
expect(request, bodyMatches('''
--{{boundary}}
@@ -209,9 +208,9 @@
});
test('with an empty stream file', () {
- var request = new http.MultipartRequest('POST', dummyUrl);
- var controller = new StreamController<List<int>>(sync: true);
- request.files.add(new http.MultipartFile('file', controller.stream, 0));
+ var request = http.MultipartRequest('POST', dummyUrl);
+ var controller = StreamController<List<int>>(sync: true);
+ request.files.add(http.MultipartFile('file', controller.stream, 0));
expect(request, bodyMatches('''
--{{boundary}}
@@ -226,9 +225,8 @@
});
test('with a byte file', () {
- var request = new http.MultipartRequest('POST', dummyUrl);
- var file =
- new http.MultipartFile.fromBytes('file', [104, 101, 108, 108, 111]);
+ var request = http.MultipartRequest('POST', dummyUrl);
+ var file = http.MultipartFile.fromBytes('file', [104, 101, 108, 108, 111]);
request.files.add(file);
expect(request, bodyMatches('''
diff --git a/test/request_test.dart b/test/request_test.dart
index 3fc8967..39243ca 100644
--- a/test/request_test.dart
+++ b/test/request_test.dart
@@ -12,7 +12,7 @@
void main() {
group('#contentLength', () {
test('is computed from bodyBytes', () {
- var request = new http.Request('POST', dummyUrl);
+ var request = http.Request('POST', dummyUrl);
request.bodyBytes = [1, 2, 3, 4, 5];
expect(request.contentLength, equals(5));
request.bodyBytes = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10];
@@ -20,7 +20,7 @@
});
test('is computed from body', () {
- var request = new http.Request('POST', dummyUrl);
+ var request = http.Request('POST', dummyUrl);
request.body = "hello";
expect(request.contentLength, equals(5));
request.body = "hello, world";
@@ -28,32 +28,32 @@
});
test('is not directly mutable', () {
- var request = new http.Request('POST', dummyUrl);
+ var request = http.Request('POST', dummyUrl);
expect(() => request.contentLength = 50, throwsUnsupportedError);
});
});
group('#encoding', () {
test('defaults to utf-8', () {
- var request = new http.Request('POST', dummyUrl);
+ var request = http.Request('POST', dummyUrl);
expect(request.encoding.name, equals(utf8.name));
});
test('can be set', () {
- var request = new http.Request('POST', dummyUrl);
+ var request = http.Request('POST', dummyUrl);
request.encoding = latin1;
expect(request.encoding.name, equals(latin1.name));
});
test('is based on the content-type charset if it exists', () {
- var request = new http.Request('POST', dummyUrl);
+ var request = http.Request('POST', dummyUrl);
request.headers['Content-Type'] = 'text/plain; charset=iso-8859-1';
expect(request.encoding.name, equals(latin1.name));
});
test('remains the default if the content-type charset is set and unset',
() {
- var request = new http.Request('POST', dummyUrl);
+ var request = http.Request('POST', dummyUrl);
request.encoding = latin1;
request.headers['Content-Type'] = 'text/plain; charset=utf-8';
expect(request.encoding.name, equals(utf8.name));
@@ -63,7 +63,7 @@
});
test('throws an error if the content-type charset is unknown', () {
- var request = new http.Request('POST', dummyUrl);
+ var request = http.Request('POST', dummyUrl);
request.headers['Content-Type'] =
'text/plain; charset=not-a-real-charset';
expect(() => request.encoding, throwsFormatException);
@@ -72,18 +72,18 @@
group('#bodyBytes', () {
test('defaults to empty', () {
- var request = new http.Request('POST', dummyUrl);
+ var request = http.Request('POST', dummyUrl);
expect(request.bodyBytes, isEmpty);
});
test('can be set', () {
- var request = new http.Request('POST', dummyUrl);
+ var request = http.Request('POST', dummyUrl);
request.bodyBytes = [104, 101, 108, 108, 111];
expect(request.bodyBytes, equals([104, 101, 108, 108, 111]));
});
test('changes when body changes', () {
- var request = new http.Request('POST', dummyUrl);
+ var request = http.Request('POST', dummyUrl);
request.body = "hello";
expect(request.bodyBytes, equals([104, 101, 108, 108, 111]));
});
@@ -91,31 +91,31 @@
group('#body', () {
test('defaults to empty', () {
- var request = new http.Request('POST', dummyUrl);
+ var request = http.Request('POST', dummyUrl);
expect(request.body, isEmpty);
});
test('can be set', () {
- var request = new http.Request('POST', dummyUrl);
+ var request = http.Request('POST', dummyUrl);
request.body = "hello";
expect(request.body, equals("hello"));
});
test('changes when bodyBytes changes', () {
- var request = new http.Request('POST', dummyUrl);
+ var request = http.Request('POST', dummyUrl);
request.bodyBytes = [104, 101, 108, 108, 111];
expect(request.body, equals("hello"));
});
test('is encoded according to the given encoding', () {
- var request = new http.Request('POST', dummyUrl);
+ var request = http.Request('POST', dummyUrl);
request.encoding = latin1;
request.body = "föøbãr";
expect(request.bodyBytes, equals([102, 246, 248, 98, 227, 114]));
});
test('is decoded according to the given encoding', () {
- var request = new http.Request('POST', dummyUrl);
+ var request = http.Request('POST', dummyUrl);
request.encoding = latin1;
request.bodyBytes = [102, 246, 248, 98, 227, 114];
expect(request.body, equals("föøbãr"));
@@ -124,36 +124,36 @@
group('#bodyFields', () {
test("can't be read without setting the content-type", () {
- var request = new http.Request('POST', dummyUrl);
+ var request = http.Request('POST', dummyUrl);
expect(() => request.bodyFields, throwsStateError);
});
test("can't be read with the wrong content-type", () {
- var request = new http.Request('POST', dummyUrl);
+ var request = http.Request('POST', dummyUrl);
request.headers['Content-Type'] = 'text/plain';
expect(() => request.bodyFields, throwsStateError);
});
test("can't be set with the wrong content-type", () {
- var request = new http.Request('POST', dummyUrl);
+ var request = http.Request('POST', dummyUrl);
request.headers['Content-Type'] = 'text/plain';
expect(() => request.bodyFields = {}, throwsStateError);
});
test('defaults to empty', () {
- var request = new http.Request('POST', dummyUrl);
+ var request = http.Request('POST', dummyUrl);
request.headers['Content-Type'] = 'application/x-www-form-urlencoded';
expect(request.bodyFields, isEmpty);
});
test('can be set with no content-type', () {
- var request = new http.Request('POST', dummyUrl);
+ var request = http.Request('POST', dummyUrl);
request.bodyFields = {'hello': 'world'};
expect(request.bodyFields, equals({'hello': 'world'}));
});
test('changes when body changes', () {
- var request = new http.Request('POST', dummyUrl);
+ var request = http.Request('POST', dummyUrl);
request.headers['Content-Type'] = 'application/x-www-form-urlencoded';
request.body = 'key%201=value&key+2=other%2bvalue';
expect(request.bodyFields,
@@ -161,7 +161,7 @@
});
test('is encoded according to the given encoding', () {
- var request = new http.Request('POST', dummyUrl);
+ var request = http.Request('POST', dummyUrl);
request.headers['Content-Type'] = 'application/x-www-form-urlencoded';
request.encoding = latin1;
request.bodyFields = {"föø": "bãr"};
@@ -169,7 +169,7 @@
});
test('is decoded according to the given encoding', () {
- var request = new http.Request('POST', dummyUrl);
+ var request = http.Request('POST', dummyUrl);
request.headers['Content-Type'] = 'application/x-www-form-urlencoded';
request.encoding = latin1;
request.body = 'f%F6%F8=b%E3r';
@@ -179,18 +179,18 @@
group('content-type header', () {
test('defaults to empty', () {
- var request = new http.Request('POST', dummyUrl);
+ var request = http.Request('POST', dummyUrl);
expect(request.headers['Content-Type'], isNull);
});
test('defaults to empty if only encoding is set', () {
- var request = new http.Request('POST', dummyUrl);
+ var request = http.Request('POST', dummyUrl);
request.encoding = latin1;
expect(request.headers['Content-Type'], isNull);
});
test('name is case insensitive', () {
- var request = new http.Request('POST', dummyUrl);
+ var request = http.Request('POST', dummyUrl);
request.headers['CoNtEnT-tYpE'] = 'application/json';
expect(request.headers, containsPair('content-type', 'application/json'));
});
@@ -198,7 +198,7 @@
test(
'is set to application/x-www-form-urlencoded with charset utf-8 if '
'bodyFields is set', () {
- var request = new http.Request('POST', dummyUrl);
+ var request = http.Request('POST', dummyUrl);
request.bodyFields = {'hello': 'world'};
expect(request.headers['Content-Type'],
equals('application/x-www-form-urlencoded; charset=utf-8'));
@@ -207,7 +207,7 @@
test(
'is set to application/x-www-form-urlencoded with the given charset '
'if bodyFields and encoding are set', () {
- var request = new http.Request('POST', dummyUrl);
+ var request = http.Request('POST', dummyUrl);
request.encoding = latin1;
request.bodyFields = {'hello': 'world'};
expect(request.headers['Content-Type'],
@@ -217,7 +217,7 @@
test(
'is set to text/plain and the given encoding if body and encoding are '
'both set', () {
- var request = new http.Request('POST', dummyUrl);
+ var request = http.Request('POST', dummyUrl);
request.encoding = latin1;
request.body = 'hello, world';
expect(request.headers['Content-Type'],
@@ -225,7 +225,7 @@
});
test('is modified to include utf-8 if body is set', () {
- var request = new http.Request('POST', dummyUrl);
+ var request = http.Request('POST', dummyUrl);
request.headers['Content-Type'] = 'application/json';
request.body = '{"hello": "world"}';
expect(request.headers['Content-Type'],
@@ -233,7 +233,7 @@
});
test('is modified to include the given encoding if encoding is set', () {
- var request = new http.Request('POST', dummyUrl);
+ var request = http.Request('POST', dummyUrl);
request.headers['Content-Type'] = 'application/json';
request.encoding = latin1;
expect(request.headers['Content-Type'],
@@ -241,7 +241,7 @@
});
test('has its charset overridden by an explicit encoding', () {
- var request = new http.Request('POST', dummyUrl);
+ var request = http.Request('POST', dummyUrl);
request.headers['Content-Type'] = 'application/json; charset=utf-8';
request.encoding = latin1;
expect(request.headers['Content-Type'],
@@ -249,7 +249,7 @@
});
test("doen't have its charset overridden by setting bodyFields", () {
- var request = new http.Request('POST', dummyUrl);
+ var request = http.Request('POST', dummyUrl);
request.headers['Content-Type'] =
'application/x-www-form-urlencoded; charset=iso-8859-1';
request.bodyFields = {'hello': 'world'};
@@ -258,7 +258,7 @@
});
test("doen't have its charset overridden by setting body", () {
- var request = new http.Request('POST', dummyUrl);
+ var request = http.Request('POST', dummyUrl);
request.headers['Content-Type'] = 'application/json; charset=iso-8859-1';
request.body = '{"hello": "world"}';
expect(request.headers['Content-Type'],
@@ -268,14 +268,14 @@
group('#finalize', () {
test('returns a stream that emits the request body', () {
- var request = new http.Request('POST', dummyUrl);
+ var request = http.Request('POST', dummyUrl);
request.body = "Hello, world!";
expect(request.finalize().bytesToString(),
completion(equals("Hello, world!")));
});
test('freezes #persistentConnection', () {
- var request = new http.Request('POST', dummyUrl);
+ var request = http.Request('POST', dummyUrl);
request.finalize();
expect(request.persistentConnection, isTrue);
@@ -283,7 +283,7 @@
});
test('freezes #followRedirects', () {
- var request = new http.Request('POST', dummyUrl);
+ var request = http.Request('POST', dummyUrl);
request.finalize();
expect(request.followRedirects, isTrue);
@@ -291,7 +291,7 @@
});
test('freezes #maxRedirects', () {
- var request = new http.Request('POST', dummyUrl);
+ var request = http.Request('POST', dummyUrl);
request.finalize();
expect(request.maxRedirects, equals(5));
@@ -299,7 +299,7 @@
});
test('freezes #encoding', () {
- var request = new http.Request('POST', dummyUrl);
+ var request = http.Request('POST', dummyUrl);
request.finalize();
expect(request.encoding.name, equals(utf8.name));
@@ -307,7 +307,7 @@
});
test('freezes #bodyBytes', () {
- var request = new http.Request('POST', dummyUrl);
+ var request = http.Request('POST', dummyUrl);
request.bodyBytes = [1, 2, 3];
request.finalize();
@@ -316,7 +316,7 @@
});
test('freezes #body', () {
- var request = new http.Request('POST', dummyUrl);
+ var request = http.Request('POST', dummyUrl);
request.body = "hello";
request.finalize();
@@ -325,7 +325,7 @@
});
test('freezes #bodyFields', () {
- var request = new http.Request('POST', dummyUrl);
+ var request = http.Request('POST', dummyUrl);
request.bodyFields = {"hello": "world"};
request.finalize();
@@ -334,7 +334,7 @@
});
test("can't be called twice", () {
- var request = new http.Request('POST', dummyUrl);
+ var request = http.Request('POST', dummyUrl);
request.finalize();
expect(request.finalize, throwsStateError);
});
@@ -342,7 +342,7 @@
group('#toString()', () {
test('includes the method and URL', () {
- var request = new http.Request('POST', dummyUrl);
+ var request = http.Request('POST', dummyUrl);
expect(request.toString(), 'POST $dummyUrl');
});
});
diff --git a/test/response_test.dart b/test/response_test.dart
index 44707bf..110e5ec 100644
--- a/test/response_test.dart
+++ b/test/response_test.dart
@@ -10,12 +10,12 @@
void main() {
group('()', () {
test('sets body', () {
- var response = new http.Response("Hello, world!", 200);
+ var response = http.Response("Hello, world!", 200);
expect(response.body, equals("Hello, world!"));
});
test('sets bodyBytes', () {
- var response = new http.Response("Hello, world!", 200);
+ var response = http.Response("Hello, world!", 200);
expect(
response.bodyBytes,
equals(
@@ -23,7 +23,7 @@
});
test('respects the inferred encoding', () {
- var response = new http.Response("föøbãr", 200,
+ var response = http.Response("föøbãr", 200,
headers: {'content-type': 'text/plain; charset=iso-8859-1'});
expect(response.bodyBytes, equals([102, 246, 248, 98, 227, 114]));
});
@@ -31,17 +31,17 @@
group('.bytes()', () {
test('sets body', () {
- var response = new http.Response.bytes([104, 101, 108, 108, 111], 200);
+ var response = http.Response.bytes([104, 101, 108, 108, 111], 200);
expect(response.body, equals("hello"));
});
test('sets bodyBytes', () {
- var response = new http.Response.bytes([104, 101, 108, 108, 111], 200);
+ var response = http.Response.bytes([104, 101, 108, 108, 111], 200);
expect(response.bodyBytes, equals([104, 101, 108, 108, 111]));
});
test('respects the inferred encoding', () {
- var response = new http.Response.bytes([102, 246, 248, 98, 227, 114], 200,
+ var response = http.Response.bytes([102, 246, 248, 98, 227, 114], 200,
headers: {'content-type': 'text/plain; charset=iso-8859-1'});
expect(response.body, equals("föøbãr"));
});
@@ -49,9 +49,9 @@
group('.fromStream()', () {
test('sets body', () {
- var controller = new StreamController<List<int>>(sync: true);
+ var controller = StreamController<List<int>>(sync: true);
var streamResponse =
- new http.StreamedResponse(controller.stream, 200, contentLength: 13);
+ http.StreamedResponse(controller.stream, 200, contentLength: 13);
var future = http.Response.fromStream(streamResponse)
.then((response) => response.body);
expect(future, completion(equals("Hello, world!")));
@@ -62,9 +62,9 @@
});
test('sets bodyBytes', () {
- var controller = new StreamController<List<int>>(sync: true);
+ var controller = StreamController<List<int>>(sync: true);
var streamResponse =
- new http.StreamedResponse(controller.stream, 200, contentLength: 5);
+ http.StreamedResponse(controller.stream, 200, contentLength: 5);
var future = http.Response.fromStream(streamResponse)
.then((response) => response.bodyBytes);
expect(future, completion(equals([104, 101, 108, 108, 111])));
diff --git a/test/streamed_request_test.dart b/test/streamed_request_test.dart
index 6a86fcb..ad384a5 100644
--- a/test/streamed_request_test.dart
+++ b/test/streamed_request_test.dart
@@ -10,17 +10,17 @@
void main() {
group('contentLength', () {
test('defaults to null', () {
- var request = new http.StreamedRequest('POST', dummyUrl);
+ var request = http.StreamedRequest('POST', dummyUrl);
expect(request.contentLength, isNull);
});
test('disallows negative values', () {
- var request = new http.StreamedRequest('POST', dummyUrl);
+ var request = http.StreamedRequest('POST', dummyUrl);
expect(() => request.contentLength = -1, throwsArgumentError);
});
test('is frozen by finalize()', () {
- var request = new http.StreamedRequest('POST', dummyUrl);
+ var request = http.StreamedRequest('POST', dummyUrl);
request.finalize();
expect(() => request.contentLength = 10, throwsStateError);
});
diff --git a/test/utils.dart b/test/utils.dart
index c9819c6..b92f284 100644
--- a/test/utils.dart
+++ b/test/utils.dart
@@ -40,7 +40,7 @@
/// A matcher that matches JSON that parses to a value that matches the inner
/// matcher.
-Matcher parse(matcher) => new _Parse(matcher);
+Matcher parse(matcher) => _Parse(matcher);
class _Parse extends Matcher {
final Matcher _matcher;
@@ -71,7 +71,7 @@
/// The string "{{boundary}}" in [pattern] will be replaced by the boundary
/// string for the request, and LF newlines will be replaced with CRLF.
/// Indentation will be normalized.
-Matcher bodyMatches(String pattern) => new _BodyMatches(pattern);
+Matcher bodyMatches(String pattern) => _BodyMatches(pattern);
class _BodyMatches extends Matcher {
final String _pattern;
@@ -83,7 +83,7 @@
var future = item.finalize().toBytes().then((bodyBytes) {
var body = utf8.decode(bodyBytes);
- var contentType = new MediaType.parse(item.headers['content-type']);
+ var contentType = MediaType.parse(item.headers['content-type']);
var boundary = contentType.parameters['boundary'];
var expected = cleanUpLiteral(_pattern)
.replaceAll("\n", "\r\n")
@@ -105,7 +105,7 @@
///
/// [message] can be a String or a [Matcher].
Matcher isClientException(message) => predicate((error) {
- expect(error, new TypeMatcher<http.ClientException>());
+ expect(error, TypeMatcher<http.ClientException>());
expect(error.message, message);
return true;
});