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 typedef void _BytesConsumer(List<int> bytes); | 9 typedef void _BytesConsumer(List<int> bytes); |
10 | 10 |
(...skipping 556 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
567 if (_deadlineTimer != null) _deadlineTimer.cancel(); | 567 if (_deadlineTimer != null) _deadlineTimer.cancel(); |
568 _deadline = d; | 568 _deadline = d; |
569 | 569 |
570 if (_deadline == null) return; | 570 if (_deadline == null) return; |
571 _deadlineTimer = new Timer(_deadline, () { | 571 _deadlineTimer = new Timer(_deadline, () { |
572 _httpRequest._httpConnection.destroy(); | 572 _httpRequest._httpConnection.destroy(); |
573 }); | 573 }); |
574 } | 574 } |
575 | 575 |
576 void _writeHeader() { | 576 void _writeHeader() { |
577 Uint8List buffer = new Uint8List(_OUTGOING_BUFFER_SIZE); | 577 BytesBuilder buffer = new _CopyingBytesBuilder(_OUTGOING_BUFFER_SIZE); |
578 int offset = 0; | |
579 | |
580 void write(List<int> bytes) { | |
581 int len = bytes.length; | |
582 for (int i = 0; i < len; i++) { | |
583 buffer[offset + i] = bytes[i]; | |
584 } | |
585 offset += len; | |
586 } | |
587 | 578 |
588 // Write status line. | 579 // Write status line. |
589 if (headers.protocolVersion == "1.1") { | 580 if (headers.protocolVersion == "1.1") { |
590 write(_Const.HTTP11); | 581 buffer.add(_Const.HTTP11); |
591 } else { | 582 } else { |
592 write(_Const.HTTP10); | 583 buffer.add(_Const.HTTP10); |
593 } | 584 } |
594 buffer[offset++] = _CharCode.SP; | 585 buffer.addByte(_CharCode.SP); |
595 write(statusCode.toString().codeUnits); | 586 buffer.add(statusCode.toString().codeUnits); |
596 buffer[offset++] = _CharCode.SP; | 587 buffer.addByte(_CharCode.SP); |
597 write(reasonPhrase.codeUnits); | 588 buffer.add(reasonPhrase.codeUnits); |
598 buffer[offset++] = _CharCode.CR; | 589 buffer.addByte(_CharCode.CR); |
599 buffer[offset++] = _CharCode.LF; | 590 buffer.addByte(_CharCode.LF); |
600 | 591 |
601 var session = _httpRequest._session; | 592 var session = _httpRequest._session; |
602 if (session != null && !session._destroyed) { | 593 if (session != null && !session._destroyed) { |
603 // Mark as not new. | 594 // Mark as not new. |
604 session._isNew = false; | 595 session._isNew = false; |
605 // Make sure we only send the current session id. | 596 // Make sure we only send the current session id. |
606 bool found = false; | 597 bool found = false; |
607 for (int i = 0; i < cookies.length; i++) { | 598 for (int i = 0; i < cookies.length; i++) { |
608 if (cookies[i].name.toUpperCase() == _DART_SESSION_ID) { | 599 if (cookies[i].name.toUpperCase() == _DART_SESSION_ID) { |
609 cookies[i] | 600 cookies[i] |
(...skipping 13 matching lines...) Expand all Loading... | |
623 // Add all the cookies set to the headers. | 614 // Add all the cookies set to the headers. |
624 if (_cookies != null) { | 615 if (_cookies != null) { |
625 _cookies.forEach((cookie) { | 616 _cookies.forEach((cookie) { |
626 headers.add(HttpHeaders.SET_COOKIE, cookie); | 617 headers.add(HttpHeaders.SET_COOKIE, cookie); |
627 }); | 618 }); |
628 } | 619 } |
629 | 620 |
630 headers._finalize(); | 621 headers._finalize(); |
631 | 622 |
632 // Write headers. | 623 // Write headers. |
633 offset = headers._write(buffer, offset); | 624 headers._build(buffer); |
Søren Gjesse
2017/01/05 14:22:12
Is headers._write still used?
Lasse Reichstein Nielsen
2017/01/13 06:22:59
There is another implementation of _writeHeaders,
| |
634 buffer[offset++] = _CharCode.CR; | 625 buffer.addByte(_CharCode.CR); |
635 buffer[offset++] = _CharCode.LF; | 626 buffer.addByte(_CharCode.LF); |
636 _outgoing.setHeader(buffer, offset); | 627 Uint8List headerBytes = buffer.takeBytes(); |
628 _outgoing.setHeader(headerBytes, headerBytes.length); | |
637 } | 629 } |
638 | 630 |
639 String _findReasonPhrase(int statusCode) { | 631 String _findReasonPhrase(int statusCode) { |
640 if (_reasonPhrase != null) { | 632 if (_reasonPhrase != null) { |
641 return _reasonPhrase; | 633 return _reasonPhrase; |
642 } | 634 } |
643 | 635 |
644 switch (statusCode) { | 636 switch (statusCode) { |
645 case HttpStatus.CONTINUE: return "Continue"; | 637 case HttpStatus.CONTINUE: return "Continue"; |
646 case HttpStatus.SWITCHING_PROTOCOLS: return "Switching Protocols"; | 638 case HttpStatus.SWITCHING_PROTOCOLS: return "Switching Protocols"; |
(...skipping 506 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1153 if (future != null) { | 1145 if (future != null) { |
1154 return _closeFuture = future.whenComplete(finalize); | 1146 return _closeFuture = future.whenComplete(finalize); |
1155 } | 1147 } |
1156 return _closeFuture = finalize(); | 1148 return _closeFuture = finalize(); |
1157 } | 1149 } |
1158 | 1150 |
1159 Future<Socket> get done => _doneCompleter.future; | 1151 Future<Socket> get done => _doneCompleter.future; |
1160 | 1152 |
1161 void setHeader(List<int> data, int length) { | 1153 void setHeader(List<int> data, int length) { |
1162 assert(_length == 0); | 1154 assert(_length == 0); |
1163 assert(data.length == _OUTGOING_BUFFER_SIZE); | |
1164 _buffer = data; | 1155 _buffer = data; |
1165 _length = length; | 1156 _length = length; |
1166 } | 1157 } |
1167 | 1158 |
1168 void set gzip(bool value) { | 1159 void set gzip(bool value) { |
1169 _gzip = value; | 1160 _gzip = value; |
1170 if (_gzip) { | 1161 if (_gzip) { |
1171 _gzipBuffer = new Uint8List(_OUTGOING_BUFFER_SIZE); | 1162 _gzipBuffer = new Uint8List(_OUTGOING_BUFFER_SIZE); |
1172 assert(_gzipSink == null); | 1163 assert(_gzipSink == null); |
1173 _gzipSink = new ZLibEncoder(gzip: true) | 1164 _gzipSink = new ZLibEncoder(gzip: true) |
(...skipping 1717 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2891 const _RedirectInfo(this.statusCode, this.method, this.location); | 2882 const _RedirectInfo(this.statusCode, this.method, this.location); |
2892 } | 2883 } |
2893 | 2884 |
2894 String _getHttpVersion() { | 2885 String _getHttpVersion() { |
2895 var version = Platform.version; | 2886 var version = Platform.version; |
2896 // Only include major and minor version numbers. | 2887 // Only include major and minor version numbers. |
2897 int index = version.indexOf('.', version.indexOf('.') + 1); | 2888 int index = version.indexOf('.', version.indexOf('.') + 1); |
2898 version = version.substring(0, index); | 2889 version = version.substring(0, index); |
2899 return 'Dart/$version (dart:io)'; | 2890 return 'Dart/$version (dart:io)'; |
2900 } | 2891 } |
OLD | NEW |