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

Side by Side Diff: net/spdy/spdy_framer.cc

Issue 10957038: net: separate SPDY cookies with "; " as the new RFC requires. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: address willchan's comments Created 8 years, 3 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 | third_party/zlib/deflate.h » ('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) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 // TODO(rtenhove) clean up frame buffer size calculations so that we aren't 5 // TODO(rtenhove) clean up frame buffer size calculations so that we aren't
6 // constantly adding and subtracting header sizes; this is ugly and error- 6 // constantly adding and subtracting header sizes; this is ugly and error-
7 // prone. 7 // prone.
8 8
9 #include "net/spdy/spdy_framer.h" 9 #include "net/spdy/spdy_framer.h"
10 10
(...skipping 722 matching lines...) Expand 10 before | Expand all | Expand 10 after
733 length_length = 2; 733 length_length = 2;
734 734
735 WriteLengthZ(headers->size(), length_length, kZStandardData, z); 735 WriteLengthZ(headers->size(), length_length, kZStandardData, z);
736 736
737 std::map<std::string, std::string>::const_iterator it; 737 std::map<std::string, std::string>::const_iterator it;
738 for (it = headers->begin(); it != headers->end(); ++it) { 738 for (it = headers->begin(); it != headers->end(); ++it) {
739 WriteLengthZ(it->first.size(), length_length, kZStandardData, z); 739 WriteLengthZ(it->first.size(), length_length, kZStandardData, z);
740 WriteZ(it->first, kZStandardData, z); 740 WriteZ(it->first, kZStandardData, z);
741 741
742 if (it->first == "cookie") { 742 if (it->first == "cookie") {
743 // We require the cookie values to end with a semi-colon and (save for 743 // We require the cookie values (save for the last) to end with a
744 // the first) to start with one too. The values are already separated by 744 // semicolon and (save for the first) to start with a space. This is
745 // semicolons in the header, but there's usually whitespace in there too. 745 // typically the format that we are given them in but we reserialize them
746 // So we accumulate the values without whitespace in |cookie_values| and 746 // to be sure.
747 // write them out, along with a final semicolon to terminate the last
748 // cookie.
749 747
750 std::string last_cookie;
751 std::vector<base::StringPiece> cookie_values; 748 std::vector<base::StringPiece> cookie_values;
752 size_t cookie_length = 0; 749 size_t cookie_length = 0;
753 base::StringPiece cookie_data(it->second); 750 base::StringPiece cookie_data(it->second);
754 751
755 for (;;) { 752 for (;;) {
756 while (!cookie_data.empty() && 753 while (!cookie_data.empty() &&
757 (cookie_data[0] == ' ' || cookie_data[0] == '\t')) { 754 (cookie_data[0] == ' ' || cookie_data[0] == '\t')) {
758 cookie_data.remove_prefix(1); 755 cookie_data.remove_prefix(1);
759 } 756 }
760 if (cookie_data.empty()) 757 if (cookie_data.empty())
761 break; 758 break;
762 759
763 size_t i; 760 size_t i;
764 for (i = 0; i < cookie_data.size(); i++) { 761 for (i = 0; i < cookie_data.size(); i++) {
765 if (cookie_data[i] == ';') 762 if (cookie_data[i] == ';')
766 break; 763 break;
767 } 764 }
768 if (i < cookie_data.size()) { 765 if (i < cookie_data.size()) {
769 cookie_values.push_back(cookie_data.substr(0, i+1)); 766 cookie_values.push_back(cookie_data.substr(0, i));
770 cookie_length += i+1; 767 cookie_length += i + 2 /* semicolon and space */;
771 cookie_data.remove_prefix(i + 1); 768 cookie_data.remove_prefix(i + 1);
772 } else { 769 } else {
773 last_cookie = cookie_data.as_string() + ";"; 770 cookie_values.push_back(cookie_data);
774 cookie_values.push_back(last_cookie); 771 cookie_length += cookie_data.size();
775 cookie_length += last_cookie.size();
776 cookie_data.remove_prefix(i); 772 cookie_data.remove_prefix(i);
777 } 773 }
778 } 774 }
779 775
780 WriteLengthZ(cookie_length, length_length, kZStandardData, z); 776 WriteLengthZ(cookie_length, length_length, kZStandardData, z);
781 for (std::vector<base::StringPiece>::const_iterator 777 for (size_t i = 0; i < cookie_values.size(); i++) {
782 i = cookie_values.begin(); i != cookie_values.end(); i++) { 778 std::string cookie;
783 WriteZ(*i, kZCookieData, z); 779 // Since zlib will only back-reference complete cookies, a cookie that
780 // is currently last (and so doesn't have a trailing semicolon) won't
781 // match if it's later in a non-final position. The same is true of
782 // the first cookie.
783 if (i == 0 && cookie_values.size() == 1) {
784 cookie = cookie_values[i].as_string();
785 } else if (i == 0) {
786 cookie = cookie_values[i].as_string() + ";";
787 } else if (i < cookie_values.size() - 1) {
788 cookie = " " + cookie_values[i].as_string() + ";";
789 } else {
790 cookie = " " + cookie_values[i].as_string();
791 }
792 WriteZ(cookie, kZCookieData, z);
784 } 793 }
785 } else if (it->first == "accept" || 794 } else if (it->first == "accept" ||
786 it->first == "accept-charset" || 795 it->first == "accept-charset" ||
787 it->first == "accept-encoding" || 796 it->first == "accept-encoding" ||
788 it->first == "accept-language" || 797 it->first == "accept-language" ||
789 it->first == "host" || 798 it->first == "host" ||
790 it->first == "version" || 799 it->first == "version" ||
791 it->first == "method" || 800 it->first == "method" ||
792 it->first == "scheme" || 801 it->first == "scheme" ||
793 it->first == ":host" || 802 it->first == ":host" ||
(...skipping 1040 matching lines...) Expand 10 before | Expand all | Expand 10 after
1834 } 1843 }
1835 } 1844 }
1836 return stream_id; 1845 return stream_id;
1837 } 1846 }
1838 1847
1839 void SpdyFramer::set_enable_compression(bool value) { 1848 void SpdyFramer::set_enable_compression(bool value) {
1840 enable_compression_ = value; 1849 enable_compression_ = value;
1841 } 1850 }
1842 1851
1843 } // namespace net 1852 } // namespace net
OLDNEW
« no previous file with comments | « no previous file | third_party/zlib/deflate.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698