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

Unified Diff: Source/core/loader/LinkHeader.cpp

Issue 889883002: Add a parser for Link headers (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: Handle null headers Created 5 years, 11 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: Source/core/loader/LinkHeader.cpp
diff --git a/Source/core/loader/LinkHeader.cpp b/Source/core/loader/LinkHeader.cpp
new file mode 100644
index 0000000000000000000000000000000000000000..c0a652f75f30c6269258f7e3adf4060cb615c20e
--- /dev/null
+++ b/Source/core/loader/LinkHeader.cpp
@@ -0,0 +1,80 @@
+// Copyright 2015 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.
+
+#include "config.h"
+#include "core/loader/LinkHeader.h"
+
+#include "platform/ParsingUtilities.h"
+
+namespace blink {
+
+// LWSP definition in https://www.ietf.org/rfc/rfc0822.txt
+template <typename CharType>
+static bool isWhitespace(CharType chr)
+{
+ return (chr == ' ') || (chr == '\t');
+}
+
+template < typename CharType>
Mike West 2015/01/30 13:55:13 Nit: No space after '<'.
+bool LinkHeader::init(CharType* headerValue, unsigned len)
+{
+ CharType* position = headerValue;
+ CharType* headerEnd = headerValue + len;
+
+ skipWhile<CharType, isWhitespace<CharType>>(position, headerEnd);
+
+ if (*position != '<')
+ return false;
+
+ skipWhile<CharType, isWhitespace<CharType>>(++position, headerEnd);
+
+ CharType* urlStart = position;
+ skipUntil<CharType, isWhitespace<CharType>>(position, headerEnd, '>');
+ CharType* urlEnd = position;
+ skipUntil<CharType>(position, headerEnd, '>');
+ ++position;
+ m_url = String(urlStart, urlEnd - urlStart);
+
+ while (position < headerEnd) {
+ skipWhile<CharType, isWhitespace<CharType>>(position, headerEnd);
+ if (*position != ';' && position != headerEnd)
+ return false;
+ skipWhile<CharType, isWhitespace<CharType>>(++position, headerEnd);
+ if (position == headerEnd)
+ return true;
+ CharType* paramStart = position;
+ skipUntil<CharType, isWhitespace<CharType>>(position, headerEnd, '=');
+ CharType* paramEnd = position;
+ skipWhile<CharType, isWhitespace<CharType>>(position, headerEnd);
+ if (*position != '=')
+ return false;
+ skipWhile<CharType, isWhitespace<CharType>>(++position, headerEnd);
+
+ CharType* valueStart = position;
+ skipUntil<CharType, isWhitespace<CharType>>(position, headerEnd, ';');
+ CharType* valueEnd = position;
+ skipWhile<CharType, isWhitespace<CharType>>(position, headerEnd);
+ if ((valueEnd == valueStart) || (*position != ';' && position != headerEnd))
+ return false;
+ if (String(paramStart, paramEnd - paramStart) == "rel")
+ m_rel = String(valueStart, valueEnd - valueStart);
Mike West 2015/01/30 13:55:13 Would you mind adding some comments in here regard
+ }
+
+ return true;
+}
+
+LinkHeader::LinkHeader(const String& header)
+{
+ if (header.isNull()) {
+ m_isValid = false;
+ return;
+ }
+
+ if (header.is8Bit())
+ m_isValid = init(header.characters8(), header.length());
+ else
+ m_isValid = init(header.characters16(), header.length());
+}
+
+}

Powered by Google App Engine
This is Rietveld 408576698