| 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 class _HttpIncoming extends Stream<List<int>> { | 7 class _HttpIncoming extends Stream<List<int>> { |
| 8 final int _transferLength; | 8 final int _transferLength; |
| 9 final Completer _dataCompleter = new Completer(); | 9 final Completer _dataCompleter = new Completer(); |
| 10 Stream<List<int>> _stream; | 10 Stream<List<int>> _stream; |
| (...skipping 380 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 391 _ChunkedTransformer._addChunk([], _ioSink.add); | 391 _ChunkedTransformer._addChunk([], _ioSink.add); |
| 392 } | 392 } |
| 393 } | 393 } |
| 394 _ioSink.close(); | 394 _ioSink.close(); |
| 395 } | 395 } |
| 396 | 396 |
| 397 Future<T> get done => _ioSink.done.then((_) => this); | 397 Future<T> get done => _ioSink.done.then((_) => this); |
| 398 | 398 |
| 399 void _writeHeaders() { | 399 void _writeHeaders() { |
| 400 if (_headersWritten) return; | 400 if (_headersWritten) return; |
| 401 bool _tmpIgnoreBody = _ignoreBody; | |
| 402 _ignoreBody = false; | |
| 403 _headersWritten = true; | 401 _headersWritten = true; |
| 404 _writeHeader(); | 402 _writeHeader(); |
| 405 _ignoreBody = _tmpIgnoreBody; | |
| 406 if (_ignoreBody) { | 403 if (_ignoreBody) { |
| 407 _ioSink.close(); | 404 _ioSink.close(); |
| 408 return; | 405 return; |
| 409 } | 406 } |
| 410 _chunked = headers.chunkedTransferEncoding; | 407 _chunked = headers.chunkedTransferEncoding; |
| 411 if (headers.contentLength >= 0) { | 408 if (headers.contentLength >= 0) { |
| 412 _outgoing.setTransferLength(headers.contentLength); | 409 _outgoing.setTransferLength(headers.contentLength); |
| 413 } | 410 } |
| 414 } | 411 } |
| 415 | 412 |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 448 done.catchError((_) { | 445 done.catchError((_) { |
| 449 // Catch any error on done, as they automatically will be propegated to | 446 // Catch any error on done, as they automatically will be propegated to |
| 450 // the websocket. | 447 // the websocket. |
| 451 }); | 448 }); |
| 452 return future; | 449 return future; |
| 453 } | 450 } |
| 454 | 451 |
| 455 HttpConnectionInfo get connectionInfo => _httpRequest.connectionInfo; | 452 HttpConnectionInfo get connectionInfo => _httpRequest.connectionInfo; |
| 456 | 453 |
| 457 void _writeHeader() { | 454 void _writeHeader() { |
| 458 writeSP() => add([_CharCode.SP]); | 455 writeSP() => _ioSink.add([_CharCode.SP]); |
| 459 writeCRLF() => add([_CharCode.CR, _CharCode.LF]); | 456 writeCRLF() => _ioSink.add([_CharCode.CR, _CharCode.LF]); |
| 460 | 457 |
| 461 // Write status line. | 458 // Write status line. |
| 462 if (headers.protocolVersion == "1.1") { | 459 if (headers.protocolVersion == "1.1") { |
| 463 add(_Const.HTTP11); | 460 _ioSink.add(_Const.HTTP11); |
| 464 } else { | 461 } else { |
| 465 add(_Const.HTTP10); | 462 _ioSink.add(_Const.HTTP10); |
| 466 } | 463 } |
| 467 writeSP(); | 464 writeSP(); |
| 468 addString(statusCode.toString()); | 465 _ioSink.addString(statusCode.toString()); |
| 469 writeSP(); | 466 writeSP(); |
| 470 addString(reasonPhrase); | 467 _ioSink.addString(reasonPhrase); |
| 471 writeCRLF(); | 468 writeCRLF(); |
| 472 | 469 |
| 473 var session = _httpRequest._session; | 470 var session = _httpRequest._session; |
| 474 if (session != null && !session._destroyed) { | 471 if (session != null && !session._destroyed) { |
| 475 // Mark as not new. | 472 // Mark as not new. |
| 476 session._isNew = false; | 473 session._isNew = false; |
| 477 // Make sure we only send the current session id. | 474 // Make sure we only send the current session id. |
| 478 bool found = false; | 475 bool found = false; |
| 479 for (int i = 0; i < cookies.length; i++) { | 476 for (int i = 0; i < cookies.length; i++) { |
| 480 if (cookies[i].name.toUpperCase() == _DART_SESSION_ID) { | 477 if (cookies[i].name.toUpperCase() == _DART_SESSION_ID) { |
| (...skipping 10 matching lines...) Expand all Loading... |
| 491 // Add all the cookies set to the headers. | 488 // Add all the cookies set to the headers. |
| 492 if (_cookies != null) { | 489 if (_cookies != null) { |
| 493 _cookies.forEach((cookie) { | 490 _cookies.forEach((cookie) { |
| 494 headers.add(HttpHeaders.SET_COOKIE, cookie); | 491 headers.add(HttpHeaders.SET_COOKIE, cookie); |
| 495 }); | 492 }); |
| 496 } | 493 } |
| 497 | 494 |
| 498 headers._finalize(); | 495 headers._finalize(); |
| 499 | 496 |
| 500 // Write headers. | 497 // Write headers. |
| 501 headers._write(this); | 498 headers._write(_ioSink); |
| 502 writeCRLF(); | 499 writeCRLF(); |
| 503 } | 500 } |
| 504 | 501 |
| 505 String _findReasonPhrase(int statusCode) { | 502 String _findReasonPhrase(int statusCode) { |
| 506 if (_reasonPhrase != null) { | 503 if (_reasonPhrase != null) { |
| 507 return _reasonPhrase; | 504 return _reasonPhrase; |
| 508 } | 505 } |
| 509 | 506 |
| 510 switch (statusCode) { | 507 switch (statusCode) { |
| 511 case HttpStatus.CONTINUE: return "Continue"; | 508 case HttpStatus.CONTINUE: return "Continue"; |
| (...skipping 129 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 641 onError: (e) { | 638 onError: (e) { |
| 642 _responseCompleter.completeError(e); | 639 _responseCompleter.completeError(e); |
| 643 }); | 640 }); |
| 644 } | 641 } |
| 645 | 642 |
| 646 void _onError(AsyncError error) { | 643 void _onError(AsyncError error) { |
| 647 _responseCompleter.completeError(error); | 644 _responseCompleter.completeError(error); |
| 648 } | 645 } |
| 649 | 646 |
| 650 void _writeHeader() { | 647 void _writeHeader() { |
| 651 writeSP() => add([_CharCode.SP]); | 648 writeSP() => _ioSink.add([_CharCode.SP]); |
| 652 writeCRLF() => add([_CharCode.CR, _CharCode.LF]); | 649 writeCRLF() => _ioSink.add([_CharCode.CR, _CharCode.LF]); |
| 653 | 650 |
| 654 addString(method); | 651 _ioSink.addString(method); |
| 655 writeSP(); | 652 writeSP(); |
| 656 // Send the path for direct connections and the whole URL for | 653 // Send the path for direct connections and the whole URL for |
| 657 // proxy connections. | 654 // proxy connections. |
| 658 if (!_usingProxy) { | 655 if (!_usingProxy) { |
| 659 String path = uri.path; | 656 String path = uri.path; |
| 660 if (path.length == 0) path = "/"; | 657 if (path.length == 0) path = "/"; |
| 661 if (uri.query != "") { | 658 if (uri.query != "") { |
| 662 if (uri.fragment != "") { | 659 if (uri.fragment != "") { |
| 663 path = "${path}?${uri.query}#${uri.fragment}"; | 660 path = "${path}?${uri.query}#${uri.fragment}"; |
| 664 } else { | 661 } else { |
| 665 path = "${path}?${uri.query}"; | 662 path = "${path}?${uri.query}"; |
| 666 } | 663 } |
| 667 } | 664 } |
| 668 addString(path); | 665 _ioSink.addString(path); |
| 669 } else { | 666 } else { |
| 670 addString(uri.toString()); | 667 _ioSink.addString(uri.toString()); |
| 671 } | 668 } |
| 672 writeSP(); | 669 writeSP(); |
| 673 add(_Const.HTTP11); | 670 _ioSink.add(_Const.HTTP11); |
| 674 writeCRLF(); | 671 writeCRLF(); |
| 675 | 672 |
| 676 // Add the cookies to the headers. | 673 // Add the cookies to the headers. |
| 677 if (!cookies.isEmpty) { | 674 if (!cookies.isEmpty) { |
| 678 StringBuffer sb = new StringBuffer(); | 675 StringBuffer sb = new StringBuffer(); |
| 679 for (int i = 0; i < cookies.length; i++) { | 676 for (int i = 0; i < cookies.length; i++) { |
| 680 if (i > 0) sb.write("; "); | 677 if (i > 0) sb.write("; "); |
| 681 sb.write(cookies[i].name); | 678 sb.write(cookies[i].name); |
| 682 sb.write("="); | 679 sb.write("="); |
| 683 sb.write(cookies[i].value); | 680 sb.write(cookies[i].value); |
| 684 } | 681 } |
| 685 headers.add(HttpHeaders.COOKIE, sb.toString()); | 682 headers.add(HttpHeaders.COOKIE, sb.toString()); |
| 686 } | 683 } |
| 687 | 684 |
| 688 headers._finalize(); | 685 headers._finalize(); |
| 689 | 686 |
| 690 // Write headers. | 687 // Write headers. |
| 691 headers._write(this); | 688 headers._write(_ioSink); |
| 692 writeCRLF(); | 689 writeCRLF(); |
| 693 } | 690 } |
| 694 } | 691 } |
| 695 | 692 |
| 696 | 693 |
| 697 // Transformer that transforms data to HTTP Chunked Encoding. | 694 // Transformer that transforms data to HTTP Chunked Encoding. |
| 698 class _ChunkedTransformer extends StreamEventTransformer<List<int>, List<int>> { | 695 class _ChunkedTransformer extends StreamEventTransformer<List<int>, List<int>> { |
| 699 final bool writeEnd; | 696 final bool writeEnd; |
| 700 _ChunkedTransformer({this.writeEnd: true}); | 697 _ChunkedTransformer({this.writeEnd: true}); |
| 701 | 698 |
| (...skipping 937 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1639 | 1636 |
| 1640 | 1637 |
| 1641 class _RedirectInfo implements RedirectInfo { | 1638 class _RedirectInfo implements RedirectInfo { |
| 1642 const _RedirectInfo(int this.statusCode, | 1639 const _RedirectInfo(int this.statusCode, |
| 1643 String this.method, | 1640 String this.method, |
| 1644 Uri this.location); | 1641 Uri this.location); |
| 1645 final int statusCode; | 1642 final int statusCode; |
| 1646 final String method; | 1643 final String method; |
| 1647 final Uri location; | 1644 final Uri location; |
| 1648 } | 1645 } |
| OLD | NEW |