OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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" |
11 | 11 |
12 #include <algorithm> | 12 #include <algorithm> |
13 | 13 |
| 14 #include "base/format_macros.h" |
14 #include "base/logging.h" | 15 #include "base/logging.h" |
15 #include "base/metrics/histogram.h" | 16 #include "base/metrics/histogram.h" |
16 #include "base/pickle.h" | 17 #include "base/pickle.h" |
17 #include "base/strings/string_number_conversions.h" | 18 #include "base/strings/string_number_conversions.h" |
18 #include "base/strings/string_piece.h" | 19 #include "base/strings/string_piece.h" |
19 #include "base/strings/string_util.h" | 20 #include "base/strings/string_util.h" |
20 #include "base/strings/stringprintf.h" | 21 #include "base/strings/stringprintf.h" |
21 #include "base/time/time.h" | 22 #include "base/time/time.h" |
22 #include "base/values.h" | 23 #include "base/values.h" |
23 #include "net/base/escape.h" | 24 #include "net/base/escape.h" |
| 25 #include "net/http/http_byte_range.h" |
24 #include "net/http/http_util.h" | 26 #include "net/http/http_util.h" |
25 | 27 |
26 using base::StringPiece; | 28 using base::StringPiece; |
27 using base::Time; | 29 using base::Time; |
28 using base::TimeDelta; | 30 using base::TimeDelta; |
29 | 31 |
30 namespace net { | 32 namespace net { |
31 | 33 |
32 //----------------------------------------------------------------------------- | 34 //----------------------------------------------------------------------------- |
33 | 35 |
(...skipping 333 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
367 void HttpResponseHeaders::ReplaceStatusLine(const std::string& new_status) { | 369 void HttpResponseHeaders::ReplaceStatusLine(const std::string& new_status) { |
368 CheckDoesNotHaveEmbededNulls(new_status); | 370 CheckDoesNotHaveEmbededNulls(new_status); |
369 // Copy up to the null byte. This just copies the status line. | 371 // Copy up to the null byte. This just copies the status line. |
370 std::string new_raw_headers(new_status); | 372 std::string new_raw_headers(new_status); |
371 new_raw_headers.push_back('\0'); | 373 new_raw_headers.push_back('\0'); |
372 | 374 |
373 HeaderSet empty_to_remove; | 375 HeaderSet empty_to_remove; |
374 MergeWithHeaders(new_raw_headers, empty_to_remove); | 376 MergeWithHeaders(new_raw_headers, empty_to_remove); |
375 } | 377 } |
376 | 378 |
| 379 void HttpResponseHeaders::UpdateWithNewRange( |
| 380 const HttpByteRange& byte_range, |
| 381 int64 resource_size, |
| 382 bool replace_status_line) { |
| 383 DCHECK(byte_range.IsValid()); |
| 384 DCHECK(byte_range.HasFirstBytePosition()); |
| 385 DCHECK(byte_range.HasLastBytePosition()); |
| 386 |
| 387 const char kLengthHeader[] = "Content-Length"; |
| 388 const char kRangeHeader[] = "Content-Range"; |
| 389 |
| 390 RemoveHeader(kLengthHeader); |
| 391 RemoveHeader(kRangeHeader); |
| 392 |
| 393 int64 start = byte_range.first_byte_position(); |
| 394 int64 end = byte_range.last_byte_position(); |
| 395 int64 range_len = end - start + 1; |
| 396 |
| 397 if (replace_status_line) |
| 398 ReplaceStatusLine("HTTP/1.1 206 Partial Content"); |
| 399 |
| 400 AddHeader(base::StringPrintf("%s: bytes %" PRId64 "-%" PRId64 "/%" PRId64, |
| 401 kRangeHeader, start, end, resource_size)); |
| 402 AddHeader(base::StringPrintf("%s: %" PRId64, kLengthHeader, range_len)); |
| 403 } |
| 404 |
377 void HttpResponseHeaders::Parse(const std::string& raw_input) { | 405 void HttpResponseHeaders::Parse(const std::string& raw_input) { |
378 raw_headers_.reserve(raw_input.size()); | 406 raw_headers_.reserve(raw_input.size()); |
379 | 407 |
380 // ParseStatusLine adds a normalized status line to raw_headers_ | 408 // ParseStatusLine adds a normalized status line to raw_headers_ |
381 std::string::const_iterator line_begin = raw_input.begin(); | 409 std::string::const_iterator line_begin = raw_input.begin(); |
382 std::string::const_iterator line_end = | 410 std::string::const_iterator line_end = |
383 std::find(line_begin, raw_input.end(), '\0'); | 411 std::find(line_begin, raw_input.end(), '\0'); |
384 // has_headers = true, if there is any data following the status line. | 412 // has_headers = true, if there is any data following the status line. |
385 // Used by ParseStatusLine() to decide if a HTTP/0.9 is really a HTTP/1.0. | 413 // Used by ParseStatusLine() to decide if a HTTP/0.9 is really a HTTP/1.0. |
386 bool has_headers = (line_end != raw_input.end() && | 414 bool has_headers = (line_end != raw_input.end() && |
(...skipping 1054 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1441 iter = NULL; | 1469 iter = NULL; |
1442 while (EnumerateHeader(&iter, "via", &value)) | 1470 while (EnumerateHeader(&iter, "via", &value)) |
1443 if (value == kDeprecatedChromeProxyViaValue) | 1471 if (value == kDeprecatedChromeProxyViaValue) |
1444 return true; | 1472 return true; |
1445 | 1473 |
1446 return false; | 1474 return false; |
1447 } | 1475 } |
1448 #endif // defined(SPDY_PROXY_AUTH_ORIGIN) | 1476 #endif // defined(SPDY_PROXY_AUTH_ORIGIN) |
1449 | 1477 |
1450 } // namespace net | 1478 } // namespace net |
OLD | NEW |