Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(45)

Side by Side Diff: third_party/WebKit/Source/platform/network/ParsedContentHeaderFieldParameters.h

Issue 2880543003: Implement a parser for Content-Disposition header fields (Closed)
Patch Set: Inheritance to delegation, tests Created 3 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 /* 1 /*
2 * Copyright (C) 2011 Google Inc. All rights reserved. 2 * Copyright (C) 2011 Google Inc. All rights reserved.
3 * Copyright (C) 2012 Intel Corporation. All rights reserved. 3 * Copyright (C) 2012 Intel Corporation. All rights reserved.
4 * 4 *
5 * Redistribution and use in source and binary forms, with or without 5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions are 6 * modification, are permitted provided that the following conditions are
7 * met: 7 * met:
8 * 8 *
9 * * Redistributions of source code must retain the above copyright 9 * * Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer. 10 * notice, this list of conditions and the following disclaimer.
(...skipping 11 matching lines...) Expand all
22 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 22 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
23 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 23 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
24 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 24 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
25 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 25 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
26 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 26 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
27 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 27 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
28 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 28 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
29 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 29 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
30 */ 30 */
31 31
32 #ifndef ParsedContentType_h 32 #ifndef ParsedParameterizedContentHeaderField_h
33 #define ParsedContentType_h 33 #define ParsedParameterizedContentHeaderField_h
34 34
35 #include "platform/PlatformExport.h" 35 #include "platform/PlatformExport.h"
36 #include "platform/wtf/Allocator.h" 36 #include "platform/wtf/Allocator.h"
37 #include "platform/wtf/HashMap.h" 37 #include "platform/wtf/HashMap.h"
38 #include "platform/wtf/text/StringHash.h" 38 #include "platform/wtf/text/StringHash.h"
39 39
40 namespace blink { 40 namespace blink {
41 41
42 // ParsedContentType parses the constructor argument as specified in RFC2045 42 class ContentHeaderFieldInput;
43 // and stores the result. 43
44 // ParsedParameterizedContentHeaderField parses the constructor argument as
45 // specified in RFC2045 and stores the result.
44 // FIXME: add support for comments. 46 // FIXME: add support for comments.
45 class PLATFORM_EXPORT ParsedContentType final { 47 class PLATFORM_EXPORT ParsedContentHeaderFieldParameters final {
46 STACK_ALLOCATED(); 48 STACK_ALLOCATED();
47 49
48 public: 50 public:
49 // When |Relaxed| is specified, the parser parses parameter values in a sloppy 51 // When |Relaxed| is specified, the parser parses parameter values in a sloppy
50 // manner, i.e., only ';' and '"' are treated as special characters. 52 // manner, i.e., only ';' and '"' are treated as special characters.
51 // See https://chromiumcodereview.appspot.com/23043002. 53 // See https://chromiumcodereview.appspot.com/23043002.
52 // When |Strict| is specified, the parser does not allow multiple values 54 // When |Strict| is specified, the parser does not allow multiple values
53 // for the same parameter. Some RFCs based on RFC2045 (e.g. RFC6838) note that 55 // for the same parameter. Some RFCs based on RFC2045 (e.g. RFC6838) note that
54 // "It is an error for a specific parameter to be specified more than once." 56 // "It is an error for a specific parameter to be specified more than once."
55 enum class Mode { 57 enum class Mode {
56 kNormal, 58 kNormal,
57 kRelaxed, 59 kRelaxed,
58 kStrict, 60 kStrict,
59 }; 61 };
60 explicit ParsedContentType(const String&, Mode = Mode::kNormal);
61 62
62 String MimeType() const { return mime_type_; } 63 ParsedContentHeaderFieldParameters();
63 String Charset() const;
64 64
65 // Note that in the case of multiple values for the same name, the last value 65 // Note that in the case of multiple values for the same name, the last value
66 // is returned. 66 // is returned.
67 String ParameterValueForName(const String&) const; 67 String ParameterValueForName(const String&) const;
68 size_t ParameterCount() const; 68 size_t ParameterCount() const;
69 69
70 bool IsValid() const { return is_valid_; } 70 bool IsValid() const { return is_valid_; }
71 71
72 void ParseParameters(ContentHeaderFieldInput, Mode);
73
74 static ParsedContentHeaderFieldParameters CreateForTesting(
75 const String&,
76 Mode = Mode::kNormal);
77
72 private: 78 private:
73 bool Parse(const String&); 79 typedef HashMap<String, String> KeyValuePairs;
74
75 const Mode mode_;
76 bool is_valid_; 80 bool is_valid_;
77
78 typedef HashMap<String, String> KeyValuePairs;
79 KeyValuePairs parameters_; 81 KeyValuePairs parameters_;
80 String mime_type_;
81 }; 82 };
82 83
83 } // namespace blink 84 } // namespace blink
84 85
85 #endif 86 #endif
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698