diff options
author | abarth@chromium.org <abarth@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-01-27 06:03:16 +0000 |
---|---|---|
committer | abarth@chromium.org <abarth@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-01-27 06:03:16 +0000 |
commit | 56eab2f216ce86217149753a407f981cb6d5de6c (patch) | |
tree | bf4b45a8fbb845b5ec177332df0ebafcfaedb98f /net/http/http_content_disposition.h | |
parent | 9b961c91eeb8ba43be7918563a07432cbcb1c4df (diff) | |
download | chromium_src-56eab2f216ce86217149753a407f981cb6d5de6c.zip chromium_src-56eab2f216ce86217149753a407f981cb6d5de6c.tar.gz chromium_src-56eab2f216ce86217149753a407f981cb6d5de6c.tar.bz2 |
Improve parsing of the Content-Disposition header
Previous, we were using GetHeaderParamValue to parse the Content-Disposition
header, which describes itself as a "quick and dirty implementation." After
this patch, we use more of our normal HTTP parsing machinery, making our
parsing much less quirky and better aligned with RFC 6266.
Some notes:
1) Many of the test cases for parsing the Content-Disposition header included
the string "Content-Disposition: " in the input. I've looked through all
of the callers of these functions, and that seems to be completely bogus.
The old parser wasn't careful enough to see that as a problem, but the new
one follows the spec more closely. I've updated the test cases to remove
this string.
2) After this patch, there's a bunch of code in net_util.cc that really should
be moved to http_content_disposition.cc. I didn't move that code in this
patch because I didn't want this path to be too large. I'll move it in a
future patch.
3) In a future patch, I'll audit the codebase for callers of
GetHeaderParamValue. With any luck, we'll be able to remove them all and
delete this less-than-amazing function.
BUG=65423
Review URL: http://codereview.chromium.org/9234055
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@119378 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'net/http/http_content_disposition.h')
-rw-r--r-- | net/http/http_content_disposition.h | 42 |
1 files changed, 42 insertions, 0 deletions
diff --git a/net/http/http_content_disposition.h b/net/http/http_content_disposition.h new file mode 100644 index 0000000..c75610a --- /dev/null +++ b/net/http/http_content_disposition.h @@ -0,0 +1,42 @@ +// Copyright (c) 2012 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. + +#ifndef NET_HTTP_HTTP_CONTENT_DISPOSITION_H_ +#define NET_HTTP_HTTP_CONTENT_DISPOSITION_H_ +#pragma once + +#include <string> + +#include "base/basictypes.h" +#include "net/base/net_export.h" + +namespace net { + +class NET_EXPORT_PRIVATE HttpContentDisposition { + public: + enum Type { + INLINE, + ATTACHMENT, + }; + + HttpContentDisposition(const std::string& header, + const std::string& referrer_charset); + ~HttpContentDisposition(); + + const std::string& filename() const { return filename_; } + + private: + void Parse(const std::string& header, const std::string& referrer_charset); + std::string::const_iterator ConsumeDispositionType( + std::string::const_iterator begin, std::string::const_iterator end); + + Type type_; // TODO(abarth): Add an accessor and tests. + std::string filename_; + + DISALLOW_COPY_AND_ASSIGN(HttpContentDisposition); +}; + +} // namespace net + +#endif // NET_HTTP_HTTP_CONTENT_DISPOSITION_H_ |