| 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 _HttpHeaders(String this.protocolVersion) | 8 _HttpHeaders(String this.protocolVersion) |
| 9 : _headers = new Map<String, List<String>>(); | 9 : _headers = new Map<String, List<String>>(); |
| 10 | 10 |
| (...skipping 326 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 337 protocolVersion == "1.1") { | 337 protocolVersion == "1.1") { |
| 338 contentLength = -1; | 338 contentLength = -1; |
| 339 } | 339 } |
| 340 } | 340 } |
| 341 | 341 |
| 342 void _finalize() { | 342 void _finalize() { |
| 343 _synchronize(); | 343 _synchronize(); |
| 344 _mutable = false; | 344 _mutable = false; |
| 345 } | 345 } |
| 346 | 346 |
| 347 _write(BytesBuilder builder) { | 347 int _write(Uint8List buffer, int offset) { |
| 348 final COLONSP = const [_CharCode.COLON, _CharCode.SP]; | 348 void write(List<int> bytes) { |
| 349 final COMMASP = const [_CharCode.COMMA, _CharCode.SP]; | 349 int len = bytes.length; |
| 350 final CRLF = const [_CharCode.CR, _CharCode.LF]; | 350 for (int i = 0; i < len; i++) { |
| 351 buffer[offset + i] = bytes[i]; |
| 352 } |
| 353 offset += len; |
| 354 } |
| 351 | 355 |
| 352 // Format headers. | 356 // Format headers. |
| 353 _headers.forEach((String name, List<String> values) { | 357 _headers.forEach((String name, List<String> values) { |
| 354 bool fold = _foldHeader(name); | 358 bool fold = _foldHeader(name); |
| 355 var nameData = name.codeUnits; | 359 var nameData = name.codeUnits; |
| 356 builder.add(nameData); | 360 write(nameData); |
| 357 builder.add(const [_CharCode.COLON, _CharCode.SP]); | 361 write(const [_CharCode.COLON, _CharCode.SP]); |
| 358 for (int i = 0; i < values.length; i++) { | 362 for (int i = 0; i < values.length; i++) { |
| 359 if (i > 0) { | 363 if (i > 0) { |
| 360 if (fold) { | 364 if (fold) { |
| 361 builder.add(const [_CharCode.COMMA, _CharCode.SP]); | 365 write(const [_CharCode.COMMA, _CharCode.SP]); |
| 362 } else { | 366 } else { |
| 363 builder.add(const [_CharCode.CR, _CharCode.LF]); | 367 write(const [_CharCode.CR, _CharCode.LF]); |
| 364 builder.add(nameData); | 368 write(nameData); |
| 365 builder.add(const [_CharCode.COLON, _CharCode.SP]); | 369 write(const [_CharCode.COLON, _CharCode.SP]); |
| 366 } | 370 } |
| 367 } | 371 } |
| 368 builder.add(values[i].codeUnits); | 372 write(values[i].codeUnits); |
| 369 } | 373 } |
| 370 builder.add(const [_CharCode.CR, _CharCode.LF]); | 374 write(const [_CharCode.CR, _CharCode.LF]); |
| 371 }); | 375 }); |
| 376 return offset; |
| 372 } | 377 } |
| 373 | 378 |
| 374 String toString() { | 379 String toString() { |
| 375 StringBuffer sb = new StringBuffer(); | 380 StringBuffer sb = new StringBuffer(); |
| 376 _headers.forEach((String name, List<String> values) { | 381 _headers.forEach((String name, List<String> values) { |
| 377 sb.write(name); | 382 sb.write(name); |
| 378 sb.write(": "); | 383 sb.write(": "); |
| 379 bool fold = _foldHeader(name); | 384 bool fold = _foldHeader(name); |
| 380 for (int i = 0; i < values.length; i++) { | 385 for (int i = 0; i < values.length; i++) { |
| 381 if (i > 0) { | 386 if (i > 0) { |
| (...skipping 440 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 822 void clear() { | 827 void clear() { |
| 823 throw new UnsupportedError("Cannot modify an unmodifiable map"); | 828 throw new UnsupportedError("Cannot modify an unmodifiable map"); |
| 824 } | 829 } |
| 825 void forEach(void f(K key, V value)) => _map.forEach(f); | 830 void forEach(void f(K key, V value)) => _map.forEach(f); |
| 826 Iterable<K> get keys => _map.keys; | 831 Iterable<K> get keys => _map.keys; |
| 827 Iterable<V> get values => _map.values; | 832 Iterable<V> get values => _map.values; |
| 828 int get length => _map.length; | 833 int get length => _map.length; |
| 829 bool get isEmpty => _map.isEmpty; | 834 bool get isEmpty => _map.isEmpty; |
| 830 bool get isNotEmpty => _map.isNotEmpty; | 835 bool get isNotEmpty => _map.isNotEmpty; |
| 831 } | 836 } |
| OLD | NEW |