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 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
70 // search_start now points to the first char after the end of the | 70 // search_start now points to the first char after the end of the |
71 // string, so just go back to the top of the loop and look for | 71 // string, so just go back to the top of the loop and look for |
72 // |delimiter| again. | 72 // |delimiter| again. |
73 } while (true); | 73 } while (true); |
74 | 74 |
75 NOTREACHED(); | 75 NOTREACHED(); |
76 return line.length(); | 76 return line.length(); |
77 } | 77 } |
78 | 78 |
79 // static | 79 // static |
80 bool HttpUtil::ParseVersion(const std::string& version_str, | |
81 HttpVersion* version) { | |
82 std::string::const_iterator p = version_str.begin(); | |
83 | |
84 // RFC2616 sec 3.1: HTTP-Version = "HTTP" "/" 1*DIGIT "." 1*DIGIT | |
85 // TODO: (1*DIGIT apparently means one or more digits, but we only handle 1). | |
86 // TODO: handle leading zeros, which is allowed by the rfc1616 sec 3.1. | |
87 | |
88 if (version_str.length() < 4 || !LowerCaseEqualsASCII(p, p + 4, "http")) { | |
89 DVLOG(1) << "missing status line"; | |
90 return false; | |
91 } | |
92 | |
93 p += 4; | |
94 | |
95 if (p >= version_str.end() || *p != '/') { | |
96 DVLOG(1) << "missing version"; | |
97 return false; | |
98 } | |
99 | |
100 std::string::const_iterator dot = std::find(p, version_str.end(), '.'); | |
101 if (dot == version_str.end()) { | |
102 DVLOG(1) << "malformed version"; | |
103 return false; | |
104 } | |
105 | |
106 ++p; // from / to first digit. | |
107 ++dot; // from . to second digit. | |
108 | |
109 if (!(*p >= '0' && *p <= '9' && *dot >= '0' && *dot <= '9')) { | |
110 DVLOG(1) << "malformed version number"; | |
111 return false; | |
112 } | |
113 | |
114 uint16 major = *p - '0'; | |
115 uint16 minor = *dot - '0'; | |
116 | |
117 *version = HttpVersion(major, minor); | |
118 return true; | |
119 } | |
120 | |
121 // static | |
122 void HttpUtil::ParseContentType(const std::string& content_type_str, | 80 void HttpUtil::ParseContentType(const std::string& content_type_str, |
123 std::string* mime_type, | 81 std::string* mime_type, |
124 std::string* charset, | 82 std::string* charset, |
125 bool* had_charset, | 83 bool* had_charset, |
126 std::string* boundary) { | 84 std::string* boundary) { |
127 const std::string::const_iterator begin = content_type_str.begin(); | 85 const std::string::const_iterator begin = content_type_str.begin(); |
128 | 86 |
129 // Trim leading and trailing whitespace from type. We include '(' in | 87 // Trim leading and trailing whitespace from type. We include '(' in |
130 // the trailing trim set to catch media-type comments, which are not at all | 88 // the trailing trim set to catch media-type comments, which are not at all |
131 // standard, but may occur in rare cases. | 89 // standard, but may occur in rare cases. |
(...skipping 808 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
940 value_is_quoted_ = true; | 898 value_is_quoted_ = true; |
941 // Do not store iterators into this. See declaration of unquoted_value_. | 899 // Do not store iterators into this. See declaration of unquoted_value_. |
942 unquoted_value_ = HttpUtil::Unquote(value_begin_, value_end_); | 900 unquoted_value_ = HttpUtil::Unquote(value_begin_, value_end_); |
943 } | 901 } |
944 } | 902 } |
945 | 903 |
946 return true; | 904 return true; |
947 } | 905 } |
948 | 906 |
949 } // namespace net | 907 } // namespace net |
OLD | NEW |