]>
Commit | Line | Data |
---|---|---|
528b2c61 | 1 | /* |
bbc27441 | 2 | * Copyright (C) 1996-2014 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" |
8596962e | 14 | #include "HttpMsg.h" |
582c2af2 | 15 | #include "HttpRequest.h" |
528b2c61 | 16 | |
8a648e8d | 17 | void httpReplyInitModule(void); |
e0459b28 | 18 | |
924f73bc | 19 | /* Sync changes here with HttpReply.cc */ |
20 | ||
21 | class HttpHdrContRange; | |
22 | ||
25b6a907 | 23 | class HttpHdrSc; |
24 | ||
8596962e | 25 | class HttpReply: public HttpMsg |
924f73bc | 26 | { |
741c2986 | 27 | MEMPROXY_CLASS(HttpReply); |
924f73bc | 28 | |
29 | public: | |
b248c2a3 | 30 | typedef RefCount<HttpReply> Pointer; |
f3630c67 | 31 | |
75faaa7a | 32 | HttpReply(); |
06a5ae20 | 33 | ~HttpReply(); |
8596962e | 34 | |
35 | virtual void reset(); | |
36 | ||
e0459b28 AJ |
37 | /** |
38 | \retval true on success | |
39 | \retval false and sets *error to zero when needs more data | |
955394ce | 40 | \retval false and sets *error to a positive Http::StatusCode on error |
e0459b28 | 41 | */ |
955394ce | 42 | virtual bool sanityCheckStartLine(MemBuf *buf, const size_t hdr_len, Http::StatusCode *error); |
924f73bc | 43 | |
e0459b28 | 44 | /** \par public, readable; never update these or their .hdr equivalents directly */ |
924f73bc | 45 | time_t date; |
4a56ee8d | 46 | |
924f73bc | 47 | time_t last_modified; |
4a56ee8d | 48 | |
924f73bc | 49 | time_t expires; |
4a56ee8d | 50 | |
30abd221 | 51 | String content_type; |
4a56ee8d | 52 | |
924f73bc | 53 | HttpHdrSc *surrogate_control; |
4a56ee8d | 54 | |
924f73bc | 55 | HttpHdrContRange *content_range; |
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 | |
d67acb4e AJ |
73 | virtual bool inheritProperties(const HttpMsg *aMsg); |
74 | ||
06a5ae20 | 75 | void updateOnNotModified(HttpReply const *other); |
4a56ee8d | 76 | |
e0459b28 | 77 | /** set commonly used info with one call */ |
955394ce | 78 | void setHeaders(Http::StatusCode status, |
47f6e231 | 79 | const char *reason, const char *ctype, int64_t clen, time_t lmt, time_t expires); |
4a56ee8d | 80 | |
e0459b28 | 81 | /** \return a ready to use mem buffer with a packed reply */ |
06a5ae20 | 82 | MemBuf *pack(); |
4a56ee8d | 83 | |
e0459b28 | 84 | /** construct a 304 reply and return it */ |
06a5ae20 | 85 | HttpReply *make304() const; |
86 | ||
955394ce | 87 | void redirect(Http::StatusCode, const char *); |
4a56ee8d | 88 | |
60745f24 | 89 | int64_t bodySize(const HttpRequestMethod&) const; |
4a56ee8d | 90 | |
e0459b28 AJ |
91 | /** Checks whether received body exceeds known maximum size. |
92 | * Requires a prior call to calcMaxBodySize(). | |
93 | */ | |
0667cbfb | 94 | bool receivedBodyTooLarge(HttpRequest&, int64_t receivedBodySize); |
95 | ||
e0459b28 AJ |
96 | /** Checks whether expected body exceeds known maximum size. |
97 | * Requires a prior call to calcMaxBodySize(). | |
98 | */ | |
0667cbfb | 99 | bool expectedBodyTooLarge(HttpRequest& request); |
100 | ||
06a5ae20 | 101 | int validatorsMatch (HttpReply const *other) const; |
4a56ee8d | 102 | |
06a5ae20 | 103 | void packHeadersInto(Packer * p) const; |
104 | ||
e0459b28 AJ |
105 | /** Clone this reply. |
106 | * Could be done as a copy-contructor but we do not want to accidently copy a HttpReply.. | |
107 | */ | |
da33c835 HN |
108 | HttpReply *clone() const; |
109 | ||
c679653d AR |
110 | /// Remove Warnings with warn-date different from Date value |
111 | void removeStaleWarnings(); | |
112 | ||
434a79b0 DK |
113 | virtual void hdrCacheInit(); |
114 | ||
06a5ae20 | 115 | private: |
e0459b28 | 116 | /** initialize */ |
06a5ae20 | 117 | void init(); |
4a56ee8d | 118 | |
06a5ae20 | 119 | void clean(); |
4a56ee8d | 120 | |
06a5ae20 | 121 | void hdrCacheClean(); |
4a56ee8d | 122 | |
06a5ae20 | 123 | void packInto(Packer * p); |
4a56ee8d | 124 | |
06a5ae20 | 125 | /* ez-routines */ |
e0459b28 | 126 | /** \return construct 304 reply and pack it into a MemBuf */ |
06a5ae20 | 127 | MemBuf *packed304Reply(); |
4a56ee8d | 128 | |
06a5ae20 | 129 | /* header manipulation */ |
130 | time_t hdrExpirationTime(); | |
07947ad8 | 131 | |
e0459b28 AJ |
132 | /** Calculates and stores maximum body size if needed. |
133 | * Used by receivedBodyTooLarge() and expectedBodyTooLarge(). | |
134 | */ | |
b248c2a3 | 135 | void calcMaxBodySize(HttpRequest& request) const; |
0667cbfb | 136 | |
c679653d AR |
137 | String removeStaleWarningValues(const String &value); |
138 | ||
e0459b28 | 139 | mutable int64_t bodySizeMax; /**< cached result of calcMaxBodySize */ |
0667cbfb | 140 | |
8596962e | 141 | protected: |
9b769c67 | 142 | virtual void packFirstLineInto(Packer * p, bool) const { sline.packInto(p); } |
4a56ee8d | 143 | |
429f7150 | 144 | virtual bool parseFirstLine(const char *start, const char *end); |
924f73bc | 145 | }; |
146 | ||
528b2c61 | 147 | #endif /* SQUID_HTTPREPLY_H */ |
f53969cc | 148 |