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 "webkit/glue/multipart_response_delegate.h" | 5 #include "webkit/glue/multipart_response_delegate.h" |
6 | 6 |
7 #include "base/logging.h" | 7 #include "base/logging.h" |
8 #include "base/string_util.h" | 8 #include "base/string_util.h" |
9 #include "net/base/net_util.h" | 9 #include "net/base/net_util.h" |
10 #include "net/http/http_util.h" | 10 #include "net/http/http_util.h" |
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
57 WebURLLoaderClient* client, | 57 WebURLLoaderClient* client, |
58 WebURLLoader* loader, | 58 WebURLLoader* loader, |
59 const WebURLResponse& response, | 59 const WebURLResponse& response, |
60 const std::string& boundary) | 60 const std::string& boundary) |
61 : client_(client), | 61 : client_(client), |
62 loader_(loader), | 62 loader_(loader), |
63 original_response_(response), | 63 original_response_(response), |
64 boundary_("--"), | 64 boundary_("--"), |
65 first_received_data_(true), | 65 first_received_data_(true), |
66 processing_headers_(false), | 66 processing_headers_(false), |
67 stop_sending_(false) { | 67 stop_sending_(false), |
| 68 has_sent_first_response_(false) { |
68 // Some servers report a boundary prefixed with "--". See bug 5786. | 69 // Some servers report a boundary prefixed with "--". See bug 5786. |
69 if (StartsWithASCII(boundary, "--", true)) { | 70 if (StartsWithASCII(boundary, "--", true)) { |
70 boundary_.assign(boundary); | 71 boundary_.assign(boundary); |
71 } else { | 72 } else { |
72 boundary_.append(boundary); | 73 boundary_.append(boundary); |
73 } | 74 } |
74 } | 75 } |
75 | 76 |
76 void MultipartResponseDelegate::OnReceivedData(const char* data, | 77 void MultipartResponseDelegate::OnReceivedData(const char* data, |
77 int data_len) { | 78 int data_len) { |
(...skipping 142 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
220 original_response_.visitHTTPHeaderFields(&copier); | 221 original_response_.visitHTTPHeaderFields(&copier); |
221 | 222 |
222 for (size_t i = 0; i < arraysize(kReplaceHeaders); ++i) { | 223 for (size_t i = 0; i < arraysize(kReplaceHeaders); ++i) { |
223 std::string name(kReplaceHeaders[i]); | 224 std::string name(kReplaceHeaders[i]); |
224 std::string value = net::GetSpecificHeader(headers, name); | 225 std::string value = net::GetSpecificHeader(headers, name); |
225 if (!value.empty()) { | 226 if (!value.empty()) { |
226 response.setHTTPHeaderField(WebString::fromUTF8(name), | 227 response.setHTTPHeaderField(WebString::fromUTF8(name), |
227 WebString::fromUTF8(value)); | 228 WebString::fromUTF8(value)); |
228 } | 229 } |
229 } | 230 } |
| 231 // To avoid recording every multipart load as a separate visit in |
| 232 // the history database, we want to keep track of whether the response |
| 233 // is part of a multipart payload. We do want to record the first visit, |
| 234 // so we only set isMultipartPayload to true after the first visit. |
| 235 response.setIsMultipartPayload(has_sent_first_response_); |
| 236 has_sent_first_response_ = true; |
230 // Send the response! | 237 // Send the response! |
231 client_->didReceiveResponse(loader_, response); | 238 client_->didReceiveResponse(loader_, response); |
232 | 239 |
233 return true; | 240 return true; |
234 } | 241 } |
235 | 242 |
236 // Boundaries are supposed to be preceeded with --, but it looks like gecko | 243 // Boundaries are supposed to be preceeded with --, but it looks like gecko |
237 // doesn't require the dashes to exist. See nsMultiMixedConv::FindToken. | 244 // doesn't require the dashes to exist. See nsMultiMixedConv::FindToken. |
238 size_t MultipartResponseDelegate::FindBoundary() { | 245 size_t MultipartResponseDelegate::FindBoundary() { |
239 size_t boundary_pos = data_.find(boundary_); | 246 size_t boundary_pos = data_.find(boundary_); |
(...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
332 byte_range_upper_bound_characters); | 339 byte_range_upper_bound_characters); |
333 | 340 |
334 if (!StringToInt(byte_range_lower_bound, content_range_lower_bound)) | 341 if (!StringToInt(byte_range_lower_bound, content_range_lower_bound)) |
335 return false; | 342 return false; |
336 if (!StringToInt(byte_range_upper_bound, content_range_upper_bound)) | 343 if (!StringToInt(byte_range_upper_bound, content_range_upper_bound)) |
337 return false; | 344 return false; |
338 return true; | 345 return true; |
339 } | 346 } |
340 | 347 |
341 } // namespace webkit_glue | 348 } // namespace webkit_glue |
OLD | NEW |