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