http_content_disposition.h 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  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
  3. // found in the LICENSE file.
  4. #ifndef NET_HTTP_HTTP_CONTENT_DISPOSITION_H_
  5. #define NET_HTTP_HTTP_CONTENT_DISPOSITION_H_
  6. #include <string>
  7. #include "net/base/net_export.h"
  8. namespace net {
  9. class NET_EXPORT HttpContentDisposition {
  10. public:
  11. enum Type {
  12. INLINE,
  13. ATTACHMENT,
  14. };
  15. // Properties of the Content-Disposition header. These flags are used to
  16. // report download metrics in UMA. This enum isn't directly used in UMA but
  17. // mapped to another one for binary compatiblity; ie. changes are OK.
  18. enum ParseResultFlags {
  19. INVALID = 0,
  20. // A valid disposition-type is present.
  21. HAS_DISPOSITION_TYPE = 1 << 0,
  22. // The disposition-type is not 'inline' or 'attachment'.
  23. HAS_UNKNOWN_DISPOSITION_TYPE = 1 << 1,
  24. // Has a valid non-empty 'filename' attribute.
  25. HAS_FILENAME = 1 << 2,
  26. // Has a valid non-empty 'filename*' attribute.
  27. HAS_EXT_FILENAME = 1 << 3,
  28. // The following fields are properties of the 'filename' attribute:
  29. // Quoted-string contains non-ASCII characters.
  30. HAS_NON_ASCII_STRINGS = 1 << 4,
  31. // Quoted-string contains percent-encoding.
  32. HAS_PERCENT_ENCODED_STRINGS = 1 << 5,
  33. // Quoted-string contains RFC 2047 encoded words.
  34. HAS_RFC2047_ENCODED_STRINGS = 1 << 6,
  35. // Has a filename that starts with a single quote.
  36. HAS_SINGLE_QUOTED_FILENAME = 1 << 7,
  37. };
  38. HttpContentDisposition(const std::string& header,
  39. const std::string& referrer_charset);
  40. HttpContentDisposition(const HttpContentDisposition&) = delete;
  41. HttpContentDisposition& operator=(const HttpContentDisposition&) = delete;
  42. ~HttpContentDisposition();
  43. bool is_attachment() const { return type() == ATTACHMENT; }
  44. Type type() const { return type_; }
  45. const std::string& filename() const { return filename_; }
  46. // A combination of ParseResultFlags values.
  47. int parse_result_flags() const { return parse_result_flags_; }
  48. private:
  49. void Parse(const std::string& header, const std::string& referrer_charset);
  50. std::string::const_iterator ConsumeDispositionType(
  51. std::string::const_iterator begin, std::string::const_iterator end);
  52. Type type_ = INLINE;
  53. std::string filename_;
  54. int parse_result_flags_ = INVALID;
  55. };
  56. } // namespace net
  57. #endif // NET_HTTP_HTTP_CONTENT_DISPOSITION_H_