summaryrefslogtreecommitdiffstats
path: root/net/http/http_request_headers.h
diff options
context:
space:
mode:
authorwillchan@chromium.org <willchan@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-03-23 20:25:20 +0000
committerwillchan@chromium.org <willchan@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-03-23 20:25:20 +0000
commitaa98311d5083e2505e1e089bb21ed3735d4623f8 (patch)
tree6b771930d2f86a7c3d804b610004a6aab9f9bd5b /net/http/http_request_headers.h
parent6b889fb5d046cdecc27c2b2d56e2400dd7c10270 (diff)
downloadchromium_src-aa98311d5083e2505e1e089bb21ed3735d4623f8.zip
chromium_src-aa98311d5083e2505e1e089bb21ed3735d4623f8.tar.gz
chromium_src-aa98311d5083e2505e1e089bb21ed3735d4623f8.tar.bz2
Reland r42300: "HttpRequestHeaders refactor.""
This time, make sure HttpRequestHeaders::FindHeader() checks key lengths are equal. * Create HttpRequestHeaders. * Switch HttpNetworkTransaction to build request headers. TODO: Change extra_headers to use HttpRequestHeaders. BUG=22588 Review URL: http://codereview.chromium.org/1110014 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@42376 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'net/http/http_request_headers.h')
-rw-r--r--net/http/http_request_headers.h97
1 files changed, 97 insertions, 0 deletions
diff --git a/net/http/http_request_headers.h b/net/http/http_request_headers.h
new file mode 100644
index 0000000..79522aa
--- /dev/null
+++ b/net/http/http_request_headers.h
@@ -0,0 +1,97 @@
+// Copyright (c) 2010 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+//
+// HttpRequestHeaders manages the request headers (including the request line).
+// It maintains these in a vector of header key/value pairs, thereby maintaining
+// the order of the headers. This means that any lookups are linear time
+// operations.
+
+#ifndef NET_HTTP_HTTP_REQUEST_HEADERS_H_
+#define NET_HTTP_HTTP_REQUEST_HEADERS_H_
+
+#include <string>
+#include <vector>
+#include "base/basictypes.h"
+#include "base/string_piece.h"
+
+namespace net {
+
+class HttpRequestHeaders {
+ public:
+ static const char kGetMethod[];
+
+ static const char kCacheControl[];
+ static const char kConnection[];
+ static const char kContentLength[];
+ static const char kHost[];
+ static const char kPragma[];
+ static const char kProxyConnection[];
+ static const char kReferer[];
+ static const char kUserAgent[];
+
+ HttpRequestHeaders();
+ ~HttpRequestHeaders();
+
+ void SetRequestLine(const base::StringPiece& method,
+ const base::StringPiece& path,
+ const base::StringPiece& version);
+
+ // Sets the header value pair for |key| and |value|. If |key| already exists,
+ // then the header value is modified, but the key is untouched, and the order
+ // in the vector remains the same. When comparing |key|, case is ignored.
+ void SetHeader(const base::StringPiece& key, const base::StringPiece& value);
+
+ // Removes the first header that matches (case insensitive) |key|.
+ void RemoveHeader(const base::StringPiece& key);
+
+ // Parses the header from a string and calls SetHeader() with it. This string
+ // should not contain any CRLF. As per RFC2616, the format is:
+ //
+ // message-header = field-name ":" [ field-value ]
+ // field-name = token
+ // field-value = *( field-content | LWS )
+ // field-content = <the OCTETs making up the field-value
+ // and consisting of either *TEXT or combinations
+ // of token, separators, and quoted-string>
+ //
+ // AddHeaderFromString() will trim any LWS surrounding the
+ // field-content.
+ void AddHeaderFromString(const base::StringPiece& header_line);
+
+ // Calls SetHeader() on each header from |other|, maintaining order.
+ void MergeFrom(const HttpRequestHeaders& other);
+
+ // Serializes HttpRequestHeaders to a string representation. Joins all the
+ // header keys and values with ": ", and inserts "\r\n" between each header
+ // line, and adds the trailing "\r\n".
+ std::string ToString() const;
+
+ private:
+ struct HeaderKeyValuePair {
+ HeaderKeyValuePair() {}
+ HeaderKeyValuePair(const base::StringPiece& key,
+ const base::StringPiece& value)
+ : key(key.data(), key.size()), value(value.data(), value.size()) {}
+
+ std::string key;
+ std::string value;
+ };
+
+ typedef std::vector<HeaderKeyValuePair> HeaderVector;
+
+ HeaderVector::iterator FindHeader(const base::StringPiece& key);
+ HeaderVector::const_iterator FindHeader(const base::StringPiece& key) const;
+
+ std::string method_;
+ std::string path_;
+ std::string version_;
+
+ HeaderVector headers_;
+
+ DISALLOW_COPY_AND_ASSIGN(HttpRequestHeaders);
+};
+
+} // namespace net
+
+#endif // NET_HTTP_HTTP_REQUEST_HEADERS_H_