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

Side by Side Diff: runtime/bin/http_impl.dart

Issue 10872033: Change getters syntax in dart:io library. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 8 years, 4 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 | « runtime/bin/http.dart ('k') | runtime/bin/http_parser.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 class _HttpHeaders implements HttpHeaders { 5 class _HttpHeaders implements HttpHeaders {
6 _HttpHeaders() : _headers = new Map<String, List<String>>(); 6 _HttpHeaders() : _headers = new Map<String, List<String>>();
7 7
8 List<String> operator[](String name) { 8 List<String> operator[](String name) {
9 name = name.toLowerCase(); 9 name = name.toLowerCase();
10 return _headers[name]; 10 return _headers[name];
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after
58 58
59 void forEach(void f(String name, List<String> values)) { 59 void forEach(void f(String name, List<String> values)) {
60 _headers.forEach(f); 60 _headers.forEach(f);
61 } 61 }
62 62
63 void noFolding(String name) { 63 void noFolding(String name) {
64 if (_noFoldingHeaders == null) _noFoldingHeaders = new List<String>(); 64 if (_noFoldingHeaders == null) _noFoldingHeaders = new List<String>();
65 _noFoldingHeaders.add(name); 65 _noFoldingHeaders.add(name);
66 } 66 }
67 67
68 String get host() => _host; 68 String get host => _host;
69 69
70 void set host(String host) { 70 void set host(String host) {
71 _checkMutable(); 71 _checkMutable();
72 _host = host; 72 _host = host;
73 _updateHostHeader(); 73 _updateHostHeader();
74 } 74 }
75 75
76 int get port() => _port; 76 int get port => _port;
77 77
78 void set port(int port) { 78 void set port(int port) {
79 _checkMutable(); 79 _checkMutable();
80 _port = port; 80 _port = port;
81 _updateHostHeader(); 81 _updateHostHeader();
82 } 82 }
83 83
84 Date get ifModifiedSince() { 84 Date get ifModifiedSince {
85 List<String> values = _headers["if-modified-since"]; 85 List<String> values = _headers["if-modified-since"];
86 if (values != null) { 86 if (values != null) {
87 try { 87 try {
88 return _HttpUtils.parseDate(values[0]); 88 return _HttpUtils.parseDate(values[0]);
89 } catch (Exception e) { 89 } catch (Exception e) {
90 return null; 90 return null;
91 } 91 }
92 } 92 }
93 return null; 93 return null;
94 } 94 }
95 95
96 void set ifModifiedSince(Date ifModifiedSince) { 96 void set ifModifiedSince(Date ifModifiedSince) {
97 _checkMutable(); 97 _checkMutable();
98 // Format "ifModifiedSince" header with date in Greenwich Mean Time (GMT). 98 // Format "ifModifiedSince" header with date in Greenwich Mean Time (GMT).
99 String formatted = _HttpUtils.formatDate(ifModifiedSince.toUtc()); 99 String formatted = _HttpUtils.formatDate(ifModifiedSince.toUtc());
100 _set("if-modified-since", formatted); 100 _set("if-modified-since", formatted);
101 } 101 }
102 102
103 Date get date() { 103 Date get date {
104 List<String> values = _headers["date"]; 104 List<String> values = _headers["date"];
105 if (values != null) { 105 if (values != null) {
106 try { 106 try {
107 return _HttpUtils.parseDate(values[0]); 107 return _HttpUtils.parseDate(values[0]);
108 } catch (Exception e) { 108 } catch (Exception e) {
109 return null; 109 return null;
110 } 110 }
111 } 111 }
112 return null; 112 return null;
113 } 113 }
114 114
115 void set date(Date date) { 115 void set date(Date date) {
116 _checkMutable(); 116 _checkMutable();
117 // Format "Date" header with date in Greenwich Mean Time (GMT). 117 // Format "Date" header with date in Greenwich Mean Time (GMT).
118 String formatted = _HttpUtils.formatDate(date.toUtc()); 118 String formatted = _HttpUtils.formatDate(date.toUtc());
119 _set("date", formatted); 119 _set("date", formatted);
120 } 120 }
121 121
122 Date get expires() { 122 Date get expires {
123 List<String> values = _headers["expires"]; 123 List<String> values = _headers["expires"];
124 if (values != null) { 124 if (values != null) {
125 try { 125 try {
126 return _HttpUtils.parseDate(values[0]); 126 return _HttpUtils.parseDate(values[0]);
127 } catch (Exception e) { 127 } catch (Exception e) {
128 return null; 128 return null;
129 } 129 }
130 } 130 }
131 return null; 131 return null;
132 } 132 }
133 133
134 void set expires(Date expires) { 134 void set expires(Date expires) {
135 _checkMutable(); 135 _checkMutable();
136 // Format "Expires" header with date in Greenwich Mean Time (GMT). 136 // Format "Expires" header with date in Greenwich Mean Time (GMT).
137 String formatted = _HttpUtils.formatDate(expires.toUtc()); 137 String formatted = _HttpUtils.formatDate(expires.toUtc());
138 _set("expires", formatted); 138 _set("expires", formatted);
139 } 139 }
140 140
141 ContentType get contentType() { 141 ContentType get contentType {
142 var values = _headers["content-type"]; 142 var values = _headers["content-type"];
143 if (values != null) { 143 if (values != null) {
144 return new ContentType.fromString(values[0]); 144 return new ContentType.fromString(values[0]);
145 } else { 145 } else {
146 return new ContentType(); 146 return new ContentType();
147 } 147 }
148 } 148 }
149 149
150 void set contentType(ContentType contentType) { 150 void set contentType(ContentType contentType) {
151 _checkMutable(); 151 _checkMutable();
(...skipping 154 matching lines...) Expand 10 before | Expand all | Expand 10 after
306 306
307 307
308 class _HeaderValue implements HeaderValue { 308 class _HeaderValue implements HeaderValue {
309 _HeaderValue([String this.value = ""]); 309 _HeaderValue([String this.value = ""]);
310 310
311 _HeaderValue.fromString(String value) { 311 _HeaderValue.fromString(String value) {
312 // Parse the string. 312 // Parse the string.
313 _parse(value); 313 _parse(value);
314 } 314 }
315 315
316 Map<String, String> get parameters() { 316 Map<String, String> get parameters {
317 if (_parameters == null) _parameters = new Map<String, String>(); 317 if (_parameters == null) _parameters = new Map<String, String>();
318 return _parameters; 318 return _parameters;
319 } 319 }
320 320
321 String toString() { 321 String toString() {
322 StringBuffer sb = new StringBuffer(); 322 StringBuffer sb = new StringBuffer();
323 sb.add(value); 323 sb.add(value);
324 if (parameters != null && parameters.length > 0) { 324 if (parameters != null && parameters.length > 0) {
325 _parameters.forEach((String name, String value) { 325 _parameters.forEach((String name, String value) {
326 sb.add("; "); 326 sb.add("; ");
(...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after
424 String value; 424 String value;
425 Map<String, String> _parameters; 425 Map<String, String> _parameters;
426 } 426 }
427 427
428 428
429 class _ContentType extends _HeaderValue implements ContentType { 429 class _ContentType extends _HeaderValue implements ContentType {
430 _ContentType([String this._primaryType = "", String this._subType = ""]); 430 _ContentType([String this._primaryType = "", String this._subType = ""]);
431 431
432 _ContentType.fromString(String value) : super.fromString(value); 432 _ContentType.fromString(String value) : super.fromString(value);
433 433
434 String get value() => "$_primaryType/$_subType"; 434 String get value => "$_primaryType/$_subType";
435 435
436 void set value(String s) { 436 void set value(String s) {
437 int index = s.indexOf("/"); 437 int index = s.indexOf("/");
438 if (index == -1 || index == (s.length - 1)) { 438 if (index == -1 || index == (s.length - 1)) {
439 primaryType = s.trim().toLowerCase(); 439 primaryType = s.trim().toLowerCase();
440 subType = ""; 440 subType = "";
441 } else { 441 } else {
442 primaryType = s.substring(0, index).trim().toLowerCase(); 442 primaryType = s.substring(0, index).trim().toLowerCase();
443 subType = s.substring(index + 1).trim().toLowerCase(); 443 subType = s.substring(index + 1).trim().toLowerCase();
444 } 444 }
445 } 445 }
446 446
447 String get primaryType() => _primaryType; 447 String get primaryType => _primaryType;
448 448
449 void set primaryType(String s) { 449 void set primaryType(String s) {
450 _primaryType = s; 450 _primaryType = s;
451 } 451 }
452 452
453 String get subType() => _subType; 453 String get subType => _subType;
454 454
455 void set subType(String s) { 455 void set subType(String s) {
456 _subType = s; 456 _subType = s;
457 } 457 }
458 458
459 String get charset() => parameters["charset"]; 459 String get charset => parameters["charset"];
460 460
461 void set charset(String s) { 461 void set charset(String s) {
462 parameters["charset"] = s; 462 parameters["charset"] = s;
463 } 463 }
464 464
465 String _primaryType = ""; 465 String _primaryType = "";
466 String _subType = ""; 466 String _subType = "";
467 } 467 }
468 468
469 469
(...skipping 133 matching lines...) Expand 10 before | Expand all | Expand 10 after
603 final int HEADER_SENT = 1; 603 final int HEADER_SENT = 1;
604 final int DONE = 2; 604 final int DONE = 2;
605 final int UPGRADED = 3; 605 final int UPGRADED = 3;
606 606
607 _HttpRequestResponseBase(_HttpConnectionBase this._httpConnection) 607 _HttpRequestResponseBase(_HttpConnectionBase this._httpConnection)
608 : _headers = new _HttpHeaders() { 608 : _headers = new _HttpHeaders() {
609 _state = START; 609 _state = START;
610 _headResponse = false; 610 _headResponse = false;
611 } 611 }
612 612
613 int get contentLength() => _contentLength; 613 int get contentLength => _contentLength;
614 HttpHeaders get headers() => _headers; 614 HttpHeaders get headers => _headers;
615 615
616 bool get persistentConnection() { 616 bool get persistentConnection {
617 List<String> connection = headers[HttpHeaders.CONNECTION]; 617 List<String> connection = headers[HttpHeaders.CONNECTION];
618 if (_protocolVersion == "1.1") { 618 if (_protocolVersion == "1.1") {
619 if (connection == null) return true; 619 if (connection == null) return true;
620 return !headers[HttpHeaders.CONNECTION].some( 620 return !headers[HttpHeaders.CONNECTION].some(
621 (value) => value.toLowerCase() == "close"); 621 (value) => value.toLowerCase() == "close");
622 } else { 622 } else {
623 if (connection == null) return false; 623 if (connection == null) return false;
624 return headers[HttpHeaders.CONNECTION].some( 624 return headers[HttpHeaders.CONNECTION].some(
625 (value) => value.toLowerCase() == "keep-alive"); 625 (value) => value.toLowerCase() == "keep-alive");
626 } 626 }
(...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after
731 } 731 }
732 } 732 }
733 733
734 void _updateContentLength(int bytes) { 734 void _updateContentLength(int bytes) {
735 if (_bodyBytesWritten + bytes > _contentLength) { 735 if (_bodyBytesWritten + bytes > _contentLength) {
736 throw new HttpException("Writing more than specified content length"); 736 throw new HttpException("Writing more than specified content length");
737 } 737 }
738 _bodyBytesWritten += bytes; 738 _bodyBytesWritten += bytes;
739 } 739 }
740 740
741 HttpConnectionInfo get connectionInfo() => _httpConnection.connectionInfo; 741 HttpConnectionInfo get connectionInfo => _httpConnection.connectionInfo;
742 742
743 bool get _done() => _state == DONE; 743 bool get _done => _state == DONE;
744 744
745 int _state; 745 int _state;
746 bool _headResponse; 746 bool _headResponse;
747 747
748 _HttpConnectionBase _httpConnection; 748 _HttpConnectionBase _httpConnection;
749 _HttpHeaders _headers; 749 _HttpHeaders _headers;
750 List<Cookie> _cookies; 750 List<Cookie> _cookies;
751 String _protocolVersion = "1.1"; 751 String _protocolVersion = "1.1";
752 752
753 // Length of the content body. If this is set to -1 (default value) 753 // Length of the content body. If this is set to -1 (default value)
754 // when starting to send data chunked transfer encoding will be 754 // when starting to send data chunked transfer encoding will be
755 // used. 755 // used.
756 int _contentLength = -1; 756 int _contentLength = -1;
757 // Number of body bytes written. This is only actual body data not 757 // Number of body bytes written. This is only actual body data not
758 // including headers or chunk information of using chinked transfer 758 // including headers or chunk information of using chinked transfer
759 // encoding. 759 // encoding.
760 int _bodyBytesWritten = 0; 760 int _bodyBytesWritten = 0;
761 } 761 }
762 762
763 763
764 // Parsed HTTP request providing information on the HTTP headers. 764 // Parsed HTTP request providing information on the HTTP headers.
765 class _HttpRequest extends _HttpRequestResponseBase implements HttpRequest { 765 class _HttpRequest extends _HttpRequestResponseBase implements HttpRequest {
766 _HttpRequest(_HttpConnection connection) : super(connection); 766 _HttpRequest(_HttpConnection connection) : super(connection);
767 767
768 String get method() => _method; 768 String get method => _method;
769 String get uri() => _uri; 769 String get uri => _uri;
770 String get path() => _path; 770 String get path => _path;
771 String get queryString() => _queryString; 771 String get queryString => _queryString;
772 Map get queryParameters() => _queryParameters; 772 Map get queryParameters => _queryParameters;
773 773
774 List<Cookie> get cookies() { 774 List<Cookie> get cookies {
775 if (_cookies != null) return _cookies; 775 if (_cookies != null) return _cookies;
776 776
777 // Parse a Cookie header value according to the rules in RFC 6265. 777 // Parse a Cookie header value according to the rules in RFC 6265.
778 void _parseCookieString(String s) { 778 void _parseCookieString(String s) {
779 int index = 0; 779 int index = 0;
780 780
781 bool done() => index == s.length; 781 bool done() => index == s.length;
782 782
783 void skipWS() { 783 void skipWS() {
784 while (!done()) { 784 while (!done()) {
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after
831 } 831 }
832 832
833 _cookies = new List<Cookie>(); 833 _cookies = new List<Cookie>();
834 List<String> headerValues = headers["cookie"]; 834 List<String> headerValues = headers["cookie"];
835 if (headerValues != null) { 835 if (headerValues != null) {
836 headerValues.forEach((headerValue) => _parseCookieString(headerValue)); 836 headerValues.forEach((headerValue) => _parseCookieString(headerValue));
837 } 837 }
838 return _cookies; 838 return _cookies;
839 } 839 }
840 840
841 InputStream get inputStream() { 841 InputStream get inputStream {
842 if (_inputStream == null) { 842 if (_inputStream == null) {
843 _inputStream = new _HttpInputStream(this); 843 _inputStream = new _HttpInputStream(this);
844 } 844 }
845 return _inputStream; 845 return _inputStream;
846 } 846 }
847 847
848 String get protocolVersion() => _protocolVersion; 848 String get protocolVersion => _protocolVersion;
849 849
850 void _onRequestStart(String method, String uri, String version) { 850 void _onRequestStart(String method, String uri, String version) {
851 _method = method; 851 _method = method;
852 _uri = uri; 852 _uri = uri;
853 _parseRequestUri(uri); 853 _parseRequestUri(uri);
854 } 854 }
855 855
856 void _onHeaderReceived(String name, String value) { 856 void _onHeaderReceived(String name, String value) {
857 _headers.add(name, value); 857 _headers.add(name, value);
858 } 858 }
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after
920 class _HttpResponse extends _HttpRequestResponseBase implements HttpResponse { 920 class _HttpResponse extends _HttpRequestResponseBase implements HttpResponse {
921 _HttpResponse(_HttpConnection httpConnection) 921 _HttpResponse(_HttpConnection httpConnection)
922 : super(httpConnection), 922 : super(httpConnection),
923 _statusCode = HttpStatus.OK; 923 _statusCode = HttpStatus.OK;
924 924
925 void set contentLength(int contentLength) { 925 void set contentLength(int contentLength) {
926 if (_state >= HEADER_SENT) throw new HttpException("Header already sent"); 926 if (_state >= HEADER_SENT) throw new HttpException("Header already sent");
927 _contentLength = contentLength; 927 _contentLength = contentLength;
928 } 928 }
929 929
930 int get statusCode() => _statusCode; 930 int get statusCode => _statusCode;
931 void set statusCode(int statusCode) { 931 void set statusCode(int statusCode) {
932 if (_outputStream != null) throw new HttpException("Header already sent"); 932 if (_outputStream != null) throw new HttpException("Header already sent");
933 _statusCode = statusCode; 933 _statusCode = statusCode;
934 } 934 }
935 935
936 String get reasonPhrase() => _findReasonPhrase(_statusCode); 936 String get reasonPhrase => _findReasonPhrase(_statusCode);
937 void set reasonPhrase(String reasonPhrase) { 937 void set reasonPhrase(String reasonPhrase) {
938 if (_outputStream != null) throw new HttpException("Header already sent"); 938 if (_outputStream != null) throw new HttpException("Header already sent");
939 _reasonPhrase = reasonPhrase; 939 _reasonPhrase = reasonPhrase;
940 } 940 }
941 941
942 List<Cookie> get cookies() { 942 List<Cookie> get cookies {
943 if (_cookies == null) _cookies = new List<Cookie>(); 943 if (_cookies == null) _cookies = new List<Cookie>();
944 return _cookies; 944 return _cookies;
945 } 945 }
946 946
947 OutputStream get outputStream() { 947 OutputStream get outputStream {
948 if (_state >= DONE) throw new HttpException("Response closed"); 948 if (_state >= DONE) throw new HttpException("Response closed");
949 if (_outputStream == null) { 949 if (_outputStream == null) {
950 _outputStream = new _HttpOutputStream(this); 950 _outputStream = new _HttpOutputStream(this);
951 } 951 }
952 return _outputStream; 952 return _outputStream;
953 } 953 }
954 954
955 DetachedSocket detachSocket() { 955 DetachedSocket detachSocket() {
956 if (_state >= DONE) throw new HttpException("Response closed"); 956 if (_state >= DONE) throw new HttpException("Response closed");
957 // Ensure that headers are written. 957 // Ensure that headers are written.
(...skipping 205 matching lines...) Expand 10 before | Expand all | Expand 10 after
1163 } 1163 }
1164 1164
1165 bool writeFrom(List<int> buffer, [int offset = 0, int len]) { 1165 bool writeFrom(List<int> buffer, [int offset = 0, int len]) {
1166 return _requestOrResponse._streamWriteFrom(buffer, offset, len); 1166 return _requestOrResponse._streamWriteFrom(buffer, offset, len);
1167 } 1167 }
1168 1168
1169 void close() { 1169 void close() {
1170 _requestOrResponse._streamClose(); 1170 _requestOrResponse._streamClose();
1171 } 1171 }
1172 1172
1173 bool get closed() => _requestOrResponse._done; 1173 bool get closed => _requestOrResponse._done;
1174 1174
1175 void destroy() { 1175 void destroy() {
1176 throw "Not implemented"; 1176 throw "Not implemented";
1177 } 1177 }
1178 1178
1179 void set onNoPendingWrites(void callback()) { 1179 void set onNoPendingWrites(void callback()) {
1180 _requestOrResponse._streamSetNoPendingWriteHandler(callback); 1180 _requestOrResponse._streamSetNoPendingWriteHandler(callback);
1181 } 1181 }
1182 1182
1183 void set onClosed(void callback()) { 1183 void set onClosed(void callback()) {
(...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after
1271 _socket.onData = null; 1271 _socket.onData = null;
1272 _socket.onClosed = null; 1272 _socket.onClosed = null;
1273 _socket.onError = null; 1273 _socket.onError = null;
1274 _socket.outputStream.onNoPendingWrites = null; 1274 _socket.outputStream.onNoPendingWrites = null;
1275 Socket socket = _socket; 1275 Socket socket = _socket;
1276 _socket = null; 1276 _socket = null;
1277 if (onDetach != null) onDetach(); 1277 if (onDetach != null) onDetach();
1278 return new _DetachedSocket(socket, _httpParser.unparsedData); 1278 return new _DetachedSocket(socket, _httpParser.unparsedData);
1279 } 1279 }
1280 1280
1281 HttpConnectionInfo get connectionInfo() { 1281 HttpConnectionInfo get connectionInfo {
1282 if (_socket == null || _closing || _error) return null; 1282 if (_socket == null || _closing || _error) return null;
1283 try { 1283 try {
1284 _HttpConnectionInfo info = new _HttpConnectionInfo(); 1284 _HttpConnectionInfo info = new _HttpConnectionInfo();
1285 info.remoteHost = _socket.remoteHost; 1285 info.remoteHost = _socket.remoteHost;
1286 info.remotePort = _socket.remotePort; 1286 info.remotePort = _socket.remotePort;
1287 info.localPort = _socket.port; 1287 info.localPort = _socket.port;
1288 return info; 1288 return info;
1289 } catch (var e) { } 1289 } catch (var e) { }
1290 return null; 1290 return null;
1291 } 1291 }
(...skipping 182 matching lines...) Expand 10 before | Expand all | Expand 10 after
1474 if (_server !== null && _closeServer) { 1474 if (_server !== null && _closeServer) {
1475 _server.close(); 1475 _server.close();
1476 } 1476 }
1477 _server = null; 1477 _server = null;
1478 for (_HttpConnection connection in _connections) { 1478 for (_HttpConnection connection in _connections) {
1479 connection._destroy(); 1479 connection._destroy();
1480 } 1480 }
1481 _connections.clear(); 1481 _connections.clear();
1482 } 1482 }
1483 1483
1484 int get port() { 1484 int get port {
1485 if (_server === null) { 1485 if (_server === null) {
1486 throw new HttpException("The HttpServer is not listening on a port."); 1486 throw new HttpException("The HttpServer is not listening on a port.");
1487 } 1487 }
1488 return _server.port; 1488 return _server.port;
1489 } 1489 }
1490 1490
1491 void set onError(void callback(e)) { 1491 void set onError(void callback(e)) {
1492 _onError = callback; 1492 _onError = callback;
1493 } 1493 }
1494 1494
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after
1539 if (_method == "GET" || _method == "HEAD") { 1539 if (_method == "GET" || _method == "HEAD") {
1540 _contentLength = 0; 1540 _contentLength = 0;
1541 } 1541 }
1542 } 1542 }
1543 1543
1544 void set contentLength(int contentLength) { 1544 void set contentLength(int contentLength) {
1545 if (_state >= HEADER_SENT) throw new HttpException("Header already sent"); 1545 if (_state >= HEADER_SENT) throw new HttpException("Header already sent");
1546 _contentLength = contentLength; 1546 _contentLength = contentLength;
1547 } 1547 }
1548 1548
1549 List<Cookie> get cookies() { 1549 List<Cookie> get cookies {
1550 if (_cookies == null) _cookies = new List<Cookie>(); 1550 if (_cookies == null) _cookies = new List<Cookie>();
1551 return _cookies; 1551 return _cookies;
1552 } 1552 }
1553 1553
1554 OutputStream get outputStream() { 1554 OutputStream get outputStream {
1555 if (_done) throw new HttpException("Request closed"); 1555 if (_done) throw new HttpException("Request closed");
1556 if (_outputStream == null) { 1556 if (_outputStream == null) {
1557 _outputStream = new _HttpOutputStream(this); 1557 _outputStream = new _HttpOutputStream(this);
1558 } 1558 }
1559 return _outputStream; 1559 return _outputStream;
1560 } 1560 }
1561 1561
1562 // Delegate functions for the HttpOutputStream implementation. 1562 // Delegate functions for the HttpOutputStream implementation.
1563 bool _streamWrite(List<int> buffer, bool copyBuffer) { 1563 bool _streamWrite(List<int> buffer, bool copyBuffer) {
1564 if (_done) throw new HttpException("Request closed"); 1564 if (_done) throw new HttpException("Request closed");
(...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after
1640 } 1640 }
1641 1641
1642 1642
1643 class _HttpClientResponse 1643 class _HttpClientResponse
1644 extends _HttpRequestResponseBase implements HttpClientResponse { 1644 extends _HttpRequestResponseBase implements HttpClientResponse {
1645 _HttpClientResponse(_HttpClientConnection connection) 1645 _HttpClientResponse(_HttpClientConnection connection)
1646 : super(connection) { 1646 : super(connection) {
1647 _connection = connection; 1647 _connection = connection;
1648 } 1648 }
1649 1649
1650 int get statusCode() => _statusCode; 1650 int get statusCode => _statusCode;
1651 String get reasonPhrase() => _reasonPhrase; 1651 String get reasonPhrase => _reasonPhrase;
1652 1652
1653 bool get isRedirect() { 1653 bool get isRedirect {
1654 return statusCode == HttpStatus.MOVED_PERMANENTLY || 1654 return statusCode == HttpStatus.MOVED_PERMANENTLY ||
1655 statusCode == HttpStatus.FOUND || 1655 statusCode == HttpStatus.FOUND ||
1656 statusCode == HttpStatus.SEE_OTHER || 1656 statusCode == HttpStatus.SEE_OTHER ||
1657 statusCode == HttpStatus.TEMPORARY_REDIRECT; 1657 statusCode == HttpStatus.TEMPORARY_REDIRECT;
1658 } 1658 }
1659 1659
1660 List<Cookie> get cookies() { 1660 List<Cookie> get cookies {
1661 if (_cookies != null) return _cookies; 1661 if (_cookies != null) return _cookies;
1662 _cookies = new List<Cookie>(); 1662 _cookies = new List<Cookie>();
1663 List<String> values = _headers["set-cookie"]; 1663 List<String> values = _headers["set-cookie"];
1664 if (values != null) { 1664 if (values != null) {
1665 values.forEach((value) { 1665 values.forEach((value) {
1666 _cookies.add(new Cookie.fromSetCookieValue(value)); 1666 _cookies.add(new Cookie.fromSetCookieValue(value));
1667 }); 1667 });
1668 } 1668 }
1669 return _cookies; 1669 return _cookies;
1670 } 1670 }
1671 1671
1672 InputStream get inputStream() { 1672 InputStream get inputStream {
1673 if (_inputStream == null) { 1673 if (_inputStream == null) {
1674 _inputStream = new _HttpInputStream(this); 1674 _inputStream = new _HttpInputStream(this);
1675 } 1675 }
1676 return _inputStream; 1676 return _inputStream;
1677 } 1677 }
1678 1678
1679 void _onRequestStart(String method, String uri, String version) { 1679 void _onRequestStart(String method, String uri, String version) {
1680 // TODO(sgjesse): Error handling 1680 // TODO(sgjesse): Error handling
1681 } 1681 }
1682 1682
(...skipping 199 matching lines...) Expand 10 before | Expand all | Expand 10 after
1882 if (_redirects == null) { 1882 if (_redirects == null) {
1883 _redirects = new List<_RedirectInfo>(); 1883 _redirects = new List<_RedirectInfo>();
1884 } 1884 }
1885 _redirects.add(new _RedirectInfo(_response.statusCode, method, url)); 1885 _redirects.add(new _RedirectInfo(_response.statusCode, method, url));
1886 _request = null; 1886 _request = null;
1887 _response = null; 1887 _response = null;
1888 // Open redirect URL using the same connection instance. 1888 // Open redirect URL using the same connection instance.
1889 _client._openUrl(method, url, this); 1889 _client._openUrl(method, url, this);
1890 } 1890 }
1891 1891
1892 List<RedirectInfo> get redirects() => _redirects; 1892 List<RedirectInfo> get redirects => _redirects;
1893 1893
1894 Function _onRequest; 1894 Function _onRequest;
1895 Function _onResponse; 1895 Function _onResponse;
1896 Function _onErrorCallback; 1896 Function _onErrorCallback;
1897 1897
1898 _HttpClient _client; 1898 _HttpClient _client;
1899 _SocketConnection _socketConn; 1899 _SocketConnection _socketConn;
1900 HttpClientRequest _request; 1900 HttpClientRequest _request;
1901 HttpClientResponse _response; 1901 HttpClientResponse _response;
1902 String _method; 1902 String _method;
(...skipping 248 matching lines...) Expand 10 before | Expand all | Expand 10 after
2151 2151
2152 class _HttpConnectionInfo implements HttpConnectionInfo { 2152 class _HttpConnectionInfo implements HttpConnectionInfo {
2153 String remoteHost; 2153 String remoteHost;
2154 int remotePort; 2154 int remotePort;
2155 int localPort; 2155 int localPort;
2156 } 2156 }
2157 2157
2158 2158
2159 class _DetachedSocket implements DetachedSocket { 2159 class _DetachedSocket implements DetachedSocket {
2160 _DetachedSocket(this._socket, this._unparsedData); 2160 _DetachedSocket(this._socket, this._unparsedData);
2161 Socket get socket() => _socket; 2161 Socket get socket => _socket;
2162 List<int> get unparsedData() => _unparsedData; 2162 List<int> get unparsedData => _unparsedData;
2163 Socket _socket; 2163 Socket _socket;
2164 List<int> _unparsedData; 2164 List<int> _unparsedData;
2165 } 2165 }
2166 2166
2167 2167
2168 class _RedirectInfo implements RedirectInfo { 2168 class _RedirectInfo implements RedirectInfo {
2169 const _RedirectInfo(int this.statusCode, 2169 const _RedirectInfo(int this.statusCode,
2170 String this.method, 2170 String this.method,
2171 Uri this.location); 2171 Uri this.location);
2172 final int statusCode; 2172 final int statusCode;
2173 final String method; 2173 final String method;
2174 final Uri location; 2174 final Uri location;
2175 } 2175 }
OLDNEW
« no previous file with comments | « runtime/bin/http.dart ('k') | runtime/bin/http_parser.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698