OLD | NEW |
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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 header parsing were borrowed from Firefox: | 5 // The rules for header parsing were borrowed from Firefox: |
6 // http://lxr.mozilla.org/seamonkey/source/netwerk/protocol/http/src/nsHttpRespo
nseHead.cpp | 6 // http://lxr.mozilla.org/seamonkey/source/netwerk/protocol/http/src/nsHttpRespo
nseHead.cpp |
7 // The rules for parsing content-types were also borrowed from Firefox: | 7 // The rules for parsing content-types were also borrowed from Firefox: |
8 // http://lxr.mozilla.org/mozilla/source/netwerk/base/src/nsURLHelper.cpp#834 | 8 // http://lxr.mozilla.org/mozilla/source/netwerk/base/src/nsURLHelper.cpp#834 |
9 | 9 |
10 #include "net/http/http_response_headers.h" | 10 #include "net/http/http_response_headers.h" |
(...skipping 580 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
591 | 591 |
592 if (p == code) { | 592 if (p == code) { |
593 DVLOG(1) << "missing response status number; assuming 200"; | 593 DVLOG(1) << "missing response status number; assuming 200"; |
594 raw_headers_.append(" 200 OK"); | 594 raw_headers_.append(" 200 OK"); |
595 response_code_ = 200; | 595 response_code_ = 200; |
596 return; | 596 return; |
597 } | 597 } |
598 raw_headers_.push_back(' '); | 598 raw_headers_.push_back(' '); |
599 raw_headers_.append(code, p); | 599 raw_headers_.append(code, p); |
600 raw_headers_.push_back(' '); | 600 raw_headers_.push_back(' '); |
601 base::StringToInt(std::string(code, p), &response_code_); | 601 base::StringToInt(code, p, &response_code_); |
602 | 602 |
603 // Skip whitespace. | 603 // Skip whitespace. |
604 while (*p == ' ') | 604 while (*p == ' ') |
605 ++p; | 605 ++p; |
606 | 606 |
607 // Trim trailing whitespace. | 607 // Trim trailing whitespace. |
608 while (line_end > p && line_end[-1] == ' ') | 608 while (line_end > p && line_end[-1] == ' ') |
609 --line_end; | 609 --line_end; |
610 | 610 |
611 if (p == line_end) { | 611 if (p == line_end) { |
(...skipping 354 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
966 const char kMaxAgePrefix[] = "max-age="; | 966 const char kMaxAgePrefix[] = "max-age="; |
967 const size_t kMaxAgePrefixLen = arraysize(kMaxAgePrefix) - 1; | 967 const size_t kMaxAgePrefixLen = arraysize(kMaxAgePrefix) - 1; |
968 | 968 |
969 void* iter = NULL; | 969 void* iter = NULL; |
970 while (EnumerateHeader(&iter, name, &value)) { | 970 while (EnumerateHeader(&iter, name, &value)) { |
971 if (value.size() > kMaxAgePrefixLen) { | 971 if (value.size() > kMaxAgePrefixLen) { |
972 if (LowerCaseEqualsASCII(value.begin(), | 972 if (LowerCaseEqualsASCII(value.begin(), |
973 value.begin() + kMaxAgePrefixLen, | 973 value.begin() + kMaxAgePrefixLen, |
974 kMaxAgePrefix)) { | 974 kMaxAgePrefix)) { |
975 int64 seconds; | 975 int64 seconds; |
976 base::StringToInt64(value.substr(kMaxAgePrefixLen), &seconds); | 976 base::StringToInt64(value.begin() + kMaxAgePrefixLen, |
| 977 value.end(), |
| 978 &seconds); |
977 *result = TimeDelta::FromSeconds(seconds); | 979 *result = TimeDelta::FromSeconds(seconds); |
978 return true; | 980 return true; |
979 } | 981 } |
980 } | 982 } |
981 } | 983 } |
982 | 984 |
983 return false; | 985 return false; |
984 } | 986 } |
985 | 987 |
986 bool HttpResponseHeaders::GetAgeValue(TimeDelta* result) const { | 988 bool HttpResponseHeaders::GetAgeValue(TimeDelta* result) const { |
(...skipping 154 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1141 if (!LowerCaseEqualsASCII(byte_range_resp_spec, "*")) { | 1143 if (!LowerCaseEqualsASCII(byte_range_resp_spec, "*")) { |
1142 size_t minus_position = byte_range_resp_spec.find('-'); | 1144 size_t minus_position = byte_range_resp_spec.find('-'); |
1143 if (minus_position != std::string::npos) { | 1145 if (minus_position != std::string::npos) { |
1144 // Obtain first-byte-pos. | 1146 // Obtain first-byte-pos. |
1145 std::string::const_iterator first_byte_pos_begin = | 1147 std::string::const_iterator first_byte_pos_begin = |
1146 byte_range_resp_spec.begin(); | 1148 byte_range_resp_spec.begin(); |
1147 std::string::const_iterator first_byte_pos_end = | 1149 std::string::const_iterator first_byte_pos_end = |
1148 byte_range_resp_spec.begin() + minus_position; | 1150 byte_range_resp_spec.begin() + minus_position; |
1149 HttpUtil::TrimLWS(&first_byte_pos_begin, &first_byte_pos_end); | 1151 HttpUtil::TrimLWS(&first_byte_pos_begin, &first_byte_pos_end); |
1150 | 1152 |
1151 bool ok = base::StringToInt64( | 1153 bool ok = base::StringToInt64(first_byte_pos_begin, |
1152 std::string(first_byte_pos_begin, first_byte_pos_end), | 1154 first_byte_pos_end, |
1153 first_byte_position); | 1155 first_byte_position); |
1154 | 1156 |
1155 // Obtain last-byte-pos. | 1157 // Obtain last-byte-pos. |
1156 std::string::const_iterator last_byte_pos_begin = | 1158 std::string::const_iterator last_byte_pos_begin = |
1157 byte_range_resp_spec.begin() + minus_position + 1; | 1159 byte_range_resp_spec.begin() + minus_position + 1; |
1158 std::string::const_iterator last_byte_pos_end = | 1160 std::string::const_iterator last_byte_pos_end = |
1159 byte_range_resp_spec.end(); | 1161 byte_range_resp_spec.end(); |
1160 HttpUtil::TrimLWS(&last_byte_pos_begin, &last_byte_pos_end); | 1162 HttpUtil::TrimLWS(&last_byte_pos_begin, &last_byte_pos_end); |
1161 | 1163 |
1162 ok &= base::StringToInt64( | 1164 ok &= base::StringToInt64(last_byte_pos_begin, |
1163 std::string(last_byte_pos_begin, last_byte_pos_end), | 1165 last_byte_pos_end, |
1164 last_byte_position); | 1166 last_byte_position); |
1165 if (!ok) { | 1167 if (!ok) { |
1166 *first_byte_position = *last_byte_position = -1; | 1168 *first_byte_position = *last_byte_position = -1; |
1167 return false; | 1169 return false; |
1168 } | 1170 } |
1169 if (*first_byte_position < 0 || *last_byte_position < 0 || | 1171 if (*first_byte_position < 0 || *last_byte_position < 0 || |
1170 *first_byte_position > *last_byte_position) | 1172 *first_byte_position > *last_byte_position) |
1171 return false; | 1173 return false; |
1172 } else { | 1174 } else { |
1173 return false; | 1175 return false; |
1174 } | 1176 } |
1175 } | 1177 } |
1176 | 1178 |
1177 // Parse the instance-length part. | 1179 // Parse the instance-length part. |
1178 // If instance-length == "*". | 1180 // If instance-length == "*". |
1179 std::string::const_iterator instance_length_begin = | 1181 std::string::const_iterator instance_length_begin = |
1180 content_range_spec.begin() + slash_position + 1; | 1182 content_range_spec.begin() + slash_position + 1; |
1181 std::string::const_iterator instance_length_end = | 1183 std::string::const_iterator instance_length_end = |
1182 content_range_spec.end(); | 1184 content_range_spec.end(); |
1183 HttpUtil::TrimLWS(&instance_length_begin, &instance_length_end); | 1185 HttpUtil::TrimLWS(&instance_length_begin, &instance_length_end); |
1184 | 1186 |
1185 if (LowerCaseEqualsASCII(instance_length_begin, instance_length_end, "*")) { | 1187 if (LowerCaseEqualsASCII(instance_length_begin, instance_length_end, "*")) { |
1186 return false; | 1188 return false; |
1187 } else if (!base::StringToInt64( | 1189 } else if (!base::StringToInt64(instance_length_begin, |
1188 std::string(instance_length_begin, instance_length_end), | 1190 instance_length_end, |
1189 instance_length)) { | 1191 instance_length)) { |
1190 *instance_length = -1; | 1192 *instance_length = -1; |
1191 return false; | 1193 return false; |
1192 } | 1194 } |
1193 | 1195 |
1194 // We have all the values; let's verify that they make sense for a 206 | 1196 // We have all the values; let's verify that they make sense for a 206 |
1195 // response. | 1197 // response. |
1196 if (*first_byte_position < 0 || *last_byte_position < 0 || | 1198 if (*first_byte_position < 0 || *last_byte_position < 0 || |
1197 *instance_length < 0 || *instance_length - 1 < *last_byte_position) | 1199 *instance_length < 0 || *instance_length - 1 < *last_byte_position) |
1198 return false; | 1200 return false; |
1199 | 1201 |
1200 return true; | 1202 return true; |
1201 } | 1203 } |
1202 | 1204 |
1203 } // namespace net | 1205 } // namespace net |
OLD | NEW |