| 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 #include "config.h" | 5 #include "config.h" |
| 6 #include <string> | 6 #include <string> |
| 7 | 7 |
| 8 #pragma warning(push, 0) | 8 #pragma warning(push, 0) |
| 9 #include "HTTPHeaderMap.h" | 9 #include "HTTPHeaderMap.h" |
| 10 #include "ResourceHandle.h" | 10 #include "ResourceHandle.h" |
| (...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 65 } | 65 } |
| 66 | 66 |
| 67 if (data_.substr(0, boundary_.length()) != boundary_) { | 67 if (data_.substr(0, boundary_.length()) != boundary_) { |
| 68 data_ = boundary_ + "\n" + data_; | 68 data_ = boundary_ + "\n" + data_; |
| 69 } | 69 } |
| 70 } | 70 } |
| 71 DCHECK(!first_received_data_); | 71 DCHECK(!first_received_data_); |
| 72 | 72 |
| 73 // Headers | 73 // Headers |
| 74 if (processing_headers_) { | 74 if (processing_headers_) { |
| 75 // Eat leading \r\n |
| 76 int pos = PushOverLine(data_, 0); |
| 77 if (pos) |
| 78 data_ = data_.substr(pos); |
| 79 |
| 75 if (ParseHeaders()) { | 80 if (ParseHeaders()) { |
| 76 // Successfully parsed headers. | 81 // Successfully parsed headers. |
| 77 processing_headers_ = false; | 82 processing_headers_ = false; |
| 78 } else { | 83 } else { |
| 79 // Get more data before trying again. | 84 // Get more data before trying again. |
| 80 return; | 85 return; |
| 81 } | 86 } |
| 82 } | 87 } |
| 83 DCHECK(!processing_headers_); | 88 DCHECK(!processing_headers_); |
| 84 | 89 |
| (...skipping 135 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 220 if (boundary_pos >= 2) { | 225 if (boundary_pos >= 2) { |
| 221 if ('-' == data_[boundary_pos - 1] && '-' == data_[boundary_pos - 2]) { | 226 if ('-' == data_[boundary_pos - 1] && '-' == data_[boundary_pos - 2]) { |
| 222 boundary_pos -= 2; | 227 boundary_pos -= 2; |
| 223 boundary_ = "--" + boundary_; | 228 boundary_ = "--" + boundary_; |
| 224 } | 229 } |
| 225 } | 230 } |
| 226 } | 231 } |
| 227 return boundary_pos; | 232 return boundary_pos; |
| 228 } | 233 } |
| 229 | 234 |
| 235 bool MultipartResponseDelegate::ReadMultipartBoundary( |
| 236 const WebCore::ResourceResponse& response, |
| 237 std::string* multipart_boundary) { |
| 238 |
| 239 WebCore::String content_type = response.httpHeaderField("Content-Type"); |
| 240 std::string content_type_as_string = |
| 241 webkit_glue::StringToStdString(content_type); |
| 242 |
| 243 size_t boundary_start_offset = content_type_as_string.find("boundary="); |
| 244 if (boundary_start_offset == std::wstring::npos) { |
| 245 return false; |
| 246 } |
| 247 |
| 248 boundary_start_offset += strlen("boundary="); |
| 249 size_t boundary_end_offset = content_type.length(); |
| 250 |
| 251 size_t boundary_length = boundary_end_offset - boundary_start_offset; |
| 252 |
| 253 *multipart_boundary = |
| 254 content_type_as_string.substr(boundary_start_offset, boundary_length); |
| 255 return true; |
| 256 } |
| 257 |
| 258 bool MultipartResponseDelegate::ReadContentRanges( |
| 259 const WebCore::ResourceResponse& response, |
| 260 int* content_range_lower_bound, |
| 261 int* content_range_upper_bound) { |
| 262 |
| 263 std::string content_range = |
| 264 webkit_glue::StringToStdString( |
| 265 response.httpHeaderField("Content-Range")); |
| 266 |
| 267 size_t byte_range_lower_bound_start_offset = |
| 268 content_range.find(" "); |
| 269 if (byte_range_lower_bound_start_offset == std::string::npos) { |
| 270 return false; |
| 271 } |
| 272 |
| 273 // Skip over the initial space. |
| 274 byte_range_lower_bound_start_offset++; |
| 275 |
| 276 size_t byte_range_lower_bound_end_offset = |
| 277 content_range.find("-", byte_range_lower_bound_start_offset); |
| 278 if (byte_range_lower_bound_end_offset == std::string::npos) { |
| 279 return false; |
| 280 } |
| 281 |
| 282 size_t byte_range_lower_bound_characters = |
| 283 byte_range_lower_bound_end_offset - byte_range_lower_bound_start_offset; |
| 284 std::string byte_range_lower_bound = |
| 285 content_range.substr(byte_range_lower_bound_start_offset, |
| 286 byte_range_lower_bound_characters); |
| 287 |
| 288 size_t byte_range_upper_bound_start_offset = |
| 289 byte_range_lower_bound_end_offset + 1; |
| 290 |
| 291 size_t byte_range_upper_bound_end_offset = |
| 292 content_range.find("/", byte_range_upper_bound_start_offset); |
| 293 if (byte_range_upper_bound_end_offset == std::string::npos) { |
| 294 return false; |
| 295 } |
| 296 |
| 297 size_t byte_range_upper_bound_characters = |
| 298 byte_range_upper_bound_end_offset - byte_range_upper_bound_start_offset; |
| 299 |
| 300 std::string byte_range_upper_bound = |
| 301 content_range.substr(byte_range_upper_bound_start_offset, |
| 302 byte_range_upper_bound_characters); |
| 303 |
| 304 if (!StringToInt(byte_range_lower_bound, content_range_lower_bound)) |
| 305 return false; |
| 306 if (!StringToInt(byte_range_upper_bound, content_range_upper_bound)) |
| 307 return false; |
| 308 return true; |
| 309 } |
| OLD | NEW |