Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(284)

Side by Side Diff: pkg/http/test/utils.dart

Issue 12504006: Make IOSink implement StringSink (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Correct rebase Created 7 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « no previous file | runtime/bin/socket_patch.dart » ('j') | runtime/bin/socket_patch.dart » ('J')
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2012, 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:io'; 8 import 'dart:io';
9 import 'dart:json' as json; 9 import 'dart:json' as json;
10 import 'dart:uri'; 10 import 'dart:uri';
11 11
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
51 if (path == '/redirect') { 51 if (path == '/redirect') {
52 response.statusCode = 302; 52 response.statusCode = 302;
53 response.headers.set('location', serverUrl.resolve('/').toString()); 53 response.headers.set('location', serverUrl.resolve('/').toString());
54 response.contentLength = 0; 54 response.contentLength = 0;
55 response.close(); 55 response.close();
56 return; 56 return;
57 } 57 }
58 58
59 new ByteStream(request).toBytes().then((requestBodyBytes) { 59 new ByteStream(request).toBytes().then((requestBodyBytes) {
60 response.statusCode = 200; 60 response.statusCode = 200;
61 response.headers.contentType = new ContentType("application", "json"); 61 var encodingName = request.queryParameters['response-encoding'];
62 response.headers.set('single', 'value'); 62 response.headers.contentType =
63 new ContentType("application", "json", charset: encodingName);
64 response.headers.set('single', 'value');
63 65
64 var requestBody; 66 var requestBody;
65 if (requestBodyBytes.isEmpty) { 67 if (requestBodyBytes.isEmpty) {
66 requestBody = null; 68 requestBody = null;
67 } else if (request.headers.contentType.charset != null) { 69 } else if (request.headers.contentType.charset != null) {
68 var encoding = requiredEncodingForCharset( 70 var encoding = request.headers.contentType.encoding;
nweiz 2013/03/06 20:31:51 If you've removed all references to requiredEncodi
Søren Gjesse 2013/03/07 16:28:47 Done.
69 request.headers.contentType.charset);
70 requestBody = decodeString(requestBodyBytes, encoding); 71 requestBody = decodeString(requestBodyBytes, encoding);
71 } else { 72 } else {
72 requestBody = requestBodyBytes; 73 requestBody = requestBodyBytes;
73 } 74 }
74 75
75 var content = { 76 var content = {
76 'method': request.method, 77 'method': request.method,
77 'path': request.uri.path, 78 'path': request.uri.path,
78 'headers': {} 79 'headers': {}
79 }; 80 };
80 if (requestBody != null) content['body'] = requestBody; 81 if (requestBody != null) content['body'] = requestBody;
81 request.headers.forEach((name, values) { 82 request.headers.forEach((name, values) {
82 // These headers are automatically generated by dart:io, so we don't 83 // These headers are automatically generated by dart:io, so we don't
83 // want to test them here. 84 // want to test them here.
84 if (name == 'cookie' || name == 'host') return; 85 if (name == 'cookie' || name == 'host') return;
85 86
86 content['headers'][name] = values; 87 content['headers'][name] = values;
87 }); 88 });
88 89
89 var outputEncoding;
90 var encodingName = request.queryParameters['response-encoding'];
91 if (encodingName != null) {
92 outputEncoding = requiredEncodingForCharset(encodingName);
93 } else {
94 outputEncoding = Encoding.ASCII;
95 }
96
97 var body = json.stringify(content); 90 var body = json.stringify(content);
98 response.contentLength = body.length; 91 response.contentLength = body.length;
99 response.addString(body, outputEncoding); 92 response.write(body);
100 response.close(); 93 response.close();
101 }); 94 });
102 }); 95 });
103 }); 96 });
104 } 97 }
105 98
106 /// Stops the current HTTP server. 99 /// Stops the current HTTP server.
107 void stopServer() { 100 void stopServer() {
108 _server.close(); 101 _server.close();
109 _server = null; 102 _server = null;
(...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after
196 const isSocketIOException = const _SocketIOException(); 189 const isSocketIOException = const _SocketIOException();
197 190
198 /// A matcher for functions that throw SocketIOException. 191 /// A matcher for functions that throw SocketIOException.
199 const Matcher throwsSocketIOException = 192 const Matcher throwsSocketIOException =
200 const Throws(isSocketIOException); 193 const Throws(isSocketIOException);
201 194
202 class _SocketIOException extends TypeMatcher { 195 class _SocketIOException extends TypeMatcher {
203 const _SocketIOException() : super("SocketIOException"); 196 const _SocketIOException() : super("SocketIOException");
204 bool matches(item, MatchState matchState) => item is SocketIOException; 197 bool matches(item, MatchState matchState) => item is SocketIOException;
205 } 198 }
OLDNEW
« no previous file with comments | « no previous file | runtime/bin/socket_patch.dart » ('j') | runtime/bin/socket_patch.dart » ('J')

Powered by Google App Engine
This is Rietveld 408576698