]>
Commit | Line | Data |
---|---|---|
528b2c61 | 1 | /* |
f70aedc4 | 2 | * Copyright (C) 1996-2021 The Squid Software Foundation and contributors |
528b2c61 | 3 | * |
bbc27441 AJ |
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. | |
528b2c61 | 7 | */ |
bbc27441 | 8 | |
528b2c61 | 9 | #ifndef SQUID_HTTPREPLY_H |
10 | #define SQUID_HTTPREPLY_H | |
11 | ||
602d9612 | 12 | #include "http/StatusLine.h" |
0521f8be | 13 | #include "HttpBody.h" |
582c2af2 | 14 | #include "HttpRequest.h" |
528b2c61 | 15 | |
8a648e8d | 16 | void httpReplyInitModule(void); |
e0459b28 | 17 | |
924f73bc | 18 | /* Sync changes here with HttpReply.cc */ |
19 | ||
20 | class HttpHdrContRange; | |
21 | ||
25b6a907 | 22 | class HttpHdrSc; |
23 | ||
63df1d28 | 24 | class HttpReply: public Http::Message |
924f73bc | 25 | { |
741c2986 | 26 | MEMPROXY_CLASS(HttpReply); |
924f73bc | 27 | |
28 | public: | |
b248c2a3 | 29 | typedef RefCount<HttpReply> Pointer; |
f3630c67 | 30 | |
75faaa7a | 31 | HttpReply(); |
06a5ae20 | 32 | ~HttpReply(); |
8596962e | 33 | |
34 | virtual void reset(); | |
35 | ||
e0459b28 AJ |
36 | /** |
37 | \retval true on success | |
38 | \retval false and sets *error to zero when needs more data | |
955394ce | 39 | \retval false and sets *error to a positive Http::StatusCode on error |
e0459b28 | 40 | */ |
84ae6223 | 41 | virtual bool sanityCheckStartLine(const char *buf, const size_t hdr_len, Http::StatusCode *error); |
924f73bc | 42 | |
e0459b28 | 43 | /** \par public, readable; never update these or their .hdr equivalents directly */ |
924f73bc | 44 | time_t date; |
4a56ee8d | 45 | |
924f73bc | 46 | time_t last_modified; |
4a56ee8d | 47 | |
924f73bc | 48 | time_t expires; |
4a56ee8d | 49 | |
30abd221 | 50 | String content_type; |
4a56ee8d | 51 | |
924f73bc | 52 | HttpHdrSc *surrogate_control; |
4a56ee8d | 53 | |
8341f96d EB |
54 | /// \returns parsed Content-Range for a 206 response and nil for others |
55 | const HttpHdrContRange *contentRange() const; | |
4a56ee8d | 56 | |
924f73bc | 57 | short int keep_alive; |
58 | ||
e0459b28 | 59 | /** \par public, writable, but use httpReply* interfaces when possible */ |
9b769c67 | 60 | Http::StatusLine sline; |
4a56ee8d | 61 | |
f53969cc | 62 | HttpBody body; /**< for small constant memory-resident text bodies only */ |
8596962e | 63 | |
e0459b28 | 64 | String protoPrefix; /**< e.g., "HTTP/" */ |
4a56ee8d | 65 | |
06a5ae20 | 66 | bool do_clean; |
8596962e | 67 | |
07947ad8 | 68 | public: |
fb525683 | 69 | virtual int httpMsgParseError(); |
70 | ||
60745f24 | 71 | virtual bool expectingBody(const HttpRequestMethod&, int64_t&) const; |
4a56ee8d | 72 | |
63df1d28 | 73 | virtual bool inheritProperties(const Http::Message *); |
d67acb4e | 74 | |
66d51f4f AR |
75 | /// \returns nil (if no updates are necessary) |
76 | /// \returns a new reply combining this reply with 304 updates (otherwise) | |
77 | Pointer recreateOnNotModified(const HttpReply &reply304) const; | |
4a56ee8d | 78 | |
e0459b28 | 79 | /** set commonly used info with one call */ |
955394ce | 80 | void setHeaders(Http::StatusCode status, |
47f6e231 | 81 | const char *reason, const char *ctype, int64_t clen, time_t lmt, time_t expires); |
4a56ee8d | 82 | |
e0459b28 | 83 | /** \return a ready to use mem buffer with a packed reply */ |
1f28a150 | 84 | MemBuf *pack() const; |
4a56ee8d | 85 | |
ea55799d EB |
86 | /// construct and return an HTTP/200 (Connection Established) response |
87 | static HttpReplyPointer MakeConnectionEstablished(); | |
88 | ||
e0459b28 | 89 | /** construct a 304 reply and return it */ |
66d51f4f | 90 | HttpReplyPointer make304() const; |
06a5ae20 | 91 | |
955394ce | 92 | void redirect(Http::StatusCode, const char *); |
4a56ee8d | 93 | |
60745f24 | 94 | int64_t bodySize(const HttpRequestMethod&) const; |
4a56ee8d | 95 | |
e0459b28 AJ |
96 | /** Checks whether received body exceeds known maximum size. |
97 | * Requires a prior call to calcMaxBodySize(). | |
98 | */ | |
0667cbfb | 99 | bool receivedBodyTooLarge(HttpRequest&, int64_t receivedBodySize); |
100 | ||
e0459b28 AJ |
101 | /** Checks whether expected body exceeds known maximum size. |
102 | * Requires a prior call to calcMaxBodySize(). | |
103 | */ | |
0667cbfb | 104 | bool expectedBodyTooLarge(HttpRequest& request); |
105 | ||
06a5ae20 | 106 | int validatorsMatch (HttpReply const *other) const; |
4a56ee8d | 107 | |
f8432432 EB |
108 | /// adds status line and header to the given Packable |
109 | /// assumes that `p` can quickly process small additions | |
110 | void packHeadersUsingFastPacker(Packable &p) const; | |
111 | /// same as packHeadersUsingFastPacker() but assumes that `p` cannot quickly process small additions | |
112 | void packHeadersUsingSlowPacker(Packable &p) const; | |
06a5ae20 | 113 | |
e0459b28 | 114 | /** Clone this reply. |
2f8abb64 | 115 | * Could be done as a copy-contructor but we do not want to accidentally copy a HttpReply.. |
e0459b28 | 116 | */ |
da33c835 HN |
117 | HttpReply *clone() const; |
118 | ||
c679653d AR |
119 | /// Remove Warnings with warn-date different from Date value |
120 | void removeStaleWarnings(); | |
121 | ||
434a79b0 DK |
122 | virtual void hdrCacheInit(); |
123 | ||
eace013e EB |
124 | /// whether our Date header value is smaller than theirs |
125 | /// \returns false if any information is missing | |
126 | bool olderThan(const HttpReply *them) const; | |
127 | ||
4f1c93a7 EB |
128 | /// Some response status codes prohibit sending Content-Length (RFC 7230 section 3.3.2). |
129 | void removeIrrelevantContentLength(); | |
130 | ||
131 | virtual void configureContentLengthInterpreter(Http::ContentLengthInterpreter &); | |
132 | /// parses reply header using Parser | |
133 | bool parseHeader(Http1::Parser &hp); | |
134 | ||
06a5ae20 | 135 | private: |
e0459b28 | 136 | /** initialize */ |
06a5ae20 | 137 | void init(); |
4a56ee8d | 138 | |
06a5ae20 | 139 | void clean(); |
4a56ee8d | 140 | |
06a5ae20 | 141 | void hdrCacheClean(); |
4a56ee8d | 142 | |
f8432432 | 143 | void packInto(MemBuf &) const; |
4a56ee8d | 144 | |
06a5ae20 | 145 | /* ez-routines */ |
e0459b28 | 146 | /** \return construct 304 reply and pack it into a MemBuf */ |
1f28a150 | 147 | MemBuf *packed304Reply() const; |
4a56ee8d | 148 | |
06a5ae20 | 149 | /* header manipulation */ |
150 | time_t hdrExpirationTime(); | |
07947ad8 | 151 | |
e0459b28 AJ |
152 | /** Calculates and stores maximum body size if needed. |
153 | * Used by receivedBodyTooLarge() and expectedBodyTooLarge(). | |
154 | */ | |
b248c2a3 | 155 | void calcMaxBodySize(HttpRequest& request) const; |
0667cbfb | 156 | |
c679653d AR |
157 | String removeStaleWarningValues(const String &value); |
158 | ||
e0459b28 | 159 | mutable int64_t bodySizeMax; /**< cached result of calcMaxBodySize */ |
0667cbfb | 160 | |
8341f96d EB |
161 | HttpHdrContRange *content_range; ///< parsed Content-Range; nil for non-206 responses! |
162 | ||
8596962e | 163 | protected: |
17802cf1 | 164 | virtual void packFirstLineInto(Packable * p, bool) const { sline.packInto(p); } |
4a56ee8d | 165 | |
429f7150 | 166 | virtual bool parseFirstLine(const char *start, const char *end); |
924f73bc | 167 | }; |
168 | ||
528b2c61 | 169 | #endif /* SQUID_HTTPREPLY_H */ |
f53969cc | 170 |