From 5f0d5579d27501aa23e04a0f02d7f6d27b1098d0 Mon Sep 17 00:00:00 2001 From: Lasse Reichstein Holst Nielsen Date: Fri, 6 Jul 2018 16:08:09 +0200 Subject: [PATCH] Updated more constant names. --- lib/http.dart | 6 ++--- lib/src/byte_stream.dart | 4 ++-- lib/src/client.dart | 6 ++--- lib/src/multipart_file.dart | 2 +- lib/src/request.dart | 4 ++-- lib/src/response.dart | 4 ++-- lib/src/utils.dart | 2 +- test/io/client_test.dart | 10 ++++----- test/io/streamed_request_test.dart | 6 ++--- test/io/utils.dart | 2 +- test/request_test.dart | 36 +++++++++++++++--------------- 11 files changed, 41 insertions(+), 41 deletions(-) diff --git a/lib/http.dart b/lib/http.dart index 86bcefbc4d..a40a4c232c 100644 --- a/lib/http.dart +++ b/lib/http.dart @@ -61,7 +61,7 @@ Future get(url, {Map headers}) => /// content-type of the request will be set to /// `"application/x-www-form-urlencoded"`; this cannot be overridden. /// -/// [encoding] defaults to [UTF8]. +/// [encoding] defaults to [utf8]. /// /// For more fine-grained control over the request, use [Request] or /// [StreamedRequest] instead. @@ -85,7 +85,7 @@ Future post(url, {Map headers, body, /// content-type of the request will be set to /// `"application/x-www-form-urlencoded"`; this cannot be overridden. /// -/// [encoding] defaults to [UTF8]. +/// [encoding] defaults to [utf8]. /// /// For more fine-grained control over the request, use [Request] or /// [StreamedRequest] instead. @@ -109,7 +109,7 @@ Future put(url, {Map headers, body, /// content-type of the request will be set to /// `"application/x-www-form-urlencoded"`; this cannot be overridden. /// -/// [encoding] defaults to [UTF8]. +/// [encoding] defaults to [utf8]. /// /// For more fine-grained control over the request, use [Request] or /// [StreamedRequest] instead. diff --git a/lib/src/byte_stream.dart b/lib/src/byte_stream.dart index a9d47b075f..fdfeb1a8b1 100644 --- a/lib/src/byte_stream.dart +++ b/lib/src/byte_stream.dart @@ -28,9 +28,9 @@ class ByteStream extends StreamView> { /// Collect the data of this stream in a [String], decoded according to /// [encoding], which defaults to `UTF8`. - Future bytesToString([Encoding encoding=UTF8]) => + Future bytesToString([Encoding encoding=utf8]) => encoding.decodeStream(this); - Stream toStringStream([Encoding encoding=UTF8]) => + Stream toStringStream([Encoding encoding=utf8]) => encoding.decoder.bind(this); } diff --git a/lib/src/client.dart b/lib/src/client.dart index cf1ff784a0..3d7564b5e6 100644 --- a/lib/src/client.dart +++ b/lib/src/client.dart @@ -56,7 +56,7 @@ abstract class Client { /// content-type of the request will be set to /// `"application/x-www-form-urlencoded"`; this cannot be overridden. /// - /// [encoding] defaults to [UTF8]. + /// [encoding] defaults to [utf8]. /// /// For more fine-grained control over the request, use [send] instead. Future post(url, {Map headers, body, @@ -77,7 +77,7 @@ abstract class Client { /// content-type of the request will be set to /// `"application/x-www-form-urlencoded"`; this cannot be overridden. /// - /// [encoding] defaults to [UTF8]. + /// [encoding] defaults to [utf8]. /// /// For more fine-grained control over the request, use [send] instead. Future put(url, {Map headers, body, @@ -98,7 +98,7 @@ abstract class Client { /// content-type of the request will be set to /// `"application/x-www-form-urlencoded"`; this cannot be overridden. /// - /// [encoding] defaults to [UTF8]. + /// [encoding] defaults to [utf8]. /// /// For more fine-grained control over the request, use [send] instead. Future patch(url, {Map headers, body, diff --git a/lib/src/multipart_file.dart b/lib/src/multipart_file.dart index da4bface78..3724c0be6a 100644 --- a/lib/src/multipart_file.dart +++ b/lib/src/multipart_file.dart @@ -70,7 +70,7 @@ class MultipartFile { {String filename, MediaType contentType}) { contentType = contentType == null ? new MediaType("text", "plain") : contentType; - var encoding = encodingForCharset(contentType.parameters['charset'], UTF8); + var encoding = encodingForCharset(contentType.parameters['charset'], utf8); contentType = contentType.change(parameters: {'charset': encoding.name}); return new MultipartFile.fromBytes(field, encoding.encode(value), diff --git a/lib/src/request.dart b/lib/src/request.dart index 67b664c08e..2ede981f08 100644 --- a/lib/src/request.dart +++ b/lib/src/request.dart @@ -36,7 +36,7 @@ class Request extends BaseRequest { /// If the request has a `Content-Type` header and that header has a `charset` /// parameter, that parameter's value is used as the encoding. Otherwise, if /// [encoding] has been set manually, that encoding is used. If that hasn't - /// been set either, this defaults to [UTF8]. + /// been set either, this defaults to [utf8]. /// /// If the `charset` parameter's value is not a known [Encoding], reading this /// will throw a [FormatException]. @@ -130,7 +130,7 @@ class Request extends BaseRequest { /// Creates a new HTTP request. Request(String method, Uri url) - : _defaultEncoding = UTF8, + : _defaultEncoding = utf8, _bodyBytes = new Uint8List(0), super(method, url); diff --git a/lib/src/response.dart b/lib/src/response.dart index 9fa06ee782..33160aec0b 100644 --- a/lib/src/response.dart +++ b/lib/src/response.dart @@ -21,7 +21,7 @@ class Response extends BaseResponse { /// The body of the response as a string. This is converted from [bodyBytes] /// using the `charset` parameter of the `Content-Type` header field, if /// available. If it's unavailable or if the encoding name is unknown, - /// [LATIN1] is used by default, as per [RFC 2616][]. + /// [latin1] is used by default, as per [RFC 2616][]. /// /// [RFC 2616]: http://www.w3.org/Protocols/rfc2616/rfc2616-sec3.html String get body => _encodingForHeaders(headers).decode(bodyBytes); @@ -80,7 +80,7 @@ class Response extends BaseResponse { } /// Returns the encoding to use for a response with the given headers. This -/// defaults to [LATIN1] if the headers don't specify a charset or +/// defaults to [latin1] if the headers don't specify a charset or /// if that charset is unknown. Encoding _encodingForHeaders(Map headers) => encodingForCharset(_contentTypeForHeaders(headers).parameters['charset']); diff --git a/lib/src/utils.dart b/lib/src/utils.dart index 789c2d964f..3dd9526465 100644 --- a/lib/src/utils.dart +++ b/lib/src/utils.dart @@ -40,7 +40,7 @@ List split1(String toSplit, String pattern) { /// Returns the [Encoding] that corresponds to [charset]. Returns [fallback] if /// [charset] is null or if no [Encoding] was found that corresponds to /// [charset]. -Encoding encodingForCharset(String charset, [Encoding fallback = LATIN1]) { +Encoding encodingForCharset(String charset, [Encoding fallback = latin1]) { if (charset == null) return fallback; var encoding = Encoding.getByName(charset); return encoding == null ? fallback : encoding; diff --git a/test/io/client_test.dart b/test/io/client_test.dart index acfa584a3c..a5ab2ddf04 100644 --- a/test/io/client_test.dart +++ b/test/io/client_test.dart @@ -16,9 +16,9 @@ void main() { expect(startServer().then((_) { var client = new http.Client(); var request = new http.StreamedRequest("POST", serverUrl); - request.headers[HttpHeaders.CONTENT_TYPE] = + request.headers[HttpHeaders.contentType] = 'application/json; charset=utf-8'; - request.headers[HttpHeaders.USER_AGENT] = 'Dart'; + request.headers[HttpHeaders.userAgent] = 'Dart'; expect(client.send(request).then((response) { expect(response.request, equals(request)); @@ -51,9 +51,9 @@ void main() { var ioClient = new HttpClient(); var client = new http.IOClient(ioClient); var request = new http.StreamedRequest("POST", serverUrl); - request.headers[HttpHeaders.CONTENT_TYPE] = + request.headers[HttpHeaders.contentType] = 'application/json; charset=utf-8'; - request.headers[HttpHeaders.USER_AGENT] = 'Dart'; + request.headers[HttpHeaders.userAgent] = 'Dart'; expect(client.send(request).then((response) { expect(response.request, equals(request)); @@ -86,7 +86,7 @@ void main() { var client = new http.Client(); var url = Uri.parse('http://http.invalid'); var request = new http.StreamedRequest("POST", url); - request.headers[HttpHeaders.CONTENT_TYPE] = + request.headers[HttpHeaders.contentType] = 'application/json; charset=utf-8'; expect(client.send(request), throwsSocketException); diff --git a/test/io/streamed_request_test.dart b/test/io/streamed_request_test.dart index cc05bbb0f5..c9acaa9ea6 100644 --- a/test/io/streamed_request_test.dart +++ b/test/io/streamed_request_test.dart @@ -20,7 +20,7 @@ void main() { return request.send(); }).then((response) { - expect(UTF8.decodeStream(response.stream), + expect(utf8.decodeStream(response.stream), completion(parse(containsPair('headers', containsPair('content-length', ['10']))))); }).whenComplete(stopServer); @@ -34,7 +34,7 @@ void main() { return request.send(); }).then((response) { - expect(UTF8.decodeStream(response.stream), + expect(utf8.decodeStream(response.stream), completion(parse(containsPair('headers', isNot(contains('content-length')))))); }).whenComplete(stopServer); @@ -49,7 +49,7 @@ void main() { request.sink.close(); return request.send(); }).then((response) { - expect(UTF8.decodeStream(response.stream), completion(equals('body'))); + expect(utf8.decodeStream(response.stream), completion(equals('body'))); }).whenComplete(stopServer); }); diff --git a/test/io/utils.dart b/test/io/utils.dart index 923ee8b287..2a52b2a05f 100644 --- a/test/io/utils.dart +++ b/test/io/utils.dart @@ -65,7 +65,7 @@ Future startServer() { if (encodingName != null) { outputEncoding = requiredEncodingForCharset(encodingName); } else { - outputEncoding = ASCII; + outputEncoding = ascii; } response.headers.contentType = diff --git a/test/request_test.dart b/test/request_test.dart index f2f4c133d9..4ad927f43d 100644 --- a/test/request_test.dart +++ b/test/request_test.dart @@ -36,30 +36,30 @@ void main() { group('#encoding', () { test('defaults to utf-8', () { var request = new http.Request('POST', dummyUrl); - expect(request.encoding.name, equals(UTF8.name)); + expect(request.encoding.name, equals(utf8.name)); }); test('can be set', () { var request = new http.Request('POST', dummyUrl); - request.encoding = LATIN1; - expect(request.encoding.name, equals(LATIN1.name)); + 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); request.headers['Content-Type'] = 'text/plain; charset=iso-8859-1'; - expect(request.encoding.name, equals(LATIN1.name)); + 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); - request.encoding = LATIN1; + request.encoding = latin1; request.headers['Content-Type'] = 'text/plain; charset=utf-8'; - expect(request.encoding.name, equals(UTF8.name)); + expect(request.encoding.name, equals(utf8.name)); request.headers.remove('Content-Type'); - expect(request.encoding.name, equals(LATIN1.name)); + expect(request.encoding.name, equals(latin1.name)); }); test('throws an error if the content-type charset is unknown', () { @@ -109,14 +109,14 @@ void main() { test('is encoded according to the given encoding', () { var request = new http.Request('POST', dummyUrl); - request.encoding = LATIN1; + 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); - request.encoding = LATIN1; + request.encoding = latin1; request.bodyBytes = [102, 246, 248, 98, 227, 114]; expect(request.body, equals("föøbãr")); }); @@ -166,7 +166,7 @@ void main() { var request = new http.Request('POST', dummyUrl); request.headers['Content-Type'] = 'application/x-www-form-urlencoded'; - request.encoding = LATIN1; + request.encoding = latin1; request.bodyFields = {"föø": "bãr"}; expect(request.body, equals('f%F6%F8=b%E3r')); }); @@ -175,7 +175,7 @@ void main() { var request = new http.Request('POST', dummyUrl); request.headers['Content-Type'] = 'application/x-www-form-urlencoded'; - request.encoding = LATIN1; + request.encoding = latin1; request.body = 'f%F6%F8=b%E3r'; expect(request.bodyFields, equals({"föø": "bãr"})); }); @@ -189,7 +189,7 @@ void main() { test('defaults to empty if only encoding is set', () { var request = new http.Request('POST', dummyUrl); - request.encoding = LATIN1; + request.encoding = latin1; expect(request.headers['Content-Type'], isNull); }); @@ -211,7 +211,7 @@ void main() { 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); - request.encoding = LATIN1; + request.encoding = latin1; request.bodyFields = {'hello': 'world'}; expect(request.headers['Content-Type'], equals('application/x-www-form-urlencoded; charset=iso-8859-1')); @@ -220,7 +220,7 @@ void main() { test('is set to text/plain and the given encoding if body and encoding are ' 'both set', () { var request = new http.Request('POST', dummyUrl); - request.encoding = LATIN1; + request.encoding = latin1; request.body = 'hello, world'; expect(request.headers['Content-Type'], equals('text/plain; charset=iso-8859-1')); @@ -237,7 +237,7 @@ void main() { test('is modified to include the given encoding if encoding is set', () { var request = new http.Request('POST', dummyUrl); request.headers['Content-Type'] = 'application/json'; - request.encoding = LATIN1; + request.encoding = latin1; expect(request.headers['Content-Type'], equals('application/json; charset=iso-8859-1')); }); @@ -246,7 +246,7 @@ void main() { var request = new http.Request('POST', dummyUrl); request.headers['Content-Type'] = 'application/json; charset=utf-8'; - request.encoding = LATIN1; + request.encoding = latin1; expect(request.headers['Content-Type'], equals('application/json; charset=iso-8859-1')); }); @@ -306,8 +306,8 @@ void main() { var request = new http.Request('POST', dummyUrl); request.finalize(); - expect(request.encoding.name, equals(UTF8.name)); - expect(() => request.encoding = ASCII, throwsStateError); + expect(request.encoding.name, equals(utf8.name)); + expect(() => request.encoding = ascii, throwsStateError); }); test('freezes #bodyBytes', () {