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 _OUTGOING_BUFFER_SIZE = 8 * 1024; | 7 const int _OUTGOING_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 930 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
941 " bytes")); | 941 " bytes")); |
942 } | 942 } |
943 } | 943 } |
944 if (headersWritten) return null; | 944 if (headersWritten) return null; |
945 headersWritten = true; | 945 headersWritten = true; |
946 Future drainFuture; | 946 Future drainFuture; |
947 bool isServerSide = outbound is _HttpResponse; | 947 bool isServerSide = outbound is _HttpResponse; |
948 bool gzip = false; | 948 bool gzip = false; |
949 if (isServerSide) { | 949 if (isServerSide) { |
950 var response = outbound; | 950 var response = outbound; |
951 if (outbound.bufferOutput && outbound.headers.chunkedTransferEncoding) { | 951 if (response._httpRequest._httpServer.autoCompress && |
| 952 outbound.bufferOutput && |
| 953 outbound.headers.chunkedTransferEncoding) { |
952 List acceptEncodings = | 954 List acceptEncodings = |
953 response._httpRequest.headers[HttpHeaders.ACCEPT_ENCODING]; | 955 response._httpRequest.headers[HttpHeaders.ACCEPT_ENCODING]; |
954 List contentEncoding = outbound.headers[HttpHeaders.CONTENT_ENCODING]; | 956 List contentEncoding = outbound.headers[HttpHeaders.CONTENT_ENCODING]; |
955 if (acceptEncodings != null && | 957 if (acceptEncodings != null && |
956 acceptEncodings | 958 acceptEncodings |
957 .expand((list) => list.split(",")) | 959 .expand((list) => list.split(",")) |
958 .any((encoding) => encoding.trim().toLowerCase() == "gzip") && | 960 .any((encoding) => encoding.trim().toLowerCase() == "gzip") && |
959 contentEncoding == null) { | 961 contentEncoding == null) { |
960 outbound.headers.set(HttpHeaders.CONTENT_ENCODING, "gzip"); | 962 outbound.headers.set(HttpHeaders.CONTENT_ENCODING, "gzip"); |
961 gzip = true; | 963 gzip = true; |
(...skipping 1181 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2143 | 2145 |
2144 // HTTP server waiting for socket connections. | 2146 // HTTP server waiting for socket connections. |
2145 class _HttpServer | 2147 class _HttpServer |
2146 extends Stream<HttpRequest> with _ServiceObject | 2148 extends Stream<HttpRequest> with _ServiceObject |
2147 implements HttpServer { | 2149 implements HttpServer { |
2148 // Use default Map so we keep order. | 2150 // Use default Map so we keep order. |
2149 static Map<int, _HttpServer> _servers = new Map<int, _HttpServer>(); | 2151 static Map<int, _HttpServer> _servers = new Map<int, _HttpServer>(); |
2150 | 2152 |
2151 String serverHeader; | 2153 String serverHeader; |
2152 final HttpHeaders defaultResponseHeaders = _initDefaultResponseHeaders(); | 2154 final HttpHeaders defaultResponseHeaders = _initDefaultResponseHeaders(); |
| 2155 bool autoCompress = true; |
2153 | 2156 |
2154 Duration _idleTimeout; | 2157 Duration _idleTimeout; |
2155 Timer _idleTimer; | 2158 Timer _idleTimer; |
2156 | 2159 |
2157 static Future<HttpServer> bind(address, int port, int backlog) { | 2160 static Future<HttpServer> bind(address, int port, int backlog) { |
2158 return ServerSocket.bind(address, port, backlog: backlog).then((socket) { | 2161 return ServerSocket.bind(address, port, backlog: backlog).then((socket) { |
2159 return new _HttpServer._(socket, true); | 2162 return new _HttpServer._(socket, true); |
2160 }); | 2163 }); |
2161 } | 2164 } |
2162 | 2165 |
(...skipping 644 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2807 const _RedirectInfo(this.statusCode, this.method, this.location); | 2810 const _RedirectInfo(this.statusCode, this.method, this.location); |
2808 } | 2811 } |
2809 | 2812 |
2810 String _getHttpVersion() { | 2813 String _getHttpVersion() { |
2811 var version = Platform.version; | 2814 var version = Platform.version; |
2812 // Only include major and minor version numbers. | 2815 // Only include major and minor version numbers. |
2813 int index = version.indexOf('.', version.indexOf('.') + 1); | 2816 int index = version.indexOf('.', version.indexOf('.') + 1); |
2814 version = version.substring(0, index); | 2817 version = version.substring(0, index); |
2815 return 'Dart/$version (dart:io)'; | 2818 return 'Dart/$version (dart:io)'; |
2816 } | 2819 } |
OLD | NEW |