summaryrefslogtreecommitdiffstats
path: root/net/http/http_util.h
diff options
context:
space:
mode:
authorerikwright@chromium.org <erikwright@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-09-30 13:28:44 +0000
committererikwright@chromium.org <erikwright@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-09-30 13:28:44 +0000
commite3fe59bfb0912596e8975f9c50b01683c19ee5d9 (patch)
tree04b9c722b6f9db105acfc70bd286cb4f78c7d843 /net/http/http_util.h
parentd1cd0715ae8b15982b7ca46f4497eeddb4b73bca (diff)
downloadchromium_src-e3fe59bfb0912596e8975f9c50b01683c19ee5d9.zip
chromium_src-e3fe59bfb0912596e8975f9c50b01683c19ee5d9.tar.gz
chromium_src-e3fe59bfb0912596e8975f9c50b01683c19ee5d9.tar.bz2
Extract name-value pair parsing from http_auth.cc (ChallengeTokenizer) into http_util.cc (NameValuePairsIterator). In preparation for re-use of name-value pair parsing in ChromeFrame (for X-UA-Compatible header).
BUG=None TEST=net_unittests (HttpAuth* and HttpUtilTest.NameValuePairs*) Review URL: http://codereview.chromium.org/3525004 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@61061 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'net/http/http_util.h')
-rw-r--r--net/http/http_util.h55
1 files changed, 53 insertions, 2 deletions
diff --git a/net/http/http_util.h b/net/http/http_util.h
index 776b876..631790b 100644
--- a/net/http/http_util.h
+++ b/net/http/http_util.h
@@ -6,6 +6,7 @@
#define NET_HTTP_HTTP_UTIL_H_
#pragma once
+#include <string>
#include <vector>
#include "base/string_tokenizer.h"
@@ -214,10 +215,10 @@ class HttpUtil {
std::string::const_iterator values_end_;
};
- // Used to iterate over deliminated values in a HTTP header. HTTP LWS is
+ // Iterates over delimited values in an HTTP header. HTTP LWS is
// automatically trimmed from the resulting values.
//
- // When using this class to iterate over response header values, beware that
+ // When using this class to iterate over response header values, be aware that
// for some headers (e.g., Last-Modified), commas are not used as delimiters.
// This iterator should be avoided for headers like that which are considered
// non-coalescing (see IsNonCoalescingHeader).
@@ -251,6 +252,56 @@ class HttpUtil {
std::string::const_iterator value_begin_;
std::string::const_iterator value_end_;
};
+
+ // Iterates over a delimited sequence of name-value pairs in an HTTP header.
+ // Each pair consists of a token (the name), an equals sign, and either a
+ // token or quoted-string (the value). Arbitrary HTTP LWS is permitted outside
+ // of and between names, values, and delimiters.
+ class NameValuePairsIterator {
+ public:
+ NameValuePairsIterator(std::string::const_iterator begin,
+ std::string::const_iterator end,
+ char delimiter);
+
+ // Advances the iterator to the next pair, if any. Returns true if there
+ // is a next pair. Use name* and value* methods to access the resultant
+ // value.
+ bool GetNext();
+
+ // Returns false if there was a parse error.
+ bool valid() const { return valid_; }
+
+ // The name of the current name-value pair.
+ std::string::const_iterator name_begin() const { return name_begin_; }
+ std::string::const_iterator name_end() const { return name_end_; }
+ std::string name() const { return std::string(name_begin_, name_end_); }
+
+ // The value of the current name-value pair.
+ std::string::const_iterator value_begin() const { return value_begin_; }
+ std::string::const_iterator value_end() const { return value_end_; }
+ std::string value() const { return std::string(value_begin_, value_end_); }
+
+ // If value() has quotemarks, unquote it.
+ std::string unquoted_value() const;
+
+ // True if the name-value pair's value has quote marks.
+ bool value_is_quoted() const { return value_is_quoted_; }
+
+ private:
+ HttpUtil::ValuesIterator props_;
+ bool valid_;
+
+ std::string::const_iterator begin_;
+ std::string::const_iterator end_;
+
+ std::string::const_iterator name_begin_;
+ std::string::const_iterator name_end_;
+
+ std::string::const_iterator value_begin_;
+ std::string::const_iterator value_end_;
+
+ bool value_is_quoted_;
+ };
};
} // namespace net