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

Side by Side Diff: third_party/WebKit/Source/platform/network/ContentHeaderFieldInput.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 ContentHeaderFieldInput_h
33 #define ParsedContentType_h 33 #define ContentHeaderFieldInput_h
34 34
35 #include "platform/PlatformExport.h" 35 #include "platform/network/ParsedContentHeaderFieldParameters.h"
36 #include "platform/wtf/Allocator.h" 36 #include "platform/wtf/text/WTFString.h"
37 #include "platform/wtf/HashMap.h"
38 #include "platform/wtf/text/StringHash.h"
39 37
40 namespace blink { 38 namespace blink {
41 39
42 // ParsedContentType parses the constructor argument as specified in RFC2045 40 class ContentHeaderFieldInput final {
43 // and stores the result.
44 // FIXME: add support for comments.
45 class PLATFORM_EXPORT ParsedContentType final {
46 STACK_ALLOCATED(); 41 STACK_ALLOCATED();
47 42
48 public: 43 public:
49 // When |Relaxed| is specified, the parser parses parameter values in a sloppy 44 using Mode = ParsedContentHeaderFieldParameters::Mode;
50 // manner, i.e., only ';' and '"' are treated as special characters.
51 // See https://chromiumcodereview.appspot.com/23043002.
52 // 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
54 // "It is an error for a specific parameter to be specified more than once."
55 enum class Mode {
56 kNormal,
57 kRelaxed,
58 kStrict,
59 };
60 explicit ParsedContentType(const String&, Mode = Mode::kNormal);
61 45
62 String MimeType() const { return mime_type_; } 46 explicit ContentHeaderFieldInput(const String& header_field);
63 String Charset() const; 47 ContentHeaderFieldInput(ContentHeaderFieldInput&&);
64 48
65 // Note that in the case of multiple values for the same name, the last value 49 bool Consume(char);
66 // is returned. 50 bool ConsumeToken(Mode, StringView& output);
67 String ParameterValueForName(const String&) const; 51 bool ConsumeTokenOrQuotedString(Mode, String& output);
68 size_t ParameterCount() const; 52 unsigned Index() const { return index_; }
69 53 bool IsConsumed() const { return index_ >= input_.length(); }
70 bool IsValid() const { return is_valid_; } 54 void SkipSpaces();
71 55
72 private: 56 private:
73 bool Parse(const String&); 57 bool ConsumeQuotedString(String& output);
74 58
75 const Mode mode_; 59 unsigned index_;
76 bool is_valid_; 60 const String input_;
77
78 typedef HashMap<String, String> KeyValuePairs;
79 KeyValuePairs parameters_;
80 String mime_type_;
81 }; 61 };
82 62
83 } // namespace blink 63 } // namespace blink
84 64
85 #endif 65 #endif
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698