| OLD | NEW |
| 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 base_client; | 5 library base_client; |
| 6 | 6 |
| 7 import 'dart:async'; | 7 import 'dart:async'; |
| 8 import 'dart:convert'; | 8 import 'dart:convert'; |
| 9 import 'dart:io'; | 9 import 'dart:io'; |
| 10 import 'dart:typed_data'; | 10 import 'dart:typed_data'; |
| (...skipping 110 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 121 /// | 121 /// |
| 122 /// Implementers should call [BaseRequest.finalize] to get the body of the | 122 /// Implementers should call [BaseRequest.finalize] to get the body of the |
| 123 /// request as a [ByteStream]. They shouldn't make any assumptions about the | 123 /// request as a [ByteStream]. They shouldn't make any assumptions about the |
| 124 /// state of the stream; it could have data written to it asynchronously at a | 124 /// state of the stream; it could have data written to it asynchronously at a |
| 125 /// later point, or it could already be closed when it's returned. | 125 /// later point, or it could already be closed when it's returned. |
| 126 Future<StreamedResponse> send(BaseRequest request); | 126 Future<StreamedResponse> send(BaseRequest request); |
| 127 | 127 |
| 128 /// Sends a non-streaming [Request] and returns a non-streaming [Response]. | 128 /// Sends a non-streaming [Request] and returns a non-streaming [Response]. |
| 129 Future<Response> _sendUnstreamed(String method, url, | 129 Future<Response> _sendUnstreamed(String method, url, |
| 130 Map<String, String> headers, [body, Encoding encoding]) { | 130 Map<String, String> headers, [body, Encoding encoding]) { |
| 131 return new Future.sync(() { | 131 return syncFuture(() { |
| 132 if (url is String) url = Uri.parse(url); | 132 if (url is String) url = Uri.parse(url); |
| 133 var request = new Request(method, url); | 133 var request = new Request(method, url); |
| 134 | 134 |
| 135 if (headers != null) request.headers.addAll(headers); | 135 if (headers != null) request.headers.addAll(headers); |
| 136 if (encoding != null) request.encoding = encoding; | 136 if (encoding != null) request.encoding = encoding; |
| 137 if (body != null) { | 137 if (body != null) { |
| 138 if (body is String) { | 138 if (body is String) { |
| 139 request.body = body; | 139 request.body = body; |
| 140 } else if (body is List) { | 140 } else if (body is List) { |
| 141 request.bodyBytes = body; | 141 request.bodyBytes = body; |
| (...skipping 16 matching lines...) Expand all Loading... |
| 158 message = "$message: ${response.reasonPhrase}"; | 158 message = "$message: ${response.reasonPhrase}"; |
| 159 } | 159 } |
| 160 throw new HttpException("$message."); | 160 throw new HttpException("$message."); |
| 161 } | 161 } |
| 162 | 162 |
| 163 /// Closes the client and cleans up any resources associated with it. It's | 163 /// Closes the client and cleans up any resources associated with it. It's |
| 164 /// important to close each client when it's done being used; failing to do so | 164 /// important to close each client when it's done being used; failing to do so |
| 165 /// can cause the Dart process to hang. | 165 /// can cause the Dart process to hang. |
| 166 void close() {} | 166 void close() {} |
| 167 } | 167 } |
| OLD | NEW |