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

Side by Side Diff: pkg/http/lib/src/mock_client.dart

Issue 124753002: Code cleanup (mostly io lib and some http lib). (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Merge to head. Created 6 years, 11 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
OLDNEW
1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2012, 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 mock_client; 5 library mock_client;
6 6
7 import 'dart:async'; 7 import 'dart:async';
8 8
9 import 'base_client.dart'; 9 import 'base_client.dart';
10 import 'base_request.dart'; 10 import 'base_request.dart';
(...skipping 15 matching lines...) Expand all
26 /// [StreamedResponse]s. 26 /// [StreamedResponse]s.
27 final MockClientStreamHandler _handler; 27 final MockClientStreamHandler _handler;
28 28
29 MockClient._(this._handler); 29 MockClient._(this._handler);
30 30
31 /// Creates a [MockClient] with a handler that receives [Request]s and sends 31 /// Creates a [MockClient] with a handler that receives [Request]s and sends
32 /// [Response]s. 32 /// [Response]s.
33 MockClient(MockClientHandler fn) 33 MockClient(MockClientHandler fn)
34 : this._((baseRequest, bodyStream) { 34 : this._((baseRequest, bodyStream) {
35 return bodyStream.toBytes().then((bodyBytes) { 35 return bodyStream.toBytes().then((bodyBytes) {
36 var request = new Request(baseRequest.method, baseRequest.url); 36 var request = new Request(baseRequest.method, baseRequest.url)
37 request.persistentConnection = baseRequest.persistentConnection; 37 ..persistentConnection = baseRequest.persistentConnection
38 request.followRedirects = baseRequest.followRedirects; 38 ..followRedirects = baseRequest.followRedirects
39 request.maxRedirects = baseRequest.maxRedirects; 39 ..maxRedirects = baseRequest.maxRedirects
40 request.headers.addAll(baseRequest.headers); 40 ..headers.addAll(baseRequest.headers)
41 request.bodyBytes = bodyBytes; 41 ..bodyBytes = bodyBytes
42 request.finalize(); 42 ..finalize();
43 43
44 return fn(request); 44 return fn(request);
45 }).then((response) { 45 }).then((response) {
46 return new StreamedResponse( 46 return new StreamedResponse(
47 new ByteStream.fromBytes(response.bodyBytes), 47 new ByteStream.fromBytes(response.bodyBytes),
48 response.statusCode, 48 response.statusCode,
49 response.contentLength, 49 response.contentLength,
50 request: baseRequest, 50 request: baseRequest,
51 headers: response.headers, 51 headers: response.headers,
52 isRedirect: response.isRedirect, 52 isRedirect: response.isRedirect,
(...skipping 27 matching lines...) Expand all
80 } 80 }
81 81
82 /// A handler function that receives [StreamedRequest]s and sends 82 /// A handler function that receives [StreamedRequest]s and sends
83 /// [StreamedResponse]s. Note that [request] will be finalized. 83 /// [StreamedResponse]s. Note that [request] will be finalized.
84 typedef Future<StreamedResponse> MockClientStreamHandler( 84 typedef Future<StreamedResponse> MockClientStreamHandler(
85 BaseRequest request, ByteStream bodyStream); 85 BaseRequest request, ByteStream bodyStream);
86 86
87 /// A handler function that receives [Request]s and sends [Response]s. Note that 87 /// A handler function that receives [Request]s and sends [Response]s. Note that
88 /// [request] will be finalized. 88 /// [request] will be finalized.
89 typedef Future<Response> MockClientHandler(Request request); 89 typedef Future<Response> MockClientHandler(Request request);
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698