Chromium Code Reviews| OLD | NEW |
|---|---|
| 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 #include "googleurl/src/gurl.h" | 9 #include "googleurl/src/gurl.h" |
| 10 | 10 |
| (...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 95 // The parameter |i| is the offset within |buf| to begin searching from. | 95 // The parameter |i| is the offset within |buf| to begin searching from. |
| 96 static int LocateEndOfHeaders(const char* buf, int buf_len, int i = 0); | 96 static int LocateEndOfHeaders(const char* buf, int buf_len, int i = 0); |
| 97 | 97 |
| 98 // Assemble "raw headers" in the format required by HttpResponseHeaders. | 98 // Assemble "raw headers" in the format required by HttpResponseHeaders. |
| 99 // This involves normalizing line terminators, converting [CR]LF to \0 and | 99 // This involves normalizing line terminators, converting [CR]LF to \0 and |
| 100 // handling HTTP line continuations (i.e., lines starting with LWS are | 100 // handling HTTP line continuations (i.e., lines starting with LWS are |
| 101 // continuations of the previous line). |buf_len| indicates the position of | 101 // continuations of the previous line). |buf_len| indicates the position of |
| 102 // the end-of-headers marker as defined by LocateEndOfHeaders. | 102 // the end-of-headers marker as defined by LocateEndOfHeaders. |
| 103 static std::string AssembleRawHeaders(const char* buf, int buf_len); | 103 static std::string AssembleRawHeaders(const char* buf, int buf_len); |
| 104 | 104 |
| 105 // Given a comma separated ordered list of language codes, return | |
| 106 // the list with a qvalue appended to each language. | |
| 107 // The way qvalues are assigned is rather simple. The qvalue | |
| 108 // starts with 1.0 and is decremented by 0.2 for each successive entry | |
| 109 // in the list until it reaches 0.2. All the entries after that are | |
| 110 // assigned the same qvalue of 0.2. Also, note that the 1st language | |
| 111 // will not have a qvalue added because the absence of a qvalue means | |
| 112 // q=1.0 implicitly. | |
| 113 | |
|
wtc
2009/01/14 02:21:48
Nit: add // for the blank line.
| |
| 114 // When making a http request, this should be used to determine what | |
| 115 // to put in Accept-Language header. If a comma separated list of language | |
| 116 // codes *without* qvalue is sent, web servers regard all | |
| 117 // of them as having q=1.0 and pick one of them even though it may not | |
| 118 // be at the beginning of the list (see http://crbug.com/5899). | |
| 119 static std::string GenerateAcceptLanguageHeader( | |
| 120 const std::string& raw_language_list); | |
| 121 | |
| 122 // Given a charset, return the list with a qvalue. If charset is utf-8, | |
| 123 // it will return 'utf-8,*;q=0.5'. Otherwise (e.g. 'euc-jp'), it'll return | |
| 124 // 'euc-jp,utf-8;q=0.7,*;q=0.3'. | |
| 125 static std::string GenerateAcceptCharsetHeader(const std::string& charset); | |
| 126 | |
| 105 // Used to iterate over the name/value pairs of HTTP headers. To iterate | 127 // Used to iterate over the name/value pairs of HTTP headers. To iterate |
| 106 // over the values in a multi-value header, use ValuesIterator. | 128 // over the values in a multi-value header, use ValuesIterator. |
| 107 // See AssembleRawHeaders for joining line continuations (this iterator | 129 // See AssembleRawHeaders for joining line continuations (this iterator |
| 108 // does not expect any). | 130 // does not expect any). |
| 109 class HeadersIterator { | 131 class HeadersIterator { |
| 110 public: | 132 public: |
| 111 HeadersIterator(std::string::const_iterator headers_begin, | 133 HeadersIterator(std::string::const_iterator headers_begin, |
| 112 std::string::const_iterator headers_end, | 134 std::string::const_iterator headers_end, |
| 113 const std::string& line_delimiter); | 135 const std::string& line_delimiter); |
| 114 | 136 |
| (...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 180 StringTokenizer values_; | 202 StringTokenizer values_; |
| 181 std::string::const_iterator value_begin_; | 203 std::string::const_iterator value_begin_; |
| 182 std::string::const_iterator value_end_; | 204 std::string::const_iterator value_end_; |
| 183 }; | 205 }; |
| 184 }; | 206 }; |
| 185 | 207 |
| 186 } // namespace net | 208 } // namespace net |
| 187 | 209 |
| 188 #endif // NET_HTTP_HTTP_UTIL_H_ | 210 #endif // NET_HTTP_HTTP_UTIL_H_ |
| 189 | 211 |
| OLD | NEW |