| 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 1381 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1392 _httpParser.headersComplete = () => _onHeadersComplete(); | 1392 _httpParser.headersComplete = () => _onHeadersComplete(); |
| 1393 _httpParser.dataReceived = (data) => _onDataReceived(data); | 1393 _httpParser.dataReceived = (data) => _onDataReceived(data); |
| 1394 _httpParser.dataEnd = (close) => _onDataEnd(close); | 1394 _httpParser.dataEnd = (close) => _onDataEnd(close); |
| 1395 _httpParser.error = (e) => _onError(e); | 1395 _httpParser.error = (e) => _onError(e); |
| 1396 } | 1396 } |
| 1397 | 1397 |
| 1398 void _onConnectionClosed(e) { | 1398 void _onConnectionClosed(e) { |
| 1399 // Don't report errors when HTTP parser is in idle state. Clients | 1399 // Don't report errors when HTTP parser is in idle state. Clients |
| 1400 // can close the connection and cause a connection reset by peer | 1400 // can close the connection and cause a connection reset by peer |
| 1401 // error which is OK. | 1401 // error which is OK. |
| 1402 if (e != null && onError != null && !_httpParser.isIdle) { | 1402 if (e != null && !_httpParser.isIdle) { |
| 1403 onError(e); | 1403 onError(e); |
| 1404 // Propagate the error to the streams. | 1404 // Propagate the error to the streams. |
| 1405 if (_request != null && _request._streamErrorHandler != null) { | 1405 if (_request != null && _request._streamErrorHandler != null) { |
| 1406 _request._streamErrorHandler(e); | 1406 _request._streamErrorHandler(e); |
| 1407 } | 1407 } |
| 1408 if (_response != null && _response._streamErrorHandler != null) { | 1408 if (_response != null && _response._streamErrorHandler != null) { |
| 1409 _response._streamErrorHandler(e); | 1409 _response._streamErrorHandler(e); |
| 1410 } | 1410 } |
| 1411 } | 1411 } |
| 1412 | 1412 |
| 1413 // If currently not processing any request close the socket when | 1413 // If currently not processing any request close the socket when |
| 1414 // we are done writing the response. | 1414 // we are done writing the response. |
| 1415 if (_httpParser.isIdle) { | 1415 if (_httpParser.isIdle) { |
| 1416 _socket.outputStream.onClosed = () { | 1416 if (e != null) { |
| 1417 _destroy(); | 1417 onError(e); |
| 1418 if (onClosed != null && e == null) { | 1418 } else { |
| 1419 // Don't call onClosed if onError has been called. | 1419 _socket.outputStream.onClosed = () { |
| 1420 _destroy(); |
| 1420 onClosed(); | 1421 onClosed(); |
| 1421 } | 1422 }; |
| 1422 }; | 1423 // If the client closes and we are done writing the response |
| 1423 // If the client closes and we are done writing the response | 1424 // the connection should be closed. |
| 1424 // the connection should be closed. | 1425 if (_response == null) _close(); |
| 1425 if (_response == null) _close(); | 1426 } |
| 1426 return; | 1427 } else { |
| 1427 } | 1428 // Processing a request. |
| 1428 | 1429 if (e == null) { |
| 1429 // Processing a request. | 1430 // Indicate connection close to the HTTP parser. |
| 1430 if (e == null) { | 1431 _httpParser.connectionClosed(); |
| 1431 // Indicate connection close to the HTTP parser. | 1432 } |
| 1432 _httpParser.connectionClosed(); | |
| 1433 } | 1433 } |
| 1434 } | 1434 } |
| 1435 | 1435 |
| 1436 void _onRequestStart(String method, String uri, String version) { | 1436 void _onRequestStart(String method, String uri, String version) { |
| 1437 // Create new request and response objects for this request. | 1437 // Create new request and response objects for this request. |
| 1438 _request = new _HttpRequest(this); | 1438 _request = new _HttpRequest(this); |
| 1439 _response = new _HttpResponse(this); | 1439 _response = new _HttpResponse(this); |
| 1440 _request._onRequestStart(method, uri, version); | 1440 _request._onRequestStart(method, uri, version); |
| 1441 _request._protocolVersion = version; | 1441 _request._protocolVersion = version; |
| 1442 _response._protocolVersion = version; | 1442 _response._protocolVersion = version; |
| (...skipping 23 matching lines...) Expand all Loading... |
| 1466 void _onDataEnd(bool close) { | 1466 void _onDataEnd(bool close) { |
| 1467 _request._onDataEnd(); | 1467 _request._onDataEnd(); |
| 1468 } | 1468 } |
| 1469 | 1469 |
| 1470 void _responseDone() { | 1470 void _responseDone() { |
| 1471 // If the connection is closing then close the output stream to | 1471 // If the connection is closing then close the output stream to |
| 1472 // fully close the socket. | 1472 // fully close the socket. |
| 1473 if (_closing) { | 1473 if (_closing) { |
| 1474 _socket.outputStream.onClosed = () { | 1474 _socket.outputStream.onClosed = () { |
| 1475 _socket.close(); | 1475 _socket.close(); |
| 1476 onClosed(); |
| 1476 }; | 1477 }; |
| 1477 } | 1478 } |
| 1478 _response = null; | 1479 _response = null; |
| 1479 } | 1480 } |
| 1480 | 1481 |
| 1481 HttpServer _server; | 1482 HttpServer _server; |
| 1482 HttpRequest _request; | 1483 HttpRequest _request; |
| 1483 HttpResponse _response; | 1484 HttpResponse _response; |
| 1484 | 1485 |
| 1485 // Callbacks. | 1486 // Callbacks. |
| (...skipping 1169 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2655 | 2656 |
| 2656 | 2657 |
| 2657 class _RedirectInfo implements RedirectInfo { | 2658 class _RedirectInfo implements RedirectInfo { |
| 2658 const _RedirectInfo(int this.statusCode, | 2659 const _RedirectInfo(int this.statusCode, |
| 2659 String this.method, | 2660 String this.method, |
| 2660 Uri this.location); | 2661 Uri this.location); |
| 2661 final int statusCode; | 2662 final int statusCode; |
| 2662 final String method; | 2663 final String method; |
| 2663 final Uri location; | 2664 final Uri location; |
| 2664 } | 2665 } |
| OLD | NEW |