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()); | |
mmenke
2014/03/06 18:18:48
Maybe add:
DCHECK(!byte_range.suffix_length());
D
rvargas (doing something else)
2014/03/06 19:24:00
Excellent point. Now that this lives here we canno
kinuko
2014/03/07 05:05:14
Added DCHECKs for HasFirstBytePosition/HasLastByte
| |
384 | |
385 const char kLengthHeader[] = "Content-Length"; | |
386 const char kRangeHeader[] = "Content-Range"; | |
387 | |
388 RemoveHeader(kLengthHeader); | |
389 RemoveHeader(kRangeHeader); | |
390 | |
391 int64 start = byte_range.first_byte_position(); | |
392 int64 end = byte_range.last_byte_position(); | |
393 int64 range_len = end - start + 1; | |
394 | |
395 if (replace_status_line) | |
396 ReplaceStatusLine("HTTP/1.1 206 Partial Content"); | |
397 | |
398 AddHeader(base::StringPrintf("%s: bytes %" PRId64 "-%" PRId64 "/%" PRId64, | |
399 kRangeHeader, start, end, resource_size)); | |
400 AddHeader(base::StringPrintf("%s: %" PRId64, kLengthHeader, range_len)); | |
401 } | |
402 | |
377 void HttpResponseHeaders::Parse(const std::string& raw_input) { | 403 void HttpResponseHeaders::Parse(const std::string& raw_input) { |
378 raw_headers_.reserve(raw_input.size()); | 404 raw_headers_.reserve(raw_input.size()); |
379 | 405 |
380 // ParseStatusLine adds a normalized status line to raw_headers_ | 406 // ParseStatusLine adds a normalized status line to raw_headers_ |
381 std::string::const_iterator line_begin = raw_input.begin(); | 407 std::string::const_iterator line_begin = raw_input.begin(); |
382 std::string::const_iterator line_end = | 408 std::string::const_iterator line_end = |
383 std::find(line_begin, raw_input.end(), '\0'); | 409 std::find(line_begin, raw_input.end(), '\0'); |
384 // has_headers = true, if there is any data following the status line. | 410 // 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. | 411 // 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() && | 412 bool has_headers = (line_end != raw_input.end() && |
(...skipping 1053 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1440 iter = NULL; | 1466 iter = NULL; |
1441 while (EnumerateHeader(&iter, "via", &value)) | 1467 while (EnumerateHeader(&iter, "via", &value)) |
1442 if (value == kDeprecatedChromeProxyViaValue) | 1468 if (value == kDeprecatedChromeProxyViaValue) |
1443 return true; | 1469 return true; |
1444 | 1470 |
1445 return false; | 1471 return false; |
1446 } | 1472 } |
1447 #endif // defined(SPDY_PROXY_AUTH_ORIGIN) | 1473 #endif // defined(SPDY_PROXY_AUTH_ORIGIN) |
1448 | 1474 |
1449 } // namespace net | 1475 } // namespace net |
OLD | NEW |