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

Unified Diff: third_party/WebKit/Source/platform/network/ParsedContentHeaderFieldParameters.h

Issue 2880543003: Implement a parser for Content-Disposition header fields (Closed)
Patch Set: Rebase 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 side-by-side diff with in-line comments
Download patch
Index: third_party/WebKit/Source/platform/network/ParsedContentHeaderFieldParameters.h
diff --git a/third_party/WebKit/Source/platform/network/ParsedContentHeaderFieldParameters.h b/third_party/WebKit/Source/platform/network/ParsedContentHeaderFieldParameters.h
new file mode 100644
index 0000000000000000000000000000000000000000..7158ebc124afbaa30057418646837a1a9b79081b
--- /dev/null
+++ b/third_party/WebKit/Source/platform/network/ParsedContentHeaderFieldParameters.h
@@ -0,0 +1,59 @@
+// Copyright 2017 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#ifndef ParsedContentHeaderFieldParameters_h
+#define ParsedContentHeaderFieldParameters_h
+
+#include "platform/PlatformExport.h"
+#include "platform/wtf/Allocator.h"
+#include "platform/wtf/HashMap.h"
+#include "platform/wtf/text/StringHash.h"
+
+namespace blink {
+
+class HeaderFieldTokenizer;
+
+// Parses content header field parameters as specified in RFC2045 and stores
+// them. It is used internally by ParsedContent* classes.
+// FIXME: add support for comments.
+class PLATFORM_EXPORT ParsedContentHeaderFieldParameters final {
+ STACK_ALLOCATED();
+
+ public:
+ // When |Relaxed| is specified, the parser parses parameter values in a sloppy
+ // manner, i.e., only ';' and '"' are treated as special characters.
+ // See https://chromiumcodereview.appspot.com/23043002.
+ // When |Strict| is specified, the parser does not allow multiple values
+ // for the same parameter. Some RFCs based on RFC2045 (e.g. RFC6838) note that
+ // "It is an error for a specific parameter to be specified more than once."
+ enum class Mode {
+ kNormal,
+ kRelaxed,
+ kStrict,
+ };
+
+ ParsedContentHeaderFieldParameters();
+
+ // Note that in the case of multiple values for the same name, the last value
+ // is returned.
+ String ParameterValueForName(const String&) const;
+ size_t ParameterCount() const;
+
+ bool IsValid() const { return is_valid_; }
+
+ void ParseParameters(HeaderFieldTokenizer, Mode);
+
+ static ParsedContentHeaderFieldParameters CreateForTesting(
+ const String&,
+ Mode = Mode::kNormal);
+
+ private:
+ typedef HashMap<String, String> KeyValuePairs;
+ bool is_valid_;
+ KeyValuePairs parameters_;
+};
+
+} // namespace blink
+
+#endif

Powered by Google App Engine
This is Rietveld 408576698