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

Side by Side 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, 10 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
(Empty)
1 // Copyright 2015 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.
4
5 #include "config.h"
6 #include "core/loader/LinkHeader.h"
7
8 #include "platform/ParsingUtilities.h"
9
10 namespace blink {
11
12 // LWSP definition in https://www.ietf.org/rfc/rfc0822.txt
13 template <typename CharType>
14 static bool isWhitespace(CharType chr)
15 {
16 return (chr == ' ') || (chr == '\t');
17 }
18
19 template < typename CharType>
Mike West 2015/01/30 13:55:13 Nit: No space after '<'.
20 bool LinkHeader::init(CharType* headerValue, unsigned len)
21 {
22 CharType* position = headerValue;
23 CharType* headerEnd = headerValue + len;
24
25 skipWhile<CharType, isWhitespace<CharType>>(position, headerEnd);
26
27 if (*position != '<')
28 return false;
29
30 skipWhile<CharType, isWhitespace<CharType>>(++position, headerEnd);
31
32 CharType* urlStart = position;
33 skipUntil<CharType, isWhitespace<CharType>>(position, headerEnd, '>');
34 CharType* urlEnd = position;
35 skipUntil<CharType>(position, headerEnd, '>');
36 ++position;
37 m_url = String(urlStart, urlEnd - urlStart);
38
39 while (position < headerEnd) {
40 skipWhile<CharType, isWhitespace<CharType>>(position, headerEnd);
41 if (*position != ';' && position != headerEnd)
42 return false;
43 skipWhile<CharType, isWhitespace<CharType>>(++position, headerEnd);
44 if (position == headerEnd)
45 return true;
46 CharType* paramStart = position;
47 skipUntil<CharType, isWhitespace<CharType>>(position, headerEnd, '=');
48 CharType* paramEnd = position;
49 skipWhile<CharType, isWhitespace<CharType>>(position, headerEnd);
50 if (*position != '=')
51 return false;
52 skipWhile<CharType, isWhitespace<CharType>>(++position, headerEnd);
53
54 CharType* valueStart = position;
55 skipUntil<CharType, isWhitespace<CharType>>(position, headerEnd, ';');
56 CharType* valueEnd = position;
57 skipWhile<CharType, isWhitespace<CharType>>(position, headerEnd);
58 if ((valueEnd == valueStart) || (*position != ';' && position != headerE nd))
59 return false;
60 if (String(paramStart, paramEnd - paramStart) == "rel")
61 m_rel = String(valueStart, valueEnd - valueStart);
Mike West 2015/01/30 13:55:13 Would you mind adding some comments in here regard
62 }
63
64 return true;
65 }
66
67 LinkHeader::LinkHeader(const String& header)
68 {
69 if (header.isNull()) {
70 m_isValid = false;
71 return;
72 }
73
74 if (header.is8Bit())
75 m_isValid = init(header.characters8(), header.length());
76 else
77 m_isValid = init(header.characters16(), header.length());
78 }
79
80 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698