]>
git.ipfire.org Git - thirdparty/squid.git/blob - src/HttpReply.h
2 * Copyright (C) 1996-2020 The Squid Software Foundation and contributors
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.
9 #ifndef SQUID_HTTPREPLY_H
10 #define SQUID_HTTPREPLY_H
12 #include "http/StatusLine.h"
14 #include "HttpRequest.h"
16 void httpReplyInitModule(void);
18 /* Sync changes here with HttpReply.cc */
20 class HttpHdrContRange
;
24 class HttpReply
: public Http::Message
26 MEMPROXY_CLASS(HttpReply
);
29 typedef RefCount
<HttpReply
> Pointer
;
37 \retval true on success
38 \retval false and sets *error to zero when needs more data
39 \retval false and sets *error to a positive Http::StatusCode on error
41 virtual bool sanityCheckStartLine(const char *buf
, const size_t hdr_len
, Http::StatusCode
*error
);
43 /** \par public, readable; never update these or their .hdr equivalents directly */
52 HttpHdrSc
*surrogate_control
;
54 /// \returns parsed Content-Range for a 206 response and nil for others
55 const HttpHdrContRange
*contentRange() const;
59 /** \par public, writable, but use httpReply* interfaces when possible */
60 Http::StatusLine sline
;
62 HttpBody body
; /**< for small constant memory-resident text bodies only */
64 String protoPrefix
; /**< e.g., "HTTP/" */
69 virtual int httpMsgParseError();
71 virtual bool expectingBody(const HttpRequestMethod
&, int64_t&) const;
73 virtual bool inheritProperties(const Http::Message
*);
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;
79 /** set commonly used info with one call */
80 void setHeaders(Http::StatusCode status
,
81 const char *reason
, const char *ctype
, int64_t clen
, time_t lmt
, time_t expires
);
83 /** \return a ready to use mem buffer with a packed reply */
86 /// construct and return an HTTP/200 (Connection Established) response
87 static HttpReplyPointer
MakeConnectionEstablished();
89 /** construct a 304 reply and return it */
90 HttpReplyPointer
make304() const;
92 void redirect(Http::StatusCode
, const char *);
94 int64_t bodySize(const HttpRequestMethod
&) const;
96 /** Checks whether received body exceeds known maximum size.
97 * Requires a prior call to calcMaxBodySize().
99 bool receivedBodyTooLarge(HttpRequest
&, int64_t receivedBodySize
);
101 /** Checks whether expected body exceeds known maximum size.
102 * Requires a prior call to calcMaxBodySize().
104 bool expectedBodyTooLarge(HttpRequest
& request
);
106 int validatorsMatch (HttpReply
const *other
) const;
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;
114 /** Clone this reply.
115 * Could be done as a copy-contructor but we do not want to accidently copy a HttpReply..
117 HttpReply
*clone() const;
119 /// Remove Warnings with warn-date different from Date value
120 void removeStaleWarnings();
122 virtual void hdrCacheInit();
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;
128 /// Some response status codes prohibit sending Content-Length (RFC 7230 section 3.3.2).
129 void removeIrrelevantContentLength();
131 virtual void configureContentLengthInterpreter(Http::ContentLengthInterpreter
&);
132 /// parses reply header using Parser
133 bool parseHeader(Http1::Parser
&hp
);
141 void hdrCacheClean();
143 void packInto(MemBuf
&) const;
146 /** \return construct 304 reply and pack it into a MemBuf */
147 MemBuf
*packed304Reply() const;
149 /* header manipulation */
150 time_t hdrExpirationTime();
152 /** Calculates and stores maximum body size if needed.
153 * Used by receivedBodyTooLarge() and expectedBodyTooLarge().
155 void calcMaxBodySize(HttpRequest
& request
) const;
157 String
removeStaleWarningValues(const String
&value
);
159 mutable int64_t bodySizeMax
; /**< cached result of calcMaxBodySize */
161 HttpHdrContRange
*content_range
; ///< parsed Content-Range; nil for non-206 responses!
164 virtual void packFirstLineInto(Packable
* p
, bool) const { sline
.packInto(p
); }
166 virtual bool parseFirstLine(const char *start
, const char *end
);
169 #endif /* SQUID_HTTPREPLY_H */