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

Unified Diff: sdk/lib/io/http_parser.dart

Issue 172443002: Always present data from http through a view. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 6 years, 10 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: sdk/lib/io/http_parser.dart
diff --git a/sdk/lib/io/http_parser.dart b/sdk/lib/io/http_parser.dart
index 34aaee9685ae3feb06da98868b3316ea46528f85..4e3ede1d0be829e57ba573a1901bb873ef32cb85 100644
--- a/sdk/lib/io/http_parser.dart
+++ b/sdk/lib/io/http_parser.dart
@@ -739,21 +739,15 @@ class _HttpParser extends Stream<_HttpIncoming> {
// The body is not handled one byte at a time but in blocks.
_index--;
int dataAvailable = _buffer.length - _index;
- List<int> data;
- if (_remainingContent == -1 ||
- dataAvailable <= _remainingContent) {
- if (_index == 0) {
- data = _buffer;
- } else {
- data = new Uint8List.view(_buffer.buffer,
- _index,
- dataAvailable);
- }
- } else {
- data = new Uint8List.view(_buffer.buffer,
- _index,
- _remainingContent);
+ if (_remainingContent >= 0 && dataAvailable > _remainingContent) {
+ dataAvailable = _remainingContent;
}
+ // Always present the data as a view. This way we can handle all
+ // cases like this, and the user will not experince different data
+ // typed (which could lead to polymorphic user code).
+ List<int> data = new Uint8List.view(_buffer.buffer,
+ _buffer.offsetInBytes + _index,
+ dataAvailable);
_bodyController.add(data);
if (_remainingContent != -1) {
_remainingContent -= data.length;
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698