]>
Commit | Line | Data |
---|---|---|
1 | /* | |
2 | * Copyright (C) 1996-2017 The Squid Software Foundation and contributors | |
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_HTTPREPLY_H | |
10 | #define SQUID_HTTPREPLY_H | |
11 | ||
12 | #include "http/StatusLine.h" | |
13 | #include "HttpBody.h" | |
14 | #include "HttpMsg.h" | |
15 | #include "HttpRequest.h" | |
16 | ||
17 | void httpReplyInitModule(void); | |
18 | ||
19 | /* Sync changes here with HttpReply.cc */ | |
20 | ||
21 | class HttpHdrContRange; | |
22 | ||
23 | class HttpHdrSc; | |
24 | ||
25 | class HttpReply: public HttpMsg | |
26 | { | |
27 | MEMPROXY_CLASS(HttpReply); | |
28 | ||
29 | public: | |
30 | typedef RefCount<HttpReply> Pointer; | |
31 | ||
32 | HttpReply(); | |
33 | ~HttpReply(); | |
34 | ||
35 | virtual void reset(); | |
36 | ||
37 | /** | |
38 | \retval true on success | |
39 | \retval false and sets *error to zero when needs more data | |
40 | \retval false and sets *error to a positive Http::StatusCode on error | |
41 | */ | |
42 | virtual bool sanityCheckStartLine(const char *buf, const size_t hdr_len, Http::StatusCode *error); | |
43 | ||
44 | /** \par public, readable; never update these or their .hdr equivalents directly */ | |
45 | time_t date; | |
46 | ||
47 | time_t last_modified; | |
48 | ||
49 | time_t expires; | |
50 | ||
51 | String content_type; | |
52 | ||
53 | HttpHdrSc *surrogate_control; | |
54 | ||
55 | HttpHdrContRange *content_range; | |
56 | ||
57 | short int keep_alive; | |
58 | ||
59 | /** \par public, writable, but use httpReply* interfaces when possible */ | |
60 | Http::StatusLine sline; | |
61 | ||
62 | HttpBody body; /**< for small constant memory-resident text bodies only */ | |
63 | ||
64 | String protoPrefix; /**< e.g., "HTTP/" */ | |
65 | ||
66 | bool do_clean; | |
67 | ||
68 | public: | |
69 | virtual int httpMsgParseError(); | |
70 | ||
71 | virtual bool expectingBody(const HttpRequestMethod&, int64_t&) const; | |
72 | ||
73 | virtual bool inheritProperties(const HttpMsg *aMsg); | |
74 | ||
75 | bool updateOnNotModified(HttpReply const *other); | |
76 | ||
77 | /** set commonly used info with one call */ | |
78 | void setHeaders(Http::StatusCode status, | |
79 | const char *reason, const char *ctype, int64_t clen, time_t lmt, time_t expires); | |
80 | ||
81 | /** \return a ready to use mem buffer with a packed reply */ | |
82 | MemBuf *pack() const; | |
83 | ||
84 | /** construct a 304 reply and return it */ | |
85 | HttpReply *make304() const; | |
86 | ||
87 | void redirect(Http::StatusCode, const char *); | |
88 | ||
89 | int64_t bodySize(const HttpRequestMethod&) const; | |
90 | ||
91 | /** Checks whether received body exceeds known maximum size. | |
92 | * Requires a prior call to calcMaxBodySize(). | |
93 | */ | |
94 | bool receivedBodyTooLarge(HttpRequest&, int64_t receivedBodySize); | |
95 | ||
96 | /** Checks whether expected body exceeds known maximum size. | |
97 | * Requires a prior call to calcMaxBodySize(). | |
98 | */ | |
99 | bool expectedBodyTooLarge(HttpRequest& request); | |
100 | ||
101 | int validatorsMatch (HttpReply const *other) const; | |
102 | ||
103 | void packHeadersInto(Packable * p) const; | |
104 | ||
105 | /** Clone this reply. | |
106 | * Could be done as a copy-contructor but we do not want to accidently copy a HttpReply.. | |
107 | */ | |
108 | HttpReply *clone() const; | |
109 | ||
110 | /// Remove Warnings with warn-date different from Date value | |
111 | void removeStaleWarnings(); | |
112 | ||
113 | virtual void hdrCacheInit(); | |
114 | ||
115 | /// whether our Date header value is smaller than theirs | |
116 | /// \returns false if any information is missing | |
117 | bool olderThan(const HttpReply *them) const; | |
118 | ||
119 | private: | |
120 | /** initialize */ | |
121 | void init(); | |
122 | ||
123 | void clean(); | |
124 | ||
125 | void hdrCacheClean(); | |
126 | ||
127 | void packInto(Packable * p) const; | |
128 | ||
129 | /* ez-routines */ | |
130 | /** \return construct 304 reply and pack it into a MemBuf */ | |
131 | MemBuf *packed304Reply() const; | |
132 | ||
133 | /* header manipulation */ | |
134 | time_t hdrExpirationTime(); | |
135 | ||
136 | /** Calculates and stores maximum body size if needed. | |
137 | * Used by receivedBodyTooLarge() and expectedBodyTooLarge(). | |
138 | */ | |
139 | void calcMaxBodySize(HttpRequest& request) const; | |
140 | ||
141 | String removeStaleWarningValues(const String &value); | |
142 | ||
143 | mutable int64_t bodySizeMax; /**< cached result of calcMaxBodySize */ | |
144 | ||
145 | protected: | |
146 | virtual void packFirstLineInto(Packable * p, bool) const { sline.packInto(p); } | |
147 | ||
148 | virtual bool parseFirstLine(const char *start, const char *end); | |
149 | }; | |
150 | ||
151 | #endif /* SQUID_HTTPREPLY_H */ | |
152 |