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

Side by Side Diff: sdk/lib/io/http_impl.dart

Issue 23479022: Make sure to never report SocketExceptions on HttpResponse. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 7 years, 3 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 | « no previous file | tests/standalone/io/http_server_close_response_after_error_client.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) 2013, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2013, 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 part of dart.io; 5 part of dart.io;
6 6
7 class _HttpIncoming extends Stream<List<int>> { 7 class _HttpIncoming extends Stream<List<int>> {
8 final int _transferLength; 8 final int _transferLength;
9 final Completer _dataCompleter = new Completer(); 9 final Completer _dataCompleter = new Completer();
10 Stream<List<int>> _stream; 10 Stream<List<int>> _stream;
(...skipping 552 matching lines...) Expand 10 before | Expand all | Expand 10 after
563 _HttpOutboundConsumer(_HttpOutboundMessage this._outbound); 563 _HttpOutboundConsumer(_HttpOutboundMessage this._outbound);
564 564
565 void _cancel() { 565 void _cancel() {
566 if (_subscription != null) { 566 if (_subscription != null) {
567 StreamSubscription subscription = _subscription; 567 StreamSubscription subscription = _subscription;
568 _subscription = null; 568 _subscription = null;
569 subscription.cancel(); 569 subscription.cancel();
570 } 570 }
571 } 571 }
572 572
573 bool _ignoreError(error)
574 => error is SocketException && _outbound is HttpResponse;
575
573 _ensureController() { 576 _ensureController() {
574 if (_controller != null) return; 577 if (_controller != null) return;
575 _controller = new StreamController(sync: true, 578 _controller = new StreamController(sync: true,
576 onPause: () => _subscription.pause(), 579 onPause: () => _subscription.pause(),
577 onResume: () => _subscription.resume(), 580 onResume: () => _subscription.resume(),
578 onListen: () => _subscription.resume(), 581 onListen: () => _subscription.resume(),
579 onCancel: _cancel); 582 onCancel: _cancel);
580 _outbound._addStream(_controller.stream) 583 _outbound._addStream(_controller.stream)
581 .then((_) { 584 .then((_) {
582 _cancel(); 585 _cancel();
583 _done(); 586 _done();
584 _closeCompleter.complete(_outbound); 587 _closeCompleter.complete(_outbound);
585 }, 588 },
586 onError: (error) { 589 onError: (error) {
587 _socketError = true; 590 _socketError = true;
588 if (error is SocketException && 591 if (_ignoreError(error)) {
589 _outbound is HttpResponse) {
590 _cancel(); 592 _cancel();
591 _done(); 593 _done();
592 _closeCompleter.complete(_outbound); 594 _closeCompleter.complete(_outbound);
593 } else { 595 } else {
594 if (!_done(error)) { 596 if (!_done(error)) {
595 _closeCompleter.completeError(error); 597 _closeCompleter.completeError(error);
596 } 598 }
597 } 599 }
598 }); 600 });
599 } 601 }
(...skipping 30 matching lines...) Expand all
630 cancelOnError: true); 632 cancelOnError: true);
631 // Pause the first request. 633 // Pause the first request.
632 if (_controller == null) _subscription.pause(); 634 if (_controller == null) _subscription.pause();
633 _ensureController(); 635 _ensureController();
634 return _completer.future; 636 return _completer.future;
635 } 637 }
636 638
637 Future close() { 639 Future close() {
638 Future closeOutbound() { 640 Future closeOutbound() {
639 if (_socketError) return new Future.value(_outbound); 641 if (_socketError) return new Future.value(_outbound);
640 return _outbound._close().then((_) => _outbound); 642 return _outbound._close()
643 .catchError((_) {}, test: _ignoreError)
644 .then((_) => _outbound);
641 } 645 }
642 if (_controller == null) return closeOutbound(); 646 if (_controller == null) return closeOutbound();
643 _controller.close(); 647 _controller.close();
644 return _closeCompleter.future.then((_) => closeOutbound()); 648 return _closeCompleter.future.then((_) => closeOutbound());
645 } 649 }
646 } 650 }
647 651
648 652
649 class _BufferTransformer extends StreamEventTransformer<List<int>, List<int>> { 653 class _BufferTransformer extends StreamEventTransformer<List<int>, List<int>> {
650 static const int MIN_CHUNK_SIZE = 4 * 1024; 654 static const int MIN_CHUNK_SIZE = 4 * 1024;
(...skipping 1815 matching lines...) Expand 10 before | Expand all | Expand 10 after
2466 final Uri location; 2470 final Uri location;
2467 } 2471 }
2468 2472
2469 String _getHttpVersion() { 2473 String _getHttpVersion() {
2470 var version = Platform.version; 2474 var version = Platform.version;
2471 // Only include major and minor version numbers. 2475 // Only include major and minor version numbers.
2472 int index = version.indexOf('.', version.indexOf('.') + 1); 2476 int index = version.indexOf('.', version.indexOf('.') + 1);
2473 version = version.substring(0, index); 2477 version = version.substring(0, index);
2474 return 'Dart/$version (dart:io)'; 2478 return 'Dart/$version (dart:io)';
2475 } 2479 }
OLDNEW
« no previous file with comments | « no previous file | tests/standalone/io/http_server_close_response_after_error_client.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698