• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // Copyright 2012 The Chromium Authors
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4 
5 #ifndef NET_HTTP_HTTP_CONTENT_DISPOSITION_H_
6 #define NET_HTTP_HTTP_CONTENT_DISPOSITION_H_
7 
8 #include <string>
9 
10 #include "net/base/net_export.h"
11 
12 namespace net {
13 
14 class NET_EXPORT HttpContentDisposition {
15  public:
16   enum Type {
17     INLINE,
18     ATTACHMENT,
19   };
20 
21   // Properties of the Content-Disposition header. These flags are used to
22   // report download metrics in UMA. This enum isn't directly used in UMA but
23   // mapped to another one for binary compatiblity; ie. changes are OK.
24   enum ParseResultFlags {
25     INVALID = 0,
26 
27     // A valid disposition-type is present.
28     HAS_DISPOSITION_TYPE = 1 << 0,
29 
30     // The disposition-type is not 'inline' or 'attachment'.
31     HAS_UNKNOWN_DISPOSITION_TYPE = 1 << 1,
32 
33     // Has a valid non-empty 'filename' attribute.
34     HAS_FILENAME = 1 << 2,
35 
36     // Has a valid non-empty 'filename*' attribute.
37     HAS_EXT_FILENAME = 1 << 3,
38 
39     // The following fields are properties of the 'filename' attribute:
40 
41     // Quoted-string contains non-ASCII characters.
42     HAS_NON_ASCII_STRINGS = 1 << 4,
43 
44     // Quoted-string contains percent-encoding.
45     HAS_PERCENT_ENCODED_STRINGS = 1 << 5,
46 
47     // Quoted-string contains RFC 2047 encoded words.
48     HAS_RFC2047_ENCODED_STRINGS = 1 << 6,
49 
50     // Has a filename that starts with a single quote.
51     HAS_SINGLE_QUOTED_FILENAME = 1 << 7,
52   };
53 
54   HttpContentDisposition(const std::string& header,
55                          const std::string& referrer_charset);
56 
57   HttpContentDisposition(const HttpContentDisposition&) = delete;
58   HttpContentDisposition& operator=(const HttpContentDisposition&) = delete;
59 
60   ~HttpContentDisposition();
61 
is_attachment()62   bool is_attachment() const { return type() == ATTACHMENT; }
63 
type()64   Type type() const { return type_; }
filename()65   const std::string& filename() const { return filename_; }
66 
67   // A combination of ParseResultFlags values.
parse_result_flags()68   int parse_result_flags() const { return parse_result_flags_; }
69 
70  private:
71   void Parse(const std::string& header, const std::string& referrer_charset);
72   std::string::const_iterator ConsumeDispositionType(
73       std::string::const_iterator begin, std::string::const_iterator end);
74 
75   Type type_ = INLINE;
76   std::string filename_;
77   int parse_result_flags_ = INVALID;
78 };
79 
80 }  // namespace net
81 
82 #endif  // NET_HTTP_HTTP_CONTENT_DISPOSITION_H_
83