diff options
author | initial.commit <initial.commit@0039d316-1c4b-4281-b951-d872f2087c98> | 2008-07-26 22:42:52 +0000 |
---|---|---|
committer | initial.commit <initial.commit@0039d316-1c4b-4281-b951-d872f2087c98> | 2008-07-26 22:42:52 +0000 |
commit | 586acc5fe142f498261f52c66862fa417c3d52d2 (patch) | |
tree | c98b3417a883f2477029c8cd5888f4078681e24e /net/http/http_vary_data.h | |
parent | a814a8d55429605fe6d7045045cd25b6bf624580 (diff) | |
download | chromium_src-586acc5fe142f498261f52c66862fa417c3d52d2.zip chromium_src-586acc5fe142f498261f52c66862fa417c3d52d2.tar.gz chromium_src-586acc5fe142f498261f52c66862fa417c3d52d2.tar.bz2 |
Add net to the repository.
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@14 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'net/http/http_vary_data.h')
-rw-r--r-- | net/http/http_vary_data.h | 109 |
1 files changed, 109 insertions, 0 deletions
diff --git a/net/http/http_vary_data.h b/net/http/http_vary_data.h new file mode 100644 index 0000000..ff4f753 --- /dev/null +++ b/net/http/http_vary_data.h @@ -0,0 +1,109 @@ +// Copyright 2008, Google Inc. +// All rights reserved. +// +// Redistribution and use in source and binary forms, with or without +// modification, are permitted provided that the following conditions are +// met: +// +// * Redistributions of source code must retain the above copyright +// notice, this list of conditions and the following disclaimer. +// * Redistributions in binary form must reproduce the above +// copyright notice, this list of conditions and the following disclaimer +// in the documentation and/or other materials provided with the +// distribution. +// * Neither the name of Google Inc. nor the names of its +// contributors may be used to endorse or promote products derived from +// this software without specific prior written permission. +// +// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +#ifndef NET_HTTP_HTTP_VARY_DATA_H__ +#define NET_HTTP_HTTP_VARY_DATA_H__ + +#include "base/md5.h" +#include "base/ref_counted.h" + +class Pickle; + +namespace net { + +class HttpRequestInfo; +class HttpResponseHeaders; + +// Used to implement the HTTP/1.1 Vary header. This class contains a MD5 hash +// over the request headers indicated by a Vary header. +// +// While RFC 2616 requires strict request header comparisons, it is much +// cheaper to store a MD5 sum, which should be sufficient. Storing a hash also +// avoids messy privacy issues as some of the request headers could hold +// sensitive data (e.g., cookies). +// +// NOTE: This class does not hold onto the contents of the Vary header. +// Instead, it relies on the consumer to store that and to supply it again to +// the MatchesRequest function for comparing against future HTTP requests. +// +class HttpVaryData { + public: + HttpVaryData(); + + bool is_valid() const { return is_valid_; } + + // Initialize from a request and its corresponding response headers. + // + // Returns true if a Vary header was found in the response headers and that + // Vary header was not empty and did not contain the '*' value. Upon + // success, the object is also marked as valid such that is_valid() will + // return true. Otherwise, false is returned to indicate that this object + // was not modified. + // + bool Init(const HttpRequestInfo& request_info, + const HttpResponseHeaders& response_headers); + + // Initialize from a pickle that contains data generated by a call to the + // vary data's Persist method. + // + // Upon success, true is returned and the object is marked as valid such that + // is_valid() will return true. Otherwise, false is returned to indicate + // that this object was not modified. + // + bool InitFromPickle(const Pickle& pickle, void** pickle_iter); + + // Call this method to persist the vary data. + void Persist(Pickle* pickle) const; + + // Call this method to test if the given request matches the previous request + // with which this vary data corresponds. The |cached_response_headers| must + // be the same response headers used to generate this vary data. + bool MatchesRequest(const HttpRequestInfo& request_info, + const HttpResponseHeaders& cached_response_headers) const; + + private: + // Returns the corresponding request header value. + static std::string GetRequestValue(const HttpRequestInfo& request_info, + const std::string& request_header); + + // Append to the MD5 context for the given request header. + static void AddField(const HttpRequestInfo& request_info, + const std::string& request_header, + MD5Context* context); + + // A digested version of the request headers corresponding to the Vary header. + MD5Digest request_digest_; + + // True when request_digest_ contains meaningful data. + bool is_valid_; +}; + +} // namespace net + +#endif // NET_HTTP_HTTP_VARY_DATA_H__ |