| OLD | NEW |
| 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 1031 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1042 _writeSP(); | 1042 _writeSP(); |
| 1043 data = _statusCode.toString().charCodes(); | 1043 data = _statusCode.toString().charCodes(); |
| 1044 _httpConnection._write(data); | 1044 _httpConnection._write(data); |
| 1045 _writeSP(); | 1045 _writeSP(); |
| 1046 data = reasonPhrase.charCodes(); | 1046 data = reasonPhrase.charCodes(); |
| 1047 _httpConnection._write(data); | 1047 _httpConnection._write(data); |
| 1048 _writeCRLF(); | 1048 _writeCRLF(); |
| 1049 | 1049 |
| 1050 // Determine the value of the "Transfer-Encoding" header based on | 1050 // Determine the value of the "Transfer-Encoding" header based on |
| 1051 // whether the content length is known. | 1051 // whether the content length is known. |
| 1052 if (_contentLength > 0) { | 1052 if (_contentLength >= 0) { |
| 1053 _headers.set(HttpHeaders.CONTENT_LENGTH, _contentLength.toString()); | 1053 _headers.set(HttpHeaders.CONTENT_LENGTH, _contentLength.toString()); |
| 1054 } else if (_contentLength < 0) { | 1054 } else if (_contentLength < 0) { |
| 1055 _headers.set(HttpHeaders.TRANSFER_ENCODING, "chunked"); | 1055 _headers.set(HttpHeaders.TRANSFER_ENCODING, "chunked"); |
| 1056 } | 1056 } |
| 1057 | 1057 |
| 1058 // Add all the cookies set to the headers. | 1058 // Add all the cookies set to the headers. |
| 1059 if (_cookies != null) { | 1059 if (_cookies != null) { |
| 1060 _cookies.forEach((cookie) { | 1060 _cookies.forEach((cookie) { |
| 1061 _headers.add("set-cookie", cookie); | 1061 _headers.add("set-cookie", cookie); |
| 1062 }); | 1062 }); |
| (...skipping 273 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1336 if (onRequestReceived != null) { | 1336 if (onRequestReceived != null) { |
| 1337 onRequestReceived(_request, _response); | 1337 onRequestReceived(_request, _response); |
| 1338 } | 1338 } |
| 1339 } | 1339 } |
| 1340 | 1340 |
| 1341 void _onDataReceived(List<int> data) { | 1341 void _onDataReceived(List<int> data) { |
| 1342 _request._onDataReceived(data); | 1342 _request._onDataReceived(data); |
| 1343 } | 1343 } |
| 1344 | 1344 |
| 1345 void _onDataEnd(bool close) { | 1345 void _onDataEnd(bool close) { |
| 1346 if (_request != null) { | 1346 _request._onDataEnd(); |
| 1347 _request._onDataEnd(); | |
| 1348 } | |
| 1349 _request = null; | |
| 1350 } | 1347 } |
| 1351 | 1348 |
| 1352 void _responseDone() { | 1349 void _responseDone() { |
| 1353 // If the connection is closing then close the output stream to | 1350 // If the connection is closing then close the output stream to |
| 1354 // fully close the socket. | 1351 // fully close the socket. |
| 1355 if (_closing) { | 1352 if (_closing) { |
| 1356 _socket.close(); | 1353 _socket.close(); |
| 1357 } | 1354 } |
| 1358 _response = null; | 1355 _response = null; |
| 1359 } | 1356 } |
| (...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1456 } | 1453 } |
| 1457 } | 1454 } |
| 1458 return; | 1455 return; |
| 1459 } | 1456 } |
| 1460 } | 1457 } |
| 1461 | 1458 |
| 1462 if (_defaultHandler != null) { | 1459 if (_defaultHandler != null) { |
| 1463 _defaultHandler(request, response); | 1460 _defaultHandler(request, response); |
| 1464 } else { | 1461 } else { |
| 1465 response.statusCode = HttpStatus.NOT_FOUND; | 1462 response.statusCode = HttpStatus.NOT_FOUND; |
| 1466 if (request.protocolVersion == "1.0") { | 1463 response.contentLength = 0; |
| 1467 response.contentLength = 0; | |
| 1468 } | |
| 1469 response.outputStream.close(); | 1464 response.outputStream.close(); |
| 1470 } | 1465 } |
| 1471 } | 1466 } |
| 1472 | 1467 |
| 1473 | 1468 |
| 1474 ServerSocket _server; // The server listen socket. | 1469 ServerSocket _server; // The server listen socket. |
| 1475 bool _closeServer = false; | 1470 bool _closeServer = false; |
| 1476 Set<_HttpConnection> _connections; // Set of currently connected clients. | 1471 Set<_HttpConnection> _connections; // Set of currently connected clients. |
| 1477 List<_RequestHandlerRegistration> _handlers; | 1472 List<_RequestHandlerRegistration> _handlers; |
| 1478 Object _defaultHandler; | 1473 Object _defaultHandler; |
| (...skipping 622 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2101 | 2096 |
| 2102 | 2097 |
| 2103 class _RedirectInfo implements RedirectInfo { | 2098 class _RedirectInfo implements RedirectInfo { |
| 2104 const _RedirectInfo(int this.statusCode, | 2099 const _RedirectInfo(int this.statusCode, |
| 2105 String this.method, | 2100 String this.method, |
| 2106 Uri this.location); | 2101 Uri this.location); |
| 2107 final int statusCode; | 2102 final int statusCode; |
| 2108 final String method; | 2103 final String method; |
| 2109 final Uri location; | 2104 final Uri location; |
| 2110 } | 2105 } |
| OLD | NEW |