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

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

Issue 48283002: Throw exception when trying to modify HTTP status code when header is already sent (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 7 years, 1 month 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_headers_state_test.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 679 matching lines...) Expand 10 before | Expand all | Expand 10 after
690 Stream<List<int>> bind(Stream<List<int>> stream) { 690 Stream<List<int>> bind(Stream<List<int>> stream) {
691 return new Stream<List<int>>.eventTransformed( 691 return new Stream<List<int>>.eventTransformed(
692 stream, 692 stream,
693 (EventSink outSink) => new _BufferTransformerSink(outSink)); 693 (EventSink outSink) => new _BufferTransformerSink(outSink));
694 } 694 }
695 } 695 }
696 696
697 697
698 class _HttpResponse extends _HttpOutboundMessage<HttpResponse> 698 class _HttpResponse extends _HttpOutboundMessage<HttpResponse>
699 implements HttpResponse { 699 implements HttpResponse {
700 int statusCode = 200; 700 int _statusCode = 200;
701 String _reasonPhrase; 701 String _reasonPhrase;
702 List<Cookie> _cookies; 702 List<Cookie> _cookies;
703 _HttpRequest _httpRequest; 703 _HttpRequest _httpRequest;
704 Duration _deadline; 704 Duration _deadline;
705 Timer _deadlineTimer; 705 Timer _deadlineTimer;
706 706
707 _HttpResponse(Uri uri, 707 _HttpResponse(Uri uri,
708 String protocolVersion, 708 String protocolVersion,
709 _HttpOutgoing outgoing, 709 _HttpOutgoing outgoing,
710 String serverHeader) 710 String serverHeader)
711 : super(uri, protocolVersion, outgoing) { 711 : super(uri, protocolVersion, outgoing) {
712 if (serverHeader != null) headers.set('Server', serverHeader); 712 if (serverHeader != null) headers.set('Server', serverHeader);
713 } 713 }
714 714
715 List<Cookie> get cookies { 715 List<Cookie> get cookies {
716 if (_cookies == null) _cookies = new List<Cookie>(); 716 if (_cookies == null) _cookies = new List<Cookie>();
717 return _cookies; 717 return _cookies;
718 } 718 }
719 719
720 int get statusCode => _statusCode;
721 void set statusCode(int statusCode) {
722 if (_headersWritten) throw new StateError("Header already sent");
723 _statusCode = statusCode;
724 }
725
720 String get reasonPhrase => _findReasonPhrase(statusCode); 726 String get reasonPhrase => _findReasonPhrase(statusCode);
721 void set reasonPhrase(String reasonPhrase) { 727 void set reasonPhrase(String reasonPhrase) {
722 if (_headersWritten) throw new StateError("Header already sent"); 728 if (_headersWritten) throw new StateError("Header already sent");
723 _reasonPhrase = reasonPhrase; 729 _reasonPhrase = reasonPhrase;
724 } 730 }
725 731
726 Future redirect(Uri location, {int status: HttpStatus.MOVED_TEMPORARILY}) { 732 Future redirect(Uri location, {int status: HttpStatus.MOVED_TEMPORARILY}) {
727 if (_headersWritten) throw new StateError("Header already sent"); 733 if (_headersWritten) throw new StateError("Header already sent");
728 statusCode = status; 734 statusCode = status;
729 headers.set("Location", location.toString()); 735 headers.set("Location", location.toString());
(...skipping 1775 matching lines...) Expand 10 before | Expand all | Expand 10 after
2505 final Uri location; 2511 final Uri location;
2506 } 2512 }
2507 2513
2508 String _getHttpVersion() { 2514 String _getHttpVersion() {
2509 var version = Platform.version; 2515 var version = Platform.version;
2510 // Only include major and minor version numbers. 2516 // Only include major and minor version numbers.
2511 int index = version.indexOf('.', version.indexOf('.') + 1); 2517 int index = version.indexOf('.', version.indexOf('.') + 1);
2512 version = version.substring(0, index); 2518 version = version.substring(0, index);
2513 return 'Dart/$version (dart:io)'; 2519 return 'Dart/$version (dart:io)';
2514 } 2520 }
OLDNEW
« no previous file with comments | « no previous file | tests/standalone/io/http_headers_state_test.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698