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.
5 #ifndef NET_HTTP_HTTP_CONTENT_DISPOSITION_H_
6 #define NET_HTTP_HTTP_CONTENT_DISPOSITION_H_
10 #include "base/basictypes.h"
11 #include "net/base/net_export.h"
15 class NET_EXPORT HttpContentDisposition
{
22 // Properties of the Content-Disposition header. These flags are used to
23 // report download metrics in UMA. This enum isn't directly used in UMA but
24 // mapped to another one for binary compatiblity; ie. changes are OK.
25 enum ParseResultFlags
{
28 // A valid disposition-type is present.
29 HAS_DISPOSITION_TYPE
= 1 << 0,
31 // The disposition-type is not 'inline' or 'attachment'.
32 HAS_UNKNOWN_DISPOSITION_TYPE
= 1 << 1,
34 // Has a valid non-empty 'filename' attribute.
35 HAS_FILENAME
= 1 << 2,
37 // Has a valid non-empty 'filename*' attribute.
38 HAS_EXT_FILENAME
= 1 << 3,
40 // The following fields are properties of the 'filename' attribute:
42 // Quoted-string contains non-ASCII characters.
43 HAS_NON_ASCII_STRINGS
= 1 << 4,
45 // Quoted-string contains percent-encoding.
46 HAS_PERCENT_ENCODED_STRINGS
= 1 << 5,
48 // Quoted-string contains RFC 2047 encoded words.
49 HAS_RFC2047_ENCODED_STRINGS
= 1 << 6
52 HttpContentDisposition(const std::string
& header
,
53 const std::string
& referrer_charset
);
54 ~HttpContentDisposition();
56 bool is_attachment() const { return type() == ATTACHMENT
; }
58 Type
type() const { return type_
; }
59 const std::string
& filename() const { return filename_
; }
61 // A combination of ParseResultFlags values.
62 int parse_result_flags() const { return parse_result_flags_
; }
65 void Parse(const std::string
& header
, const std::string
& referrer_charset
);
66 std::string::const_iterator
ConsumeDispositionType(
67 std::string::const_iterator begin
, std::string::const_iterator end
);
70 std::string filename_
;
71 int parse_result_flags_
;
73 DISALLOW_COPY_AND_ASSIGN(HttpContentDisposition
);
78 #endif // NET_HTTP_HTTP_CONTENT_DISPOSITION_H_