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 parsing content-types were borrowed from Firefox: | 5 // The rules for parsing content-types were borrowed from Firefox: |
6 // http://lxr.mozilla.org/mozilla/source/netwerk/base/src/nsURLHelper.cpp#834 | 6 // http://lxr.mozilla.org/mozilla/source/netwerk/base/src/nsURLHelper.cpp#834 |
7 | 7 |
8 #include "net/http/http_util.h" | 8 #include "net/http/http_util.h" |
9 | 9 |
10 #include <algorithm> | 10 #include <algorithm> |
(...skipping 524 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
535 if (buf_len >= http_len) { | 535 if (buf_len >= http_len) { |
536 int i_max = std::min(buf_len - http_len, slop); | 536 int i_max = std::min(buf_len - http_len, slop); |
537 for (int i = 0; i <= i_max; ++i) { | 537 for (int i = 0; i <= i_max; ++i) { |
538 if (LowerCaseEqualsASCII(buf + i, buf + i + http_len, "http")) | 538 if (LowerCaseEqualsASCII(buf + i, buf + i + http_len, "http")) |
539 return i; | 539 return i; |
540 } | 540 } |
541 } | 541 } |
542 return -1; // Not found | 542 return -1; // Not found |
543 } | 543 } |
544 | 544 |
545 int HttpUtil::LocateEndOfHeaders(const char* buf, int buf_len, int i) { | 545 static int LocateEndOfHeadersHelper(const char* buf, |
| 546 int buf_len, |
| 547 int i, |
| 548 bool accept_empty_header_list) { |
| 549 char last_c = '\0'; |
546 bool was_lf = false; | 550 bool was_lf = false; |
547 char last_c = '\0'; | 551 if (accept_empty_header_list) { |
| 552 // Normally two line breaks signal the end of a header list. An empty header |
| 553 // list ends with a single line break at the start of the buffer. |
| 554 last_c = '\n'; |
| 555 was_lf = true; |
| 556 } |
| 557 |
548 for (; i < buf_len; ++i) { | 558 for (; i < buf_len; ++i) { |
549 char c = buf[i]; | 559 char c = buf[i]; |
550 if (c == '\n') { | 560 if (c == '\n') { |
551 if (was_lf) | 561 if (was_lf) |
552 return i + 1; | 562 return i + 1; |
553 was_lf = true; | 563 was_lf = true; |
554 } else if (c != '\r' || last_c != '\n') { | 564 } else if (c != '\r' || last_c != '\n') { |
555 was_lf = false; | 565 was_lf = false; |
556 } | 566 } |
557 last_c = c; | 567 last_c = c; |
558 } | 568 } |
559 return -1; | 569 return -1; |
560 } | 570 } |
561 | 571 |
| 572 int HttpUtil::LocateEndOfAdditionalHeaders(const char* buf, |
| 573 int buf_len, |
| 574 int i) { |
| 575 return LocateEndOfHeadersHelper(buf, buf_len, i, true); |
| 576 } |
| 577 |
| 578 int HttpUtil::LocateEndOfHeaders(const char* buf, int buf_len, int i) { |
| 579 return LocateEndOfHeadersHelper(buf, buf_len, i, false); |
| 580 } |
| 581 |
562 // In order for a line to be continuable, it must specify a | 582 // In order for a line to be continuable, it must specify a |
563 // non-blank header-name. Line continuations are specifically for | 583 // non-blank header-name. Line continuations are specifically for |
564 // header values -- do not allow headers names to span lines. | 584 // header values -- do not allow headers names to span lines. |
565 static bool IsLineSegmentContinuable(const char* begin, const char* end) { | 585 static bool IsLineSegmentContinuable(const char* begin, const char* end) { |
566 if (begin == end) | 586 if (begin == end) |
567 return false; | 587 return false; |
568 | 588 |
569 const char* colon = std::find(begin, end, ':'); | 589 const char* colon = std::find(begin, end, ':'); |
570 if (colon == end) | 590 if (colon == end) |
571 return false; | 591 return false; |
(...skipping 362 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
934 value_is_quoted_ = true; | 954 value_is_quoted_ = true; |
935 // Do not store iterators into this. See declaration of unquoted_value_. | 955 // Do not store iterators into this. See declaration of unquoted_value_. |
936 unquoted_value_ = HttpUtil::Unquote(value_begin_, value_end_); | 956 unquoted_value_ = HttpUtil::Unquote(value_begin_, value_end_); |
937 } | 957 } |
938 } | 958 } |
939 | 959 |
940 return true; | 960 return true; |
941 } | 961 } |
942 | 962 |
943 } // namespace net | 963 } // namespace net |
OLD | NEW |