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

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

Issue 151123003: Skip bad cookies in http headers. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 6 years, 10 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 | « no previous file | tests/standalone/io/http_headers_test.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 final Map<String, List<String>> _headers; 8 final Map<String, List<String>> _headers;
9 final String protocolVersion; 9 final String protocolVersion;
10 10
(...skipping 426 matching lines...) Expand 10 before | Expand all | Expand 10 after
437 }); 437 });
438 return sb.toString(); 438 return sb.toString();
439 } 439 }
440 440
441 List<Cookie> _parseCookies() { 441 List<Cookie> _parseCookies() {
442 // Parse a Cookie header value according to the rules in RFC 6265. 442 // Parse a Cookie header value according to the rules in RFC 6265.
443 var cookies = new List<Cookie>(); 443 var cookies = new List<Cookie>();
444 void parseCookieString(String s) { 444 void parseCookieString(String s) {
445 int index = 0; 445 int index = 0;
446 446
447 bool done() => index == s.length; 447 bool done() => index == -1 || index == s.length;
448 448
449 void skipWS() { 449 void skipWS() {
450 while (!done()) { 450 while (!done()) {
451 if (s[index] != " " && s[index] != "\t") return; 451 if (s[index] != " " && s[index] != "\t") return;
452 index++; 452 index++;
453 } 453 }
454 } 454 }
455 455
456 String parseName() { 456 String parseName() {
457 int start = index; 457 int start = index;
458 while (!done()) { 458 while (!done()) {
459 if (s[index] == " " || s[index] == "\t" || s[index] == "=") break; 459 if (s[index] == " " || s[index] == "\t" || s[index] == "=") break;
460 index++; 460 index++;
461 } 461 }
462 return s.substring(start, index); 462 return s.substring(start, index);
463 } 463 }
464 464
465 String parseValue() { 465 String parseValue() {
466 int start = index; 466 int start = index;
467 while (!done()) { 467 while (!done()) {
468 if (s[index] == " " || s[index] == "\t" || s[index] == ";") break; 468 if (s[index] == " " || s[index] == "\t" || s[index] == ";") break;
469 index++; 469 index++;
470 } 470 }
471 return s.substring(start, index); 471 return s.substring(start, index);
472 } 472 }
473 473
474 void expect(String expected) { 474 bool expect(String expected) {
475 if (done()) { 475 if (done()) return false;
476 throw new HttpException("Failed to parse header value [$s]"); 476 if (s[index] != expected) return false;
477 }
478 if (s[index] != expected) {
479 throw new HttpException("Failed to parse header value [$s]");
480 }
481 index++; 477 index++;
478 return true;
482 } 479 }
483 480
484 while (!done()) { 481 while (!done()) {
485 skipWS(); 482 skipWS();
486 if (done()) return; 483 if (done()) return;
487 String name = parseName(); 484 String name = parseName();
488 skipWS(); 485 skipWS();
489 expect("="); 486 if (!expect("=")) {
487 index = s.indexOf(';', index);
488 continue;
489 }
490 skipWS(); 490 skipWS();
491 String value = parseValue(); 491 String value = parseValue();
492 cookies.add(new _Cookie(name, value)); 492 cookies.add(new _Cookie(name, value));
493 skipWS(); 493 skipWS();
494 if (done()) return; 494 if (done()) return;
495 expect(";"); 495 if (!expect(";")) {
496 index = s.indexOf(';', index);
497 continue;
498 }
496 } 499 }
497 } 500 }
498 List<String> values = _headers[HttpHeaders.COOKIE]; 501 List<String> values = _headers[HttpHeaders.COOKIE];
499 if (values != null) { 502 if (values != null) {
500 values.forEach((headerValue) => parseCookieString(headerValue)); 503 values.forEach((headerValue) => parseCookieString(headerValue));
501 } 504 }
502 return cookies; 505 return cookies;
503 } 506 }
504 } 507 }
505 508
(...skipping 340 matching lines...) Expand 10 before | Expand all | Expand 10 after
846 void clear() { 849 void clear() {
847 throw new UnsupportedError("Cannot modify an unmodifiable map"); 850 throw new UnsupportedError("Cannot modify an unmodifiable map");
848 } 851 }
849 void forEach(void f(K key, V value)) => _map.forEach(f); 852 void forEach(void f(K key, V value)) => _map.forEach(f);
850 Iterable<K> get keys => _map.keys; 853 Iterable<K> get keys => _map.keys;
851 Iterable<V> get values => _map.values; 854 Iterable<V> get values => _map.values;
852 int get length => _map.length; 855 int get length => _map.length;
853 bool get isEmpty => _map.isEmpty; 856 bool get isEmpty => _map.isEmpty;
854 bool get isNotEmpty => _map.isNotEmpty; 857 bool get isNotEmpty => _map.isNotEmpty;
855 } 858 }
OLDNEW
« no previous file with comments | « no previous file | tests/standalone/io/http_headers_test.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698