Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(349)

Side by Side Diff: sdk/lib/io/http_headers.dart

Issue 12504006: Make IOSink implement StringSink (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Addressed second round of review comments Created 7 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « sdk/lib/io/http.dart ('k') | sdk/lib/io/http_impl.dart » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 332 matching lines...) Expand 10 before | Expand all | Expand 10 after
343 _write(IOSink sink) { 343 _write(IOSink sink) {
344 final COLONSP = const [_CharCode.COLON, _CharCode.SP]; 344 final COLONSP = const [_CharCode.COLON, _CharCode.SP];
345 final COMMASP = const [_CharCode.COMMA, _CharCode.SP]; 345 final COMMASP = const [_CharCode.COMMA, _CharCode.SP];
346 final CRLF = const [_CharCode.CR, _CharCode.LF]; 346 final CRLF = const [_CharCode.CR, _CharCode.LF];
347 347
348 var bufferSize = 16 * 1024; 348 var bufferSize = 16 * 1024;
349 var buffer = new Uint8List(bufferSize); 349 var buffer = new Uint8List(bufferSize);
350 var bufferPos = 0; 350 var bufferPos = 0;
351 351
352 void writeBuffer() { 352 void writeBuffer() {
353 sink.add(buffer.getRange(0, bufferPos)); 353 sink.writeBytes(buffer.getRange(0, bufferPos));
354 bufferPos = 0; 354 bufferPos = 0;
355 } 355 }
356 356
357 // Format headers. 357 // Format headers.
358 _headers.forEach((String name, List<String> values) { 358 _headers.forEach((String name, List<String> values) {
359 bool fold = _foldHeader(name); 359 bool fold = _foldHeader(name);
360 List<int> nameData; 360 List<int> nameData;
361 nameData = name.codeUnits; 361 nameData = name.codeUnits;
362 int nameDataLen = nameData.length; 362 int nameDataLen = nameData.length;
363 if (nameDataLen + 2 > bufferSize - bufferPos) writeBuffer(); 363 if (nameDataLen + 2 > bufferSize - bufferPos) writeBuffer();
(...skipping 250 matching lines...) Expand 10 before | Expand all | Expand 10 after
614 _value = parseValue(); 614 _value = parseValue();
615 skipWS(); 615 skipWS();
616 if (done()) return; 616 if (done()) return;
617 maybeExpect(parameterSeparator); 617 maybeExpect(parameterSeparator);
618 parseParameters(); 618 parseParameters();
619 } 619 }
620 } 620 }
621 621
622 622
623 class _ContentType extends _HeaderValue implements ContentType { 623 class _ContentType extends _HeaderValue implements ContentType {
624 String _primaryType = "";
625 String _subType = "";
626
624 _ContentType(String primaryType, 627 _ContentType(String primaryType,
625 String subType, 628 String subType,
626 String charset, 629 String charset,
627 Map<String, String> parameters) 630 Map<String, String> parameters)
628 : _primaryType = primaryType, _subType = subType, super("") { 631 : _primaryType = primaryType, _subType = subType, super("") {
629 if (_primaryType == null) _primaryType = ""; 632 if (_primaryType == null) _primaryType = "";
630 if (_subType == null) _subType = ""; 633 if (_subType == null) _subType = "";
631 _value = "$_primaryType/$_subType";; 634 _value = "$_primaryType/$_subType";;
632 if (parameters != null) { 635 if (parameters != null) {
633 parameters.forEach((String key, String value) { 636 parameters.forEach((String key, String value) {
634 this.parameters[key.toLowerCase()] = value.toLowerCase(); 637 this.parameters[key.toLowerCase()] = value.toLowerCase();
635 }); 638 });
636 } 639 }
637 if (charset != null) { 640 if (charset != null) {
638 this.parameters["charset"] = charset.toLowerCase(); 641 this.parameters["charset"] = charset.toLowerCase();
639 } 642 }
640 } 643 }
641 644
642 _ContentType.fromString(String value) : super.fromString(value) { 645 _ContentType.fromString(String value) : super.fromString(value) {
643 int index = _value.indexOf("/"); 646 int index = _value.indexOf("/");
644 if (index == -1 || index == (_value.length - 1)) { 647 if (index == -1 || index == (_value.length - 1)) {
645 _primaryType = _value.trim().toLowerCase(); 648 _primaryType = _value.trim().toLowerCase();
646 _subType = ""; 649 _subType = "";
647 } else { 650 } else {
648 _primaryType = _value.substring(0, index).trim().toLowerCase(); 651 _primaryType = _value.substring(0, index).trim().toLowerCase();
649 _subType = _value.substring(index + 1).trim().toLowerCase(); 652 _subType = _value.substring(index + 1).trim().toLowerCase();
650 } 653 }
651 } 654 }
652 655
653 String get primaryType => _primaryType; 656 String get primaryType => _primaryType;
654 657
655 String get subType => _subType; 658 String get subType => _subType;
656 659
657 String get charset => parameters["charset"]; 660 String get charset => parameters["charset"];
658
659 String _primaryType = "";
660 String _subType = "";
661 } 661 }
662 662
663 663
664 class _Cookie implements Cookie { 664 class _Cookie implements Cookie {
665 _Cookie([String this.name, String this.value]); 665 _Cookie([String this.name, String this.value]);
666 666
667 _Cookie.fromSetCookieValue(String value) { 667 _Cookie.fromSetCookieValue(String value) {
668 // Parse the 'set-cookie' header value. 668 // Parse the 'set-cookie' header value.
669 _parseSetCookieValue(value); 669 _parseSetCookieValue(value);
670 } 670 }
(...skipping 112 matching lines...) Expand 10 before | Expand all | Expand 10 after
783 783
784 String name; 784 String name;
785 String value; 785 String value;
786 DateTime expires; 786 DateTime expires;
787 int maxAge; 787 int maxAge;
788 String domain; 788 String domain;
789 String path; 789 String path;
790 bool httpOnly = false; 790 bool httpOnly = false;
791 bool secure = false; 791 bool secure = false;
792 } 792 }
OLDNEW
« no previous file with comments | « sdk/lib/io/http.dart ('k') | sdk/lib/io/http_impl.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698