OLD | NEW |
1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2013, 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 library test_utils; | 5 library test_utils; |
6 | 6 |
7 import 'dart:async'; | 7 import 'dart:async'; |
| 8 import 'dart:convert'; |
8 import 'dart:io'; | 9 import 'dart:io'; |
9 import 'dart:json' as json; | 10 import 'dart:json' as json; |
10 | 11 |
11 import 'package:http/src/byte_stream.dart'; | 12 import 'package:http/src/byte_stream.dart'; |
12 import 'package:http/src/utils.dart'; | 13 import 'package:http/src/utils.dart'; |
13 import 'package:unittest/unittest.dart'; | 14 import 'package:unittest/unittest.dart'; |
14 | 15 |
15 import 'safe_http_server.dart'; | 16 import 'safe_http_server.dart'; |
16 | 17 |
17 /// The current server instance. | 18 /// The current server instance. |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
55 response.close(); | 56 response.close(); |
56 return; | 57 return; |
57 } | 58 } |
58 | 59 |
59 new ByteStream(request).toBytes().then((requestBodyBytes) { | 60 new ByteStream(request).toBytes().then((requestBodyBytes) { |
60 var outputEncoding; | 61 var outputEncoding; |
61 var encodingName = request.uri.queryParameters['response-encoding']; | 62 var encodingName = request.uri.queryParameters['response-encoding']; |
62 if (encodingName != null) { | 63 if (encodingName != null) { |
63 outputEncoding = requiredEncodingForCharset(encodingName); | 64 outputEncoding = requiredEncodingForCharset(encodingName); |
64 } else { | 65 } else { |
65 outputEncoding = Encoding.ASCII; | 66 outputEncoding = ASCII; |
66 } | 67 } |
67 | 68 |
68 response.headers.contentType = | 69 response.headers.contentType = |
69 new ContentType( | 70 new ContentType( |
70 "application", "json", charset: outputEncoding.name); | 71 "application", "json", charset: outputEncoding.name); |
71 response.headers.set('single', 'value'); | 72 response.headers.set('single', 'value'); |
72 | 73 |
73 var requestBody; | 74 var requestBody; |
74 if (requestBodyBytes.isEmpty) { | 75 if (requestBodyBytes.isEmpty) { |
75 requestBody = null; | 76 requestBody = null; |
76 } else if (request.headers.contentType.charset != null) { | 77 } else if (request.headers.contentType.charset != null) { |
77 var encoding = requiredEncodingForCharset( | 78 var encoding = requiredEncodingForCharset( |
78 request.headers.contentType.charset); | 79 request.headers.contentType.charset); |
79 requestBody = decodeString(requestBodyBytes, encoding); | 80 requestBody = encoding.decode(requestBodyBytes); |
80 } else { | 81 } else { |
81 requestBody = requestBodyBytes; | 82 requestBody = requestBodyBytes; |
82 } | 83 } |
83 | 84 |
84 var content = { | 85 var content = { |
85 'method': request.method, | 86 'method': request.method, |
86 'path': request.uri.path, | 87 'path': request.uri.path, |
87 'headers': {} | 88 'headers': {} |
88 }; | 89 }; |
89 if (requestBody != null) content['body'] = requestBody; | 90 if (requestBody != null) content['body'] = requestBody; |
(...skipping 109 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
199 const isSocketException = const _SocketException(); | 200 const isSocketException = const _SocketException(); |
200 | 201 |
201 /// A matcher for functions that throw SocketException. | 202 /// A matcher for functions that throw SocketException. |
202 const Matcher throwsSocketException = | 203 const Matcher throwsSocketException = |
203 const Throws(isSocketException); | 204 const Throws(isSocketException); |
204 | 205 |
205 class _SocketException extends TypeMatcher { | 206 class _SocketException extends TypeMatcher { |
206 const _SocketException() : super("SocketException"); | 207 const _SocketException() : super("SocketException"); |
207 bool matches(item, Map matchState) => item is SocketException; | 208 bool matches(item, Map matchState) => item is SocketException; |
208 } | 209 } |
OLD | NEW |