OLD | NEW |
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 const int _HEADERS_BUFFER_SIZE = 8 * 1024; | 7 const int _HEADERS_BUFFER_SIZE = 8 * 1024; |
8 | 8 |
9 class _HttpIncoming extends Stream<List<int>> { | 9 class _HttpIncoming extends Stream<List<int>> { |
10 final int _transferLength; | 10 final int _transferLength; |
(...skipping 706 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
717 List<Cookie> _cookies; | 717 List<Cookie> _cookies; |
718 _HttpRequest _httpRequest; | 718 _HttpRequest _httpRequest; |
719 Duration _deadline; | 719 Duration _deadline; |
720 Timer _deadlineTimer; | 720 Timer _deadlineTimer; |
721 | 721 |
722 _HttpResponse(Uri uri, | 722 _HttpResponse(Uri uri, |
723 String protocolVersion, | 723 String protocolVersion, |
724 _HttpOutgoing outgoing, | 724 _HttpOutgoing outgoing, |
725 String serverHeader) | 725 String serverHeader) |
726 : super(uri, protocolVersion, outgoing) { | 726 : super(uri, protocolVersion, outgoing) { |
727 if (serverHeader != null) headers.set('Server', serverHeader); | 727 if (serverHeader != null) headers._add('server', serverHeader); |
728 } | 728 } |
729 | 729 |
730 List<Cookie> get cookies { | 730 List<Cookie> get cookies { |
731 if (_cookies == null) _cookies = new List<Cookie>(); | 731 if (_cookies == null) _cookies = new List<Cookie>(); |
732 return _cookies; | 732 return _cookies; |
733 } | 733 } |
734 | 734 |
735 int get statusCode => _statusCode; | 735 int get statusCode => _statusCode; |
736 void set statusCode(int statusCode) { | 736 void set statusCode(int statusCode) { |
737 if (_headersWritten) throw new StateError("Header already sent"); | 737 if (_headersWritten) throw new StateError("Header already sent"); |
738 _statusCode = statusCode; | 738 _statusCode = statusCode; |
739 } | 739 } |
740 | 740 |
741 String get reasonPhrase => _findReasonPhrase(statusCode); | 741 String get reasonPhrase => _findReasonPhrase(statusCode); |
742 void set reasonPhrase(String reasonPhrase) { | 742 void set reasonPhrase(String reasonPhrase) { |
743 if (_headersWritten) throw new StateError("Header already sent"); | 743 if (_headersWritten) throw new StateError("Header already sent"); |
744 _reasonPhrase = reasonPhrase; | 744 _reasonPhrase = reasonPhrase; |
745 } | 745 } |
746 | 746 |
747 Future redirect(Uri location, {int status: HttpStatus.MOVED_TEMPORARILY}) { | 747 Future redirect(Uri location, {int status: HttpStatus.MOVED_TEMPORARILY}) { |
748 if (_headersWritten) throw new StateError("Header already sent"); | 748 if (_headersWritten) throw new StateError("Header already sent"); |
749 statusCode = status; | 749 statusCode = status; |
750 headers.set("Location", location.toString()); | 750 headers.set("location", location.toString()); |
751 return close(); | 751 return close(); |
752 } | 752 } |
753 | 753 |
754 Future<Socket> detachSocket() { | 754 Future<Socket> detachSocket() { |
755 if (_headersWritten) throw new StateError("Headers already sent"); | 755 if (_headersWritten) throw new StateError("Headers already sent"); |
756 deadline = null; // Be sure to stop any deadline. | 756 deadline = null; // Be sure to stop any deadline. |
757 var future = _httpRequest._httpConnection.detachSocket(); | 757 var future = _httpRequest._httpConnection.detachSocket(); |
758 _writeHeaders(drainRequest: false).then((_) => close()); | 758 _writeHeaders(drainRequest: false).then((_) => close()); |
759 // Close connection so the socket is 'free'. | 759 // Close connection so the socket is 'free'. |
760 close(); | 760 close(); |
(...skipping 535 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1296 var outgoing = new _HttpOutgoing(_socket); | 1296 var outgoing = new _HttpOutgoing(_socket); |
1297 // Create new request object, wrapping the outgoing connection. | 1297 // Create new request object, wrapping the outgoing connection. |
1298 var request = new _HttpClientRequest(outgoing, | 1298 var request = new _HttpClientRequest(outgoing, |
1299 uri, | 1299 uri, |
1300 method, | 1300 method, |
1301 proxy, | 1301 proxy, |
1302 _httpClient, | 1302 _httpClient, |
1303 this); | 1303 this); |
1304 request.headers.host = uri.host; | 1304 request.headers.host = uri.host; |
1305 request.headers.port = port; | 1305 request.headers.port = port; |
1306 request.headers.set(HttpHeaders.ACCEPT_ENCODING, "gzip"); | 1306 request.headers._add(HttpHeaders.ACCEPT_ENCODING, "gzip"); |
1307 if (_httpClient.userAgent != null) { | 1307 if (_httpClient.userAgent != null) { |
1308 request.headers.set('User-Agent', _httpClient.userAgent); | 1308 request.headers._add('user-agent', _httpClient.userAgent); |
1309 } | 1309 } |
1310 if (proxy.isAuthenticated) { | 1310 if (proxy.isAuthenticated) { |
1311 // If the proxy configuration contains user information use that | 1311 // If the proxy configuration contains user information use that |
1312 // for proxy basic authorization. | 1312 // for proxy basic authorization. |
1313 String auth = _CryptoUtils.bytesToBase64( | 1313 String auth = _CryptoUtils.bytesToBase64( |
1314 UTF8.encode("${proxy.username}:${proxy.password}")); | 1314 UTF8.encode("${proxy.username}:${proxy.password}")); |
1315 request.headers.set(HttpHeaders.PROXY_AUTHORIZATION, "Basic $auth"); | 1315 request.headers.set(HttpHeaders.PROXY_AUTHORIZATION, "Basic $auth"); |
1316 } else if (!proxy.isDirect && _httpClient._proxyCredentials.length > 0) { | 1316 } else if (!proxy.isDirect && _httpClient._proxyCredentials.length > 0) { |
1317 proxyCreds = _httpClient._findProxyCredentials(proxy); | 1317 proxyCreds = _httpClient._findProxyCredentials(proxy); |
1318 if (proxyCreds != null) { | 1318 if (proxyCreds != null) { |
(...skipping 1235 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2554 | 2554 |
2555 String _getHttpVersion() { | 2555 String _getHttpVersion() { |
2556 var version = Platform.version; | 2556 var version = Platform.version; |
2557 // Only include major and minor version numbers. | 2557 // Only include major and minor version numbers. |
2558 int index = version.indexOf('.', version.indexOf('.') + 1); | 2558 int index = version.indexOf('.', version.indexOf('.') + 1); |
2559 version = version.substring(0, index); | 2559 version = version.substring(0, index); |
2560 return 'Dart/$version (dart:io)'; | 2560 return 'Dart/$version (dart:io)'; |
2561 } | 2561 } |
2562 | 2562 |
2563 | 2563 |
OLD | NEW |