| 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 // The rules for parsing content-types were borrowed from Firefox: | 5 // The rules for parsing content-types were borrowed from Firefox: |
| 6 // http://lxr.mozilla.org/mozilla/source/netwerk/base/src/nsURLHelper.cpp#834 | 6 // http://lxr.mozilla.org/mozilla/source/netwerk/base/src/nsURLHelper.cpp#834 |
| 7 | 7 |
| 8 #include "net/http/http_util.h" | 8 #include "net/http/http_util.h" |
| 9 | 9 |
| 10 #include <algorithm> | 10 #include <algorithm> |
| (...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 105 // Iterate over parameters | 105 // Iterate over parameters |
| 106 bool type_has_charset = false; | 106 bool type_has_charset = false; |
| 107 size_t param_start = content_type_str.find_first_of(';', type_end); | 107 size_t param_start = content_type_str.find_first_of(';', type_end); |
| 108 if (param_start != string::npos) { | 108 if (param_start != string::npos) { |
| 109 // We have parameters. Iterate over them. | 109 // We have parameters. Iterate over them. |
| 110 size_t cur_param_start = param_start + 1; | 110 size_t cur_param_start = param_start + 1; |
| 111 do { | 111 do { |
| 112 size_t cur_param_end = | 112 size_t cur_param_end = |
| 113 FindDelimiter(content_type_str, cur_param_start, ';'); | 113 FindDelimiter(content_type_str, cur_param_start, ';'); |
| 114 | 114 |
| 115 size_t param_name_start = content_type_str.find_first_not_of(HTTP_LWS, | 115 size_t param_name_start = content_type_str.find_first_not_of( |
| 116 cur_param_start); | 116 HTTP_LWS, cur_param_start); |
| 117 param_name_start = std::min(param_name_start, cur_param_end); | 117 param_name_start = std::min(param_name_start, cur_param_end); |
| 118 | 118 |
| 119 static const char charset_str[] = "charset="; | 119 static const char charset_str[] = "charset="; |
| 120 size_t charset_end_offset = std::min(param_name_start + | 120 size_t charset_end_offset = std::min( |
| 121 sizeof(charset_str) - 1, cur_param_end); | 121 param_name_start + sizeof(charset_str) - 1, cur_param_end); |
| 122 if (LowerCaseEqualsASCII(content_type_str.begin() + param_name_start, | 122 if (LowerCaseEqualsASCII( |
| 123 content_type_str.begin() + charset_end_offset, charset_str)) { | 123 content_type_str.begin() + param_name_start, |
| 124 content_type_str.begin() + charset_end_offset, charset_str)) { |
| 124 charset_val = param_name_start + sizeof(charset_str) - 1; | 125 charset_val = param_name_start + sizeof(charset_str) - 1; |
| 125 charset_end = cur_param_end; | 126 charset_end = cur_param_end; |
| 126 type_has_charset = true; | 127 type_has_charset = true; |
| 127 } | 128 } |
| 128 | 129 |
| 129 cur_param_start = cur_param_end + 1; | 130 cur_param_start = cur_param_end + 1; |
| 130 } while (cur_param_start < content_type_str.length()); | 131 } while (cur_param_start < content_type_str.length()); |
| 131 } | 132 } |
| 132 | 133 |
| 133 if (type_has_charset) { | 134 if (type_has_charset) { |
| (...skipping 19 matching lines...) Expand all Loading... |
| 153 // charset. however, if charset is empty and mime_type hasn't | 154 // charset. however, if charset is empty and mime_type hasn't |
| 154 // changed, then don't wipe-out an existing charset. We | 155 // changed, then don't wipe-out an existing charset. We |
| 155 // also want to reject a mime-type if it does not include a slash. | 156 // also want to reject a mime-type if it does not include a slash. |
| 156 // some servers give junk after the charset parameter, which may | 157 // some servers give junk after the charset parameter, which may |
| 157 // include a comma, so this check makes us a bit more tolerant. | 158 // include a comma, so this check makes us a bit more tolerant. |
| 158 if (content_type_str.length() != 0 && | 159 if (content_type_str.length() != 0 && |
| 159 content_type_str != "*/*" && | 160 content_type_str != "*/*" && |
| 160 content_type_str.find_first_of('/') != string::npos) { | 161 content_type_str.find_first_of('/') != string::npos) { |
| 161 // Common case here is that mime_type is empty | 162 // Common case here is that mime_type is empty |
| 162 bool eq = !mime_type->empty() && | 163 bool eq = !mime_type->empty() && |
| 163 LowerCaseEqualsASCII(content_type_str.begin() + type_val, | 164 LowerCaseEqualsASCII(content_type_str.begin() + type_val, |
| 164 content_type_str.begin() + type_end, | 165 content_type_str.begin() + type_end, |
| 165 mime_type->data()); | 166 mime_type->data()); |
| 166 if (!eq) { | 167 if (!eq) { |
| 167 mime_type->assign(content_type_str.begin() + type_val, | 168 mime_type->assign(content_type_str.begin() + type_val, |
| 168 content_type_str.begin() + type_end); | 169 content_type_str.begin() + type_end); |
| 169 StringToLowerASCII(mime_type); | 170 StringToLowerASCII(mime_type); |
| 170 } | 171 } |
| 171 if ((!eq && *had_charset) || type_has_charset) { | 172 if ((!eq && *had_charset) || type_has_charset) { |
| 172 *had_charset = true; | 173 *had_charset = true; |
| 173 charset->assign(content_type_str.begin() + charset_val, | 174 charset->assign(content_type_str.begin() + charset_val, |
| 174 content_type_str.begin() + charset_end); | 175 content_type_str.begin() + charset_end); |
| 175 StringToLowerASCII(charset); | 176 StringToLowerASCII(charset); |
| (...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 235 std::string::const_iterator first_byte_pos_begin = | 236 std::string::const_iterator first_byte_pos_begin = |
| 236 byte_range_set_iterator.value_begin(); | 237 byte_range_set_iterator.value_begin(); |
| 237 std::string::const_iterator first_byte_pos_end = | 238 std::string::const_iterator first_byte_pos_end = |
| 238 first_byte_pos_begin + minus_char_offset; | 239 first_byte_pos_begin + minus_char_offset; |
| 239 TrimLWS(&first_byte_pos_begin, &first_byte_pos_end); | 240 TrimLWS(&first_byte_pos_begin, &first_byte_pos_end); |
| 240 std::string first_byte_pos(first_byte_pos_begin, first_byte_pos_end); | 241 std::string first_byte_pos(first_byte_pos_begin, first_byte_pos_end); |
| 241 | 242 |
| 242 HttpByteRange range; | 243 HttpByteRange range; |
| 243 // Try to obtain first-byte-pos. | 244 // Try to obtain first-byte-pos. |
| 244 if (!first_byte_pos.empty()) { | 245 if (!first_byte_pos.empty()) { |
| 245 int64 first_byte_position = -1; | 246 int64 first_byte_position = -1; |
| 246 if (!StringToInt64(first_byte_pos, &first_byte_position)) | 247 if (!StringToInt64(first_byte_pos, &first_byte_position)) |
| 247 return false; | 248 return false; |
| 248 range.set_first_byte_position(first_byte_position); | 249 range.set_first_byte_position(first_byte_position); |
| 249 } | 250 } |
| 250 | 251 |
| 251 std::string::const_iterator last_byte_pos_begin = | 252 std::string::const_iterator last_byte_pos_begin = |
| 252 byte_range_set_iterator.value_begin() + minus_char_offset + 1; | 253 byte_range_set_iterator.value_begin() + minus_char_offset + 1; |
| 253 std::string::const_iterator last_byte_pos_end = | 254 std::string::const_iterator last_byte_pos_end = |
| 254 byte_range_set_iterator.value_end(); | 255 byte_range_set_iterator.value_end(); |
| 255 TrimLWS(&last_byte_pos_begin, &last_byte_pos_end); | 256 TrimLWS(&last_byte_pos_begin, &last_byte_pos_end); |
| 256 std::string last_byte_pos(last_byte_pos_begin, last_byte_pos_end); | 257 std::string last_byte_pos(last_byte_pos_begin, last_byte_pos_end); |
| 257 | 258 |
| 258 // We have last-byte-pos or suffix-byte-range-spec in this case. | 259 // We have last-byte-pos or suffix-byte-range-spec in this case. |
| 259 if (!last_byte_pos.empty()) { | 260 if (!last_byte_pos.empty()) { |
| (...skipping 427 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 687 TrimLWS(&value_begin_, &value_end_); | 688 TrimLWS(&value_begin_, &value_end_); |
| 688 | 689 |
| 689 // bypass empty values. | 690 // bypass empty values. |
| 690 if (value_begin_ != value_end_) | 691 if (value_begin_ != value_end_) |
| 691 return true; | 692 return true; |
| 692 } | 693 } |
| 693 return false; | 694 return false; |
| 694 } | 695 } |
| 695 | 696 |
| 696 } // namespace net | 697 } // namespace net |
| OLD | NEW |