]>
Commit | Line | Data |
---|---|---|
a1b9ec20 | 1 | /* |
f70aedc4 | 2 | * Copyright (C) 1996-2021 The Squid Software Foundation and contributors |
a1b9ec20 AR |
3 | * |
4 | * Squid software is distributed under GPLv2+ license and includes | |
5 | * contributions from numerous individuals and organizations. | |
6 | * Please see the COPYING and CONTRIBUTORS files for details. | |
7 | */ | |
8 | ||
9 | #ifndef SQUID_SRC_HTTP_CONTENTLENGTH_INTERPRETER_H | |
10 | #define SQUID_SRC_HTTP_CONTENTLENGTH_INTERPRETER_H | |
11 | ||
4f1c93a7 EB |
12 | #include "http/StatusCode.h" |
13 | ||
a1b9ec20 AR |
14 | class String; |
15 | ||
16 | namespace Http | |
17 | { | |
18 | ||
19 | /// Finds the intended Content-Length value while parsing message-header fields. | |
20 | /// Deals with complications such as value lists and/or repeated fields. | |
21 | class ContentLengthInterpreter | |
22 | { | |
23 | public: | |
4f1c93a7 | 24 | ContentLengthInterpreter(); |
a1b9ec20 AR |
25 | |
26 | /// updates history based on the given message-header field | |
27 | /// \return true iff the field should be added/remembered for future use | |
28 | bool checkField(const String &field); | |
29 | ||
4f1c93a7 EB |
30 | /// prohibits Content-Length in 1xx and 204 responses |
31 | void applyStatusCodeRules(const StatusCode code) { | |
32 | if (!prohibitedAndIgnored_ && ProhibitsContentLength(code)) | |
33 | prohibitedAndIgnored_ = (code == scNoContent) ? "prohibited and ignored in the 204 response" : | |
34 | "prohibited and ignored the 1xx response"; | |
35 | } | |
36 | ||
37 | // TODO: implement | |
38 | /// prohibits Content-Length in GET/HEAD requests | |
39 | // void applyRequestMethodRules(const Http::MethodType method); | |
40 | ||
41 | /// prohibits Content-Length in trailer | |
42 | void applyTrailerRules() { | |
43 | if (!prohibitedAndIgnored_) | |
44 | prohibitedAndIgnored_ = "prohibited in trailers"; | |
45 | } | |
46 | ||
47 | const char *prohibitedAndIgnored() const { return prohibitedAndIgnored_; } | |
48 | ||
a1b9ec20 AR |
49 | /// intended Content-Length value if sawGood is set and sawBad is not set |
50 | /// meaningless otherwise | |
51 | int64_t value; | |
52 | ||
53 | /* for debugging (declared here to minimize padding) */ | |
54 | const char *headerWideProblem; ///< worst header-wide problem found (or nil) | |
55 | const int debugLevel; ///< debugging level for certain warnings | |
56 | ||
57 | /// whether a malformed Content-Length value was present | |
58 | bool sawBad; | |
59 | ||
60 | /// whether all remembered fields should be removed | |
61 | /// removed fields ought to be replaced with the intended value (if known) | |
62 | /// irrelevant if sawBad is set | |
63 | bool needsSanitizing; | |
64 | ||
65 | /// whether a valid field value was present, possibly among problematic ones | |
66 | /// irrelevant if sawBad is set | |
67 | bool sawGood; | |
68 | ||
69 | protected: | |
9fcf5206 | 70 | const char *findDigits(const char *prefix, const char *valueEnd) const; |
a1b9ec20 AR |
71 | bool goodSuffix(const char *suffix, const char * const end) const; |
72 | bool checkValue(const char *start, const int size); | |
73 | bool checkList(const String &list); | |
4f1c93a7 EB |
74 | |
75 | private: | |
76 | /// whether and why Content-Length is prohibited | |
77 | const char *prohibitedAndIgnored_; | |
a1b9ec20 AR |
78 | }; |
79 | ||
80 | } // namespace Http | |
81 | ||
82 | #endif /* SQUID_SRC_HTTP_CONTENTLENGTH_INTERPRETER_H */ | |
83 |