Updated more constant names.
diff --git a/lib/http.dart b/lib/http.dart
index 86bcefb..a40a4c2 100644
--- a/lib/http.dart
+++ b/lib/http.dart
@@ -61,7 +61,7 @@
/// 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 @@
/// 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 @@
/// 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 a9d47b0..fdfeb1a 100644
--- a/lib/src/byte_stream.dart
+++ b/lib/src/byte_stream.dart
@@ -28,9 +28,9 @@
/// Collect the data of this stream in a [String], decoded according to
/// [encoding], which defaults to `UTF8`.
- Future<String> bytesToString([Encoding encoding=UTF8]) =>
+ Future<String> bytesToString([Encoding encoding=utf8]) =>
encoding.decodeStream(this);
- Stream<String> toStringStream([Encoding encoding=UTF8]) =>
+ Stream<String> toStringStream([Encoding encoding=utf8]) =>
encoding.decoder.bind(this);
}
diff --git a/lib/src/client.dart b/lib/src/client.dart
index cf1ff78..3d7564b 100644
--- a/lib/src/client.dart
+++ b/lib/src/client.dart
@@ -56,7 +56,7 @@
/// 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<Response> post(url, {Map<String, String> headers, body,
@@ -77,7 +77,7 @@
/// 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<Response> put(url, {Map<String, String> headers, body,
@@ -98,7 +98,7 @@
/// 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<Response> patch(url, {Map<String, String> headers, body,
diff --git a/lib/src/multipart_file.dart b/lib/src/multipart_file.dart
index da4bfac..3724c0b 100644
--- a/lib/src/multipart_file.dart
+++ b/lib/src/multipart_file.dart
@@ -70,7 +70,7 @@
{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 67b664c..2ede981 100644
--- a/lib/src/request.dart
+++ b/lib/src/request.dart
@@ -36,7 +36,7 @@
/// 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 @@
/// 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 9fa06ee..33160ae 100644
--- a/lib/src/response.dart
+++ b/lib/src/response.dart
@@ -21,7 +21,7 @@
/// 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 @@
}
/// 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<String, String> headers) =>
encodingForCharset(_contentTypeForHeaders(headers).parameters['charset']);
diff --git a/lib/src/utils.dart b/lib/src/utils.dart
index 789c2d9..3dd9526 100644
--- a/lib/src/utils.dart
+++ b/lib/src/utils.dart
@@ -40,7 +40,7 @@
/// 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 acfa584..a5ab2dd 100644
--- a/test/io/client_test.dart
+++ b/test/io/client_test.dart
@@ -16,9 +16,9 @@
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 @@
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 @@
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 cc05bbb..c9acaa9 100644
--- a/test/io/streamed_request_test.dart
+++ b/test/io/streamed_request_test.dart
@@ -20,7 +20,7 @@
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 @@
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 @@
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 923ee8b..2a52b2a 100644
--- a/test/io/utils.dart
+++ b/test/io/utils.dart
@@ -65,7 +65,7 @@
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 f2f4c13..4ad927f 100644
--- a/test/request_test.dart
+++ b/test/request_test.dart
@@ -36,30 +36,30 @@
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 @@
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 @@
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 @@
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 @@
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 @@
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 @@
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 @@
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 @@
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 @@
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', () {