| OLD | NEW |
| 1 // Copyright (c) 2015, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2015, the Dart project authors. Please see the AUTHORS file |
| 2 // for details. All rights reserved. Use of this source code is governed by a | 2 // for details. All rights reserved. Use of this source code is governed by a |
| 3 // BSD-style license that can be found in the LICENSE file. | 3 // BSD-style license that can be found in the LICENSE file. |
| 4 | 4 |
| 5 @TestOn("vm") | 5 @TestOn("vm") |
| 6 | 6 |
| 7 import "dart:convert"; | 7 import "dart:convert"; |
| 8 import "dart:io"; | 8 import "dart:io"; |
| 9 | 9 |
| 10 import "package:resource/resource.dart"; | 10 import "package:resource/resource.dart"; |
| (...skipping 12 matching lines...) Expand all Loading... |
| 23 if (request.uri.path.endsWith(".not")) { | 23 if (request.uri.path.endsWith(".not")) { |
| 24 request.response | 24 request.response |
| 25 ..statusCode = HttpStatus.NOT_FOUND | 25 ..statusCode = HttpStatus.NOT_FOUND |
| 26 ..close(); | 26 ..close(); |
| 27 return; | 27 return; |
| 28 } | 28 } |
| 29 var encodings = request.headers[HttpHeaders.ACCEPT_CHARSET]; | 29 var encodings = request.headers[HttpHeaders.ACCEPT_CHARSET]; |
| 30 var encoding = parseAcceptCharset(encodings); | 30 var encoding = parseAcceptCharset(encodings); |
| 31 request.response.headers.contentType = | 31 request.response.headers.contentType = |
| 32 new ContentType("text", "plain", charset: encoding.name); | 32 new ContentType("text", "plain", charset: encoding.name); |
| 33 if (request.uri.query.contains("length")) { |
| 34 request.response.headers.contentLength = content.length; |
| 35 } |
| 33 request.response..write(content) | 36 request.response..write(content) |
| 34 ..close(); | 37 ..close(); |
| 35 }).catchError(print); | 38 }).catchError(print); |
| 36 }); | 39 }); |
| 37 | 40 |
| 38 test("Default encoding", () async { | 41 test("Default encoding", () async { |
| 39 var loader = ResourceLoader.defaultLoader; | 42 var loader = ResourceLoader.defaultLoader; |
| 40 String string = await loader.readAsString(uri); | 43 String string = await loader.readAsString(uri); |
| 41 expect(string, content); | 44 expect(string, content); |
| 42 }); | 45 }); |
| 43 | 46 |
| 44 test("Latin-1 encoding", () async { | 47 test("Latin-1 encoding", () async { |
| 45 var loader = ResourceLoader.defaultLoader; | 48 var loader = ResourceLoader.defaultLoader; |
| 46 String string = await loader.readAsString(uri, encoding: LATIN1); | 49 String string = await loader.readAsString(uri, encoding: LATIN1); |
| 47 expect(string, content); | 50 expect(string, content); |
| 48 }); | 51 }); |
| 49 | 52 |
| 53 test("Latin-1 encoding w/ length", () async { |
| 54 // Regression test for issue #21. |
| 55 var loader = ResourceLoader.defaultLoader; |
| 56 var newUri = uri.replace(query: "length"); // Request length set. |
| 57 String string = await loader.readAsString(newUri, encoding: LATIN1); |
| 58 expect(string, content); |
| 59 }); |
| 60 |
| 50 test("UTF-8 encoding", () async { | 61 test("UTF-8 encoding", () async { |
| 51 var loader = ResourceLoader.defaultLoader; | 62 var loader = ResourceLoader.defaultLoader; |
| 52 String string = await loader.readAsString(uri, encoding: UTF8); | 63 String string = await loader.readAsString(uri, encoding: UTF8); |
| 53 expect(string, content); | 64 expect(string, content); |
| 54 }); | 65 }); |
| 55 | 66 |
| 56 test("bytes", () async { | 67 test("bytes", () async { |
| 57 var loader = ResourceLoader.defaultLoader; | 68 var loader = ResourceLoader.defaultLoader; |
| 58 List<int> bytes = await loader.readAsBytes(uri); // Sender uses Latin-1. | 69 List<int> bytes = await loader.readAsBytes(uri); // Sender uses Latin-1. |
| 59 expect(bytes, content.codeUnits); | 70 expect(bytes, content.codeUnits); |
| (...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 107 } | 118 } |
| 108 if (w > weight) { | 119 if (w > weight) { |
| 109 weight = w; | 120 weight = w; |
| 110 encoding = e; | 121 encoding = e; |
| 111 } | 122 } |
| 112 } | 123 } |
| 113 } | 124 } |
| 114 } | 125 } |
| 115 return encoding; | 126 return encoding; |
| 116 } | 127 } |
| OLD | NEW |