Skip to content

Commit

Permalink
Updated more constant names.
Browse files Browse the repository at this point in the history
  • Loading branch information
lrhn committed Jul 6, 2018
1 parent 346ed15 commit 5f0d557
Show file tree
Hide file tree
Showing 11 changed files with 41 additions and 41 deletions.
6 changes: 3 additions & 3 deletions lib/http.dart
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ Future<Response> get(url, {Map<String, String> 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.
Expand All @@ -85,7 +85,7 @@ Future<Response> post(url, {Map<String, String> 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.
Expand All @@ -109,7 +109,7 @@ Future<Response> put(url, {Map<String, String> 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.
Expand Down
4 changes: 2 additions & 2 deletions lib/src/byte_stream.dart
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,9 @@ class ByteStream extends StreamView<List<int>> {

/// 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);
}
6 changes: 3 additions & 3 deletions lib/src/client.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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<Response> post(url, {Map<String, String> headers, body,
Expand All @@ -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<Response> put(url, {Map<String, String> headers, body,
Expand All @@ -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<Response> patch(url, {Map<String, String> headers, body,
Expand Down
2 changes: 1 addition & 1 deletion lib/src/multipart_file.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand Down
4 changes: 2 additions & 2 deletions lib/src/request.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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].
Expand Down Expand Up @@ -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);

Expand Down
4 changes: 2 additions & 2 deletions lib/src/response.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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<String, String> headers) =>
encodingForCharset(_contentTypeForHeaders(headers).parameters['charset']);
Expand Down
2 changes: 1 addition & 1 deletion lib/src/utils.dart
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ List<String> 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;
Expand Down
10 changes: 5 additions & 5 deletions test/io/client_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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] =

This comment has been minimized.

Copy link
@leafpetersen

leafpetersen Jul 11, 2018

Member

This is the wrong name. Should be HttpHeaders.contentTypeHeader

'application/json; charset=utf-8';
request.headers[HttpHeaders.USER_AGENT] = 'Dart';
request.headers[HttpHeaders.userAgent] = 'Dart';

This comment has been minimized.

Copy link
@leafpetersen

leafpetersen Jul 11, 2018

Member

Here also.


expect(client.send(request).then((response) {
expect(response.request, equals(request));
Expand Down Expand Up @@ -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] =

This comment has been minimized.

Copy link
@leafpetersen

leafpetersen Jul 11, 2018

Member

Here, and everything else with HttpHeaders below.

'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));
Expand Down Expand Up @@ -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);
Expand Down
6 changes: 3 additions & 3 deletions test/io/streamed_request_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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);
Expand All @@ -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);
});

Expand Down
2 changes: 1 addition & 1 deletion test/io/utils.dart
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ Future startServer() {
if (encodingName != null) {
outputEncoding = requiredEncodingForCharset(encodingName);
} else {
outputEncoding = ASCII;
outputEncoding = ascii;
}

response.headers.contentType =
Expand Down
36 changes: 18 additions & 18 deletions test/request_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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', () {
Expand Down Expand Up @@ -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"));
});
Expand Down Expand Up @@ -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'));
});
Expand All @@ -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"}));
});
Expand All @@ -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);
});

Expand All @@ -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'));
Expand All @@ -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'));
Expand All @@ -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'));
});
Expand All @@ -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'));
});
Expand Down Expand Up @@ -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', () {
Expand Down

0 comments on commit 5f0d557

Please sign in to comment.