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

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

Issue 216603010: Rip out dart:io from pkg/http wherever possible. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: code review Created 6 years, 8 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 | « pkg/http/lib/src/exception.dart ('k') | pkg/http/lib/src/multipart_file.dart » ('j') | no next file with comments »
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) 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 io_client; 5 library io_client;
6 6
7 import 'dart:async'; 7 import 'dart:async';
8 import 'dart:io'; 8 import 'dart:io';
9 9
10 import 'package:stack_trace/stack_trace.dart'; 10 import 'package:stack_trace/stack_trace.dart';
11 11
12 import 'base_client.dart'; 12 import 'base_client.dart';
13 import 'base_request.dart'; 13 import 'base_request.dart';
14 import 'exception.dart';
14 import 'streamed_response.dart'; 15 import 'streamed_response.dart';
15 16
16 /// A `dart:io`-based HTTP client. This is the default client. 17 /// A `dart:io`-based HTTP client. This is the default client.
17 class IOClient extends BaseClient { 18 class IOClient extends BaseClient {
18 /// The underlying `dart:io` HTTP client. 19 /// The underlying `dart:io` HTTP client.
19 HttpClient _inner; 20 HttpClient _inner;
20 21
21 /// Creates a new HTTP client. 22 /// Creates a new HTTP client.
22 IOClient() : _inner = new HttpClient(); 23 IOClient() : _inner = new HttpClient();
23 24
(...skipping 16 matching lines...) Expand all
40 return Chain.track(stream.pipe(ioRequest)); 41 return Chain.track(stream.pipe(ioRequest));
41 }).then((response) { 42 }).then((response) {
42 var headers = {}; 43 var headers = {};
43 response.headers.forEach((key, values) { 44 response.headers.forEach((key, values) {
44 headers[key] = values.join(','); 45 headers[key] = values.join(',');
45 }); 46 });
46 47
47 var contentLength = response.contentLength == -1 ? 48 var contentLength = response.contentLength == -1 ?
48 null : response.contentLength; 49 null : response.contentLength;
49 return new StreamedResponse( 50 return new StreamedResponse(
50 response, 51 response.handleError((error) =>
52 throw new ClientException(error.message, error.uri),
53 test: (error) => error is HttpException),
51 response.statusCode, 54 response.statusCode,
52 contentLength: contentLength, 55 contentLength: contentLength,
53 request: request, 56 request: request,
54 headers: headers, 57 headers: headers,
55 isRedirect: response.isRedirect, 58 isRedirect: response.isRedirect,
56 persistentConnection: response.persistentConnection, 59 persistentConnection: response.persistentConnection,
57 reasonPhrase: response.reasonPhrase); 60 reasonPhrase: response.reasonPhrase);
61 }).catchError((error) {
62 if (error is! HttpException) throw error;
63 throw new ClientException(error.message, error.uri);
58 }); 64 });
59 } 65 }
60 66
61 /// Closes the client. This terminates all active connections. If a client 67 /// Closes the client. This terminates all active connections. If a client
62 /// remains unclosed, the Dart process may not terminate. 68 /// remains unclosed, the Dart process may not terminate.
63 void close() { 69 void close() {
64 if (_inner != null) _inner.close(force: true); 70 if (_inner != null) _inner.close(force: true);
65 _inner = null; 71 _inner = null;
66 } 72 }
67 } 73 }
OLDNEW
« no previous file with comments | « pkg/http/lib/src/exception.dart ('k') | pkg/http/lib/src/multipart_file.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698