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

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

Issue 11825010: Update pkg/http to use the new async APIs. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Code review changes Created 7 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
« no previous file with comments | « pkg/http/lib/src/request.dart ('k') | pkg/http/lib/src/streamed_request.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 response; 5 library response;
6 6
7 import 'dart:async'; 7 import 'dart:async';
8 import 'dart:io'; 8 import 'dart:io';
9 import 'dart:scalarlist'; 9 import 'dart:scalarlist';
10 10
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after
59 bodyBytes.length, 59 bodyBytes.length,
60 request: request, 60 request: request,
61 headers: headers, 61 headers: headers,
62 isRedirect: isRedirect, 62 isRedirect: isRedirect,
63 persistentConnection: persistentConnection, 63 persistentConnection: persistentConnection,
64 reasonPhrase: reasonPhrase); 64 reasonPhrase: reasonPhrase);
65 65
66 /// Creates a new HTTP response by waiting for the full body to become 66 /// Creates a new HTTP response by waiting for the full body to become
67 /// available from a [StreamedResponse]. 67 /// available from a [StreamedResponse].
68 static Future<Response> fromStream(StreamedResponse response) { 68 static Future<Response> fromStream(StreamedResponse response) {
69 return consumeInputStream(response.stream).then((body) { 69 return response.stream.toBytes().then((body) {
70 return new Response.bytes( 70 return new Response.bytes(
71 body, 71 body,
72 response.statusCode, 72 response.statusCode,
73 request: response.request, 73 request: response.request,
74 headers: response.headers, 74 headers: response.headers,
75 isRedirect: response.isRedirect, 75 isRedirect: response.isRedirect,
76 persistentConnection: response.persistentConnection, 76 persistentConnection: response.persistentConnection,
77 reasonPhrase: response.reasonPhrase); 77 reasonPhrase: response.reasonPhrase);
78 }); 78 });
79 } 79 }
80 } 80 }
81 81
82 /// Returns the encoding to use for a response with the given headers. This 82 /// Returns the encoding to use for a response with the given headers. This
83 /// defaults to [Encoding.ISO_8859_1] if the headers don't specify a charset or 83 /// defaults to [Encoding.ISO_8859_1] if the headers don't specify a charset or
84 /// if that charset is unknown. 84 /// if that charset is unknown.
85 Encoding _encodingForHeaders(Map<String, String> headers) => 85 Encoding _encodingForHeaders(Map<String, String> headers) =>
86 encodingForCharset(_contentTypeForHeaders(headers).charset); 86 encodingForCharset(_contentTypeForHeaders(headers).charset);
87 87
88 /// Returns the [ContentType] object for the given headers. Defaults to 88 /// Returns the [ContentType] object for the given headers. Defaults to
89 /// `application/octet-stream`. 89 /// `application/octet-stream`.
90 ContentType _contentTypeForHeaders(Map<String, String> headers) { 90 ContentType _contentTypeForHeaders(Map<String, String> headers) {
91 var contentType = headers[HttpHeaders.CONTENT_TYPE]; 91 var contentType = headers[HttpHeaders.CONTENT_TYPE];
92 if (contentType != null) return new ContentType.fromString(contentType); 92 if (contentType != null) return new ContentType.fromString(contentType);
93 return new ContentType("application", "octet-stream"); 93 return new ContentType("application", "octet-stream");
94 } 94 }
OLDNEW
« no previous file with comments | « pkg/http/lib/src/request.dart ('k') | pkg/http/lib/src/streamed_request.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698