MCPcopy Create free account
hub / github.com/apache/tomcat / parseCookie

Method parseCookie

java/org/apache/tomcat/util/http/parser/Cookie.java:94–159  ·  view source on GitHub ↗

Parse byte array as cookie header. @param bytes Source @param offset Start point in array @param len Number of bytes to read @param serverCookies Structure to store results @param cookiesWithoutEquals How to handle a cookie name-value-pair that d

(byte[] bytes, int offset, int len, ServerCookies serverCookies,
            CookiesWithoutEquals cookiesWithoutEquals)

Source from the content-addressed store, hash-verified

92 * @param cookiesWithoutEquals How to handle a cookie name-value-pair that does not contain an equals character
93 */
94 public static void parseCookie(byte[] bytes, int offset, int len, ServerCookies serverCookies,
95 CookiesWithoutEquals cookiesWithoutEquals) {
96
97 // ByteBuffer is used throughout this parser as it allows the byte[]
98 // and position information to be easily passed between parsing methods
99 ByteBuffer bb = new ByteBuffer(bytes, offset, len);
100
101 boolean moreToProcess = true;
102
103 while (moreToProcess) {
104 skipLWS(bb);
105
106 int start = bb.position();
107 ByteBuffer name = readToken(bb);
108 ByteBuffer value = null;
109
110 skipLWS(bb);
111
112 SkipResult skipResult = skipByte(bb, EQUALS_BYTE);
113 if (skipResult == SkipResult.FOUND) {
114 skipLWS(bb);
115 value = readCookieValueRfc6265(bb);
116 if (value == null) {
117 // Invalid cookie value. Skip to the next semicolon
118 skipUntilSemiColon(bb);
119 logInvalidHeader(start, bb);
120 continue;
121 }
122 skipLWS(bb);
123 }
124
125 skipResult = skipByte(bb, SEMICOLON_BYTE);
126 if (skipResult == SkipResult.FOUND) {
127 // NO-OP
128 } else if (skipResult == SkipResult.NOT_FOUND) {
129 // Invalid cookie. Ignore it and skip to the next semicolon
130 skipUntilSemiColon(bb);
131 logInvalidHeader(start, bb);
132 continue;
133 } else {
134 // SkipResult.EOF
135 moreToProcess = false;
136 }
137
138 if (name.hasRemaining()) {
139 if (value == null) {
140 switch (cookiesWithoutEquals) {
141 case IGNORE: {
142 // This name-value-pair is a NO-OP
143 break;
144 }
145 case NAME: {
146 ServerCookie sc = serverCookies.addCookie();
147 sc.getName().setBytes(name.array(), name.position(), name.remaining());
148 sc.getValue().setBytes(EMPTY_BYTES, 0, EMPTY_BYTES.length);
149 break;
150 }
151 }

Callers 1

parseCookieHeaderMethod · 0.95

Calls 14

skipLWSMethod · 0.95
positionMethod · 0.95
readTokenMethod · 0.95
skipByteMethod · 0.95
skipUntilSemiColonMethod · 0.95
logInvalidHeaderMethod · 0.95
hasRemainingMethod · 0.95
getNameMethod · 0.95
arrayMethod · 0.95
remainingMethod · 0.95
getValueMethod · 0.95

Tested by

no test coverage detected