OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 "content/child/multipart_response_delegate.h" | 5 #include "content/child/multipart_response_delegate.h" |
6 | 6 |
7 #include "base/logging.h" | 7 #include "base/logging.h" |
8 #include "base/macros.h" | 8 #include "base/macros.h" |
9 #include "base/memory/ref_counted.h" | 9 #include "base/memory/ref_counted.h" |
10 #include "base/strings/string_number_conversions.h" | 10 #include "base/strings/string_number_conversions.h" |
(...skipping 268 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
279 if (boundary_pos >= 2) { | 279 if (boundary_pos >= 2) { |
280 if ('-' == data_[boundary_pos - 1] && '-' == data_[boundary_pos - 2]) { | 280 if ('-' == data_[boundary_pos - 1] && '-' == data_[boundary_pos - 2]) { |
281 boundary_pos -= 2; | 281 boundary_pos -= 2; |
282 boundary_ = "--" + boundary_; | 282 boundary_ = "--" + boundary_; |
283 } | 283 } |
284 } | 284 } |
285 } | 285 } |
286 return boundary_pos; | 286 return boundary_pos; |
287 } | 287 } |
288 | 288 |
289 bool MultipartResponseDelegate::ReadMultipartBoundary( | |
290 const WebURLResponse& response, | |
291 std::string* multipart_boundary) { | |
292 std::string content_type = | |
293 response.httpHeaderField(WebString::fromUTF8("Content-Type")).utf8(); | |
294 | |
295 size_t boundary_start_offset = content_type.find("boundary="); | |
296 if (boundary_start_offset == std::string::npos) | |
297 return false; | |
298 | |
299 boundary_start_offset += strlen("boundary="); | |
300 | |
301 size_t boundary_end_offset = content_type.find(';', boundary_start_offset); | |
302 | |
303 if (boundary_end_offset == std::string::npos) | |
304 boundary_end_offset = content_type.length(); | |
305 | |
306 size_t boundary_length = boundary_end_offset - boundary_start_offset; | |
307 | |
308 *multipart_boundary = | |
309 content_type.substr(boundary_start_offset, boundary_length); | |
310 // The byte range response can have quoted boundary strings. This is legal | |
311 // as per MIME specifications. Individual data fragements however don't | |
312 // contain quoted boundary strings. | |
313 base::TrimString(*multipart_boundary, "\"", multipart_boundary); | |
314 return true; | |
315 } | |
316 | |
317 bool MultipartResponseDelegate::ReadContentRanges( | 289 bool MultipartResponseDelegate::ReadContentRanges( |
318 const WebURLResponse& response, | 290 const WebURLResponse& response, |
319 int64_t* content_range_lower_bound, | 291 int64_t* content_range_lower_bound, |
320 int64_t* content_range_upper_bound, | 292 int64_t* content_range_upper_bound, |
321 int64_t* content_range_instance_size) { | 293 int64_t* content_range_instance_size) { |
322 std::string content_range = response.httpHeaderField("Content-Range").utf8(); | 294 std::string content_range = response.httpHeaderField("Content-Range").utf8(); |
323 if (content_range.empty()) { | 295 if (content_range.empty()) { |
324 content_range = response.httpHeaderField("Range").utf8(); | 296 content_range = response.httpHeaderField("Range").utf8(); |
325 } | 297 } |
326 | 298 |
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
385 if (!base::StringToInt64(byte_range_upper_bound, content_range_upper_bound)) | 357 if (!base::StringToInt64(byte_range_upper_bound, content_range_upper_bound)) |
386 return false; | 358 return false; |
387 if (!base::StringToInt64(byte_range_instance_size, | 359 if (!base::StringToInt64(byte_range_instance_size, |
388 content_range_instance_size)) { | 360 content_range_instance_size)) { |
389 return false; | 361 return false; |
390 } | 362 } |
391 return true; | 363 return true; |
392 } | 364 } |
393 | 365 |
394 } // namespace content | 366 } // namespace content |
OLD | NEW |