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 _HttpHeaders implements HttpHeaders { | 7 class _HttpHeaders implements HttpHeaders { |
8 final Map<String, List<String>> _headers; | 8 final Map<String, List<String>> _headers; |
9 final String protocolVersion; | 9 final String protocolVersion; |
10 | 10 |
(...skipping 447 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
458 _noFoldingHeaders.indexOf(name) != -1)) { | 458 _noFoldingHeaders.indexOf(name) != -1)) { |
459 return false; | 459 return false; |
460 } | 460 } |
461 return true; | 461 return true; |
462 } | 462 } |
463 | 463 |
464 void _finalize() { | 464 void _finalize() { |
465 _mutable = false; | 465 _mutable = false; |
466 } | 466 } |
467 | 467 |
| 468 void _build(BytesBuilder builder) { |
| 469 for (String name in _headers.keys) { |
| 470 List<String> values = _headers[name]; |
| 471 bool fold = _foldHeader(name); |
| 472 var nameData = name.codeUnits; |
| 473 builder.add(nameData); |
| 474 builder.addByte(_CharCode.COLON); |
| 475 builder.addByte(_CharCode.SP); |
| 476 for (int i = 0; i < values.length; i++) { |
| 477 if (i > 0) { |
| 478 if (fold) { |
| 479 builder.addByte(_CharCode.COMMA); |
| 480 builder.addByte(_CharCode.SP); |
| 481 } else { |
| 482 builder.addByte(_CharCode.CR); |
| 483 builder.addByte(_CharCode.LF); |
| 484 builder.add(nameData); |
| 485 builder.addByte(_CharCode.COLON); |
| 486 builder.addByte(_CharCode.SP); |
| 487 } |
| 488 } |
| 489 builder.add(values[i].codeUnits); |
| 490 } |
| 491 builder.addByte(_CharCode.CR); |
| 492 builder.addByte(_CharCode.LF); |
| 493 } |
| 494 } |
| 495 |
468 int _write(Uint8List buffer, int offset) { | 496 int _write(Uint8List buffer, int offset) { |
469 void write(List<int> bytes) { | 497 void write(List<int> bytes) { |
470 int len = bytes.length; | 498 int len = bytes.length; |
471 for (int i = 0; i < len; i++) { | 499 for (int i = 0; i < len; i++) { |
472 buffer[offset + i] = bytes[i]; | 500 buffer[offset + i] = bytes[i]; |
473 } | 501 } |
474 offset += len; | 502 offset += len; |
475 } | 503 } |
476 | 504 |
477 // Format headers. | 505 // Format headers. |
(...skipping 512 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
990 (codeUnit >= 0x23 && codeUnit <= 0x2B) || | 1018 (codeUnit >= 0x23 && codeUnit <= 0x2B) || |
991 (codeUnit >= 0x2D && codeUnit <= 0x3A) || | 1019 (codeUnit >= 0x2D && codeUnit <= 0x3A) || |
992 (codeUnit >= 0x3C && codeUnit <= 0x5B) || | 1020 (codeUnit >= 0x3C && codeUnit <= 0x5B) || |
993 (codeUnit >= 0x5D && codeUnit <= 0x7E))) { | 1021 (codeUnit >= 0x5D && codeUnit <= 0x7E))) { |
994 throw new FormatException( | 1022 throw new FormatException( |
995 "Invalid character in cookie value, code unit: '$codeUnit'"); | 1023 "Invalid character in cookie value, code unit: '$codeUnit'"); |
996 } | 1024 } |
997 } | 1025 } |
998 } | 1026 } |
999 } | 1027 } |
OLD | NEW |