1 // Copyright (c) 2009 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 // Utility class that performs basic operations on header value tokens: parsing 6 // them out, checking for presense of certain tokens, and removing them. 7 8 #ifndef NET_TOOLS_FLIP_SERVER_BALSA_HEADERS_TOKEN_UTILS_H_ 9 #define NET_TOOLS_FLIP_SERVER_BALSA_HEADERS_TOKEN_UTILS_H_ 10 #pragma once 11 12 #include "net/tools/flip_server/balsa_headers.h" 13 #include "base/string_piece.h" 14 15 namespace net { 16 17 class BalsaHeadersTokenUtils { 18 public: 19 // All the functions below respect multiple header lines with the same key. 20 21 // Checks whether the last header token matches a given value. Useful to 22 // check the outer-most content or transfer-encoding, for example. In the 23 // presence of multiple header lines with given key, the last token of the 24 // last line is compared. 25 static bool CheckHeaderForLastToken(const BalsaHeaders& headers, 26 const base::StringPiece& key, 27 const base::StringPiece& token); 28 29 // Tokenizes header value for a given key. In the presence of multiple lines 30 // with that key, all of them will be tokenized and tokens will be added to 31 // the list in the order in which they are encountered. 32 static void TokenizeHeaderValue(const BalsaHeaders& headers, 33 const base::StringPiece& key, 34 BalsaHeaders::HeaderTokenList* tokens); 35 36 // Removes the last token from the header value. In the presence of multiple 37 // header lines with given key, will remove the last token of the last line. 38 // Can be useful if the last encoding has to be removed. 39 static void RemoveLastTokenFromHeaderValue(const base::StringPiece& key, 40 BalsaHeaders* headers); 41 42 // Given a pointer to the beginning and the end of the header value 43 // in some buffer, populates tokens list with beginning and end indices 44 // of all tokens present in the value string. 45 static void ParseTokenList(const char* start, 46 const char* end, 47 BalsaHeaders::HeaderTokenList* tokens); 48 49 private: 50 // Helper function to tokenize a header line once we have its description. 51 static void TokenizeHeaderLine( 52 const BalsaHeaders& headers, 53 const BalsaHeaders::HeaderLineDescription& line, 54 BalsaHeaders::HeaderTokenList* tokens); 55 56 BalsaHeadersTokenUtils(); // Prohibit instantiation 57 }; 58 59 } // namespace net 60 61 #endif // NET_TOOLS_FLIP_SERVER_BALSA_HEADERS_TOKEN_UTILS_H_ 62 63