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

Side by Side Diff: net/http/http_util.h

Issue 458: [new http] Normalize line continuations in response headers. (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: '' Created 12 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 | « net/http/http_response_headers_unittest.cc ('k') | net/http/http_util.cc » ('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) 2006-2008 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2006-2008 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 #ifndef NET_HTTP_HTTP_UTIL_H_ 5 #ifndef NET_HTTP_HTTP_UTIL_H_
6 #define NET_HTTP_HTTP_UTIL_H_ 6 #define NET_HTTP_HTTP_UTIL_H_
7 7
8 #include "base/string_tokenizer.h" 8 #include "base/string_tokenizer.h"
9 9
10 // This is a macro to support extending this string literal at compile time. 10 // This is a macro to support extending this string literal at compile time.
(...skipping 28 matching lines...) Expand all
39 39
40 // Multiple occurances of some headers cannot be coalesced into a comma- 40 // Multiple occurances of some headers cannot be coalesced into a comma-
41 // separated list since their values are (or contain) unquoted HTTP-date 41 // separated list since their values are (or contain) unquoted HTTP-date
42 // values, which may contain a comma (see RFC 2616 section 3.3.1). 42 // values, which may contain a comma (see RFC 2616 section 3.3.1).
43 static bool IsNonCoalescingHeader(std::string::const_iterator name_begin, 43 static bool IsNonCoalescingHeader(std::string::const_iterator name_begin,
44 std::string::const_iterator name_end); 44 std::string::const_iterator name_end);
45 static bool IsNonCoalescingHeader(const std::string& name) { 45 static bool IsNonCoalescingHeader(const std::string& name) {
46 return IsNonCoalescingHeader(name.begin(), name.end()); 46 return IsNonCoalescingHeader(name.begin(), name.end());
47 } 47 }
48 48
49 // Return true if the character is HTTP "linear white space" (SP | HT).
50 // This definition corresponds with the HTTP_LWS macro, and does not match
51 // newlines.
52 static bool IsLWS(char c);
53
49 // Trim HTTP_LWS chars from the beginning and end of the string. 54 // Trim HTTP_LWS chars from the beginning and end of the string.
50 static void TrimLWS(std::string::const_iterator* begin, 55 static void TrimLWS(std::string::const_iterator* begin,
51 std::string::const_iterator* end); 56 std::string::const_iterator* end);
52 57
53 // Returns index beyond the end-of-headers marker or -1 if not found. RFC 58 // Returns index beyond the end-of-headers marker or -1 if not found. RFC
54 // 2616 defines the end-of-headers marker as a double CRLF; however, some 59 // 2616 defines the end-of-headers marker as a double CRLF; however, some
55 // servers only send back LFs (e.g., Unix-based CGI scripts written using the 60 // servers only send back LFs (e.g., Unix-based CGI scripts written using the
56 // ASIS Apache module). This function therefore accepts the pattern LF[CR]LF 61 // ASIS Apache module). This function therefore accepts the pattern LF[CR]LF
57 // as end-of-headers (just like Mozilla). 62 // as end-of-headers (just like Mozilla).
58 static int LocateEndOfHeaders(const char* buf, int buf_len); 63 static int LocateEndOfHeaders(const char* buf, int buf_len);
59 64
60 // Assemble "raw headers" in the format required by HttpResponseHeaders. 65 // Assemble "raw headers" in the format required by HttpResponseHeaders.
61 // This involves normalizing line terminators, converting [CR]LF to \0 and 66 // This involves normalizing line terminators, converting [CR]LF to \0 and
62 // handling HTTP line continuations (i.e., lines starting with LWS are 67 // handling HTTP line continuations (i.e., lines starting with LWS are
63 // continuations of the previous line). |buf_len| indicates the position of 68 // continuations of the previous line). |buf_len| indicates the position of
64 // the end-of-headers marker as defined by LocateEndOfHeaders. 69 // the end-of-headers marker as defined by LocateEndOfHeaders.
65 static std::string AssembleRawHeaders(const char* buf, int buf_len); 70 static std::string AssembleRawHeaders(const char* buf, int buf_len);
66 71
67 // Used to iterate over the name/value pairs of HTTP headers. To iterate 72 // Used to iterate over the name/value pairs of HTTP headers. To iterate
68 // over the values in a multi-value header, use ValuesIterator. 73 // over the values in a multi-value header, use ValuesIterator.
74 // See AssembleRawHeaders for joining line continuations (this iterator
75 // does not expect any).
69 class HeadersIterator { 76 class HeadersIterator {
70 public: 77 public:
71 HeadersIterator(std::string::const_iterator headers_begin, 78 HeadersIterator(std::string::const_iterator headers_begin,
72 std::string::const_iterator headers_end, 79 std::string::const_iterator headers_end,
73 const std::string& line_delimiter); 80 const std::string& line_delimiter);
74 81
75 // Advances the iterator to the next header, if any. Returns true if there 82 // Advances the iterator to the next header, if any. Returns true if there
76 // is a next header. Use name* and values* methods to access the resultant 83 // is a next header. Use name* and values* methods to access the resultant
77 // header name and values. 84 // header name and values.
78 bool GetNext(); 85 bool GetNext();
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after
140 StringTokenizer values_; 147 StringTokenizer values_;
141 std::string::const_iterator value_begin_; 148 std::string::const_iterator value_begin_;
142 std::string::const_iterator value_end_; 149 std::string::const_iterator value_end_;
143 }; 150 };
144 }; 151 };
145 152
146 } // namespace net 153 } // namespace net
147 154
148 #endif // NET_HTTP_HTTP_UTIL_H_ 155 #endif // NET_HTTP_HTTP_UTIL_H_
149 156
OLDNEW
« no previous file with comments | « net/http/http_response_headers_unittest.cc ('k') | net/http/http_util.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698