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 // Global constants. | 7 // Global constants. |
8 class _Const { | 8 class _Const { |
9 // Bytes for "HTTP". | 9 // Bytes for "HTTP". |
10 static const HTTP = const [72, 84, 84, 80]; | 10 static const HTTP = const [72, 84, 84, 80]; |
11 // Bytes for "HTTP/1.". | 11 // Bytes for "HTTP/1.". |
12 static const HTTP1DOT = const [72, 84, 84, 80, 47, 49, 46]; | 12 static const HTTP1DOT = const [72, 84, 84, 80, 47, 49, 46]; |
13 // Bytes for "HTTP/1.0". | 13 // Bytes for "HTTP/1.0". |
14 static const HTTP10 = const [72, 84, 84, 80, 47, 49, 46, 48]; | 14 static const HTTP10 = const [72, 84, 84, 80, 47, 49, 46, 48]; |
15 // Bytes for "HTTP/1.1". | 15 // Bytes for "HTTP/1.1". |
16 static const HTTP11 = const [72, 84, 84, 80, 47, 49, 46, 49]; | 16 static const HTTP11 = const [72, 84, 84, 80, 47, 49, 46, 49]; |
17 | 17 |
18 static const END_CHUNKED = const [0x30, 13, 10, 13, 10]; | 18 static const bool T = true; |
19 | 19 static const bool F = false; |
20 // Bytes for '()<>@,;:\\"/[]?={} \t'. | 20 // Loopup-map for the following characters: '()<>@,;:\\"/[]?={} \t'. |
21 static const SEPARATORS = const [40, 41, 60, 62, 64, 44, 59, 58, 92, 34, 47, | 21 static const SEPARATOR_MAP = const [ |
22 91, 93, 63, 61, 123, 125, 32, 9]; | 22 F,F,F,F,F,F,F,F,F,T,F,F,F,F,F,F,F,F,F,F,F,F,F,F,F,F,F,F,F,F,F,F,T,F,T,F,F, |
23 | 23 F,F,F,T,T,F,F,T,F,F,T,F,F,F,F,F,F,F,F,F,F,T,T,T,T,T,T,T,F,F,F,F,F,F,F,F,F, |
24 // Bytes for '()<>@,;:\\"/[]?={} \t\r\n'. | 24 F,F,F,F,F,F,F,F,F,F,F,F,F,F,F,F,F,T,T,T,F,F,F,F,F,F,F,F,F,F,F,F,F,F,F,F,F, |
25 static const SEPARATORS_AND_CR_LF = const [40, 41, 60, 62, 64, 44, 59, 58, 92, | 25 F,F,F,F,F,F,F,F,F,F,F,F,T,F,T,F,F,F,F,F,F,F,F,F,F,F,F,F,F,F,F,F,F,F,F,F,F, |
26 34, 47, 91, 93, 63, 61, 123, 125, | 26 F,F,F,F,F,F,F,F,F,F,F,F,F,F,F,F,F,F,F,F,F,F,F,F,F,F,F,F,F,F,F,F,F,F,F,F,F, |
27 32, 9, 13, 10]; | 27 F,F,F,F,F,F,F,F,F,F,F,F,F,F,F,F,F,F,F,F,F,F,F,F,F,F,F,F,F,F,F,F,F,F,F,F,F, |
| 28 F,F,F,F,F,F,F,F,F,F,F,F,F,F,F,F,F,F,F,F,F,F,F,F,F,F,F,F,F,F,F,F,F,F]; |
28 } | 29 } |
29 | 30 |
30 | 31 |
31 // Frequently used character codes. | 32 // Frequently used character codes. |
32 class _CharCode { | 33 class _CharCode { |
33 static const int HT = 9; | 34 static const int HT = 9; |
34 static const int LF = 10; | 35 static const int LF = 10; |
35 static const int CR = 13; | 36 static const int CR = 13; |
36 static const int SP = 32; | 37 static const int SP = 32; |
37 static const int AMPERSAND = 38; | 38 static const int AMPERSAND = 38; |
(...skipping 324 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
362 _state = _State.RESPONSE_LINE_STATUS_CODE; | 363 _state = _State.RESPONSE_LINE_STATUS_CODE; |
363 } else { | 364 } else { |
364 throw new HttpException("Invalid response line"); | 365 throw new HttpException("Invalid response line"); |
365 } | 366 } |
366 break; | 367 break; |
367 | 368 |
368 case _State.REQUEST_LINE_METHOD: | 369 case _State.REQUEST_LINE_METHOD: |
369 if (byte == _CharCode.SP) { | 370 if (byte == _CharCode.SP) { |
370 _state = _State.REQUEST_LINE_URI; | 371 _state = _State.REQUEST_LINE_URI; |
371 } else { | 372 } else { |
372 if (_Const.SEPARATORS_AND_CR_LF.indexOf(byte) != -1) { | 373 if (_Const.SEPARATOR_MAP[byte] || |
| 374 byte == _CharCode.CR || |
| 375 byte == _CharCode.LF) { |
373 throw new HttpException("Invalid request method"); | 376 throw new HttpException("Invalid request method"); |
374 } | 377 } |
375 _method_or_status_code.add(byte); | 378 _method_or_status_code.add(byte); |
376 } | 379 } |
377 break; | 380 break; |
378 | 381 |
379 case _State.REQUEST_LINE_URI: | 382 case _State.REQUEST_LINE_URI: |
380 if (byte == _CharCode.SP) { | 383 if (byte == _CharCode.SP) { |
381 if (_uri_or_reason_phrase.length == 0) { | 384 if (_uri_or_reason_phrase.length == 0) { |
382 throw new HttpException("Invalid request URI"); | 385 throw new HttpException("Invalid request URI"); |
(...skipping 446 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
829 | 832 |
830 _headers = null; | 833 _headers = null; |
831 } | 834 } |
832 | 835 |
833 _releaseBuffer() { | 836 _releaseBuffer() { |
834 _buffer = null; | 837 _buffer = null; |
835 _index = null; | 838 _index = null; |
836 } | 839 } |
837 | 840 |
838 bool _isTokenChar(int byte) { | 841 bool _isTokenChar(int byte) { |
839 return byte > 31 && byte < 128 && _Const.SEPARATORS.indexOf(byte) == -1; | 842 return byte > 31 && byte < 128 && !_Const.SEPARATOR_MAP[byte]; |
840 } | 843 } |
841 | 844 |
842 List<String> _tokenizeFieldValue(String headerValue) { | 845 List<String> _tokenizeFieldValue(String headerValue) { |
843 List<String> tokens = new List<String>(); | 846 List<String> tokens = new List<String>(); |
844 int start = 0; | 847 int start = 0; |
845 int index = 0; | 848 int index = 0; |
846 while (index < headerValue.length) { | 849 while (index < headerValue.length) { |
847 if (headerValue[index] == ",") { | 850 if (headerValue[index] == ",") { |
848 tokens.add(headerValue.substring(start, index)); | 851 tokens.add(headerValue.substring(start, index)); |
849 start = index + 1; | 852 start = index + 1; |
(...skipping 133 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
983 _HttpHeaders _headers; | 986 _HttpHeaders _headers; |
984 | 987 |
985 // The current incoming connection. | 988 // The current incoming connection. |
986 _HttpIncoming _incoming; | 989 _HttpIncoming _incoming; |
987 StreamSubscription _socketSubscription; | 990 StreamSubscription _socketSubscription; |
988 bool _paused = true; | 991 bool _paused = true; |
989 bool _bodyPaused = false; | 992 bool _bodyPaused = false; |
990 StreamController<_HttpIncoming> _controller; | 993 StreamController<_HttpIncoming> _controller; |
991 StreamController<List<int>> _bodyController; | 994 StreamController<List<int>> _bodyController; |
992 } | 995 } |
OLD | NEW |