]>
git.ipfire.org Git - thirdparty/squid.git/blob - src/HttpReply.h
2 * Copyright (C) 1996-2023 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
;
32 ~HttpReply() override
;
34 void reset() override
;
36 /* Http::Message API */
37 bool sanityCheckStartLine(const char *buf
, const size_t hdr_len
, Http::StatusCode
*error
) override
;
39 /** \par public, readable; never update these or their .hdr equivalents directly */
48 HttpHdrSc
*surrogate_control
;
50 /// \returns parsed Content-Range for a 206 response and nil for others
51 const HttpHdrContRange
*contentRange() const;
55 /** \par public, writable, but use httpReply* interfaces when possible */
56 Http::StatusLine sline
;
58 HttpBody body
; /**< for small constant memory-resident text bodies only */
60 String protoPrefix
; /**< e.g., "HTTP/" */
65 int httpMsgParseError() override
;
67 bool expectingBody(const HttpRequestMethod
&, int64_t&) const override
;
69 bool inheritProperties(const Http::Message
*) override
;
71 /// \returns nil (if no updates are necessary)
72 /// \returns a new reply combining this reply with 304 updates (otherwise)
73 Pointer
recreateOnNotModified(const HttpReply
&reply304
) const;
75 /** set commonly used info with one call */
76 void setHeaders(Http::StatusCode status
,
77 const char *reason
, const char *ctype
, int64_t clen
, time_t lmt
, time_t expires
);
79 /** \return a ready to use mem buffer with a packed reply */
82 /// construct and return an HTTP/200 (Connection Established) response
83 static HttpReplyPointer
MakeConnectionEstablished();
85 /** construct a 304 reply and return it */
86 HttpReplyPointer
make304() const;
88 void redirect(Http::StatusCode
, const char *);
90 int64_t bodySize(const HttpRequestMethod
&) const;
92 /** Checks whether received body exceeds known maximum size.
93 * Requires a prior call to calcMaxBodySize().
95 bool receivedBodyTooLarge(HttpRequest
&, int64_t receivedBodySize
);
97 /** Checks whether expected body exceeds known maximum size.
98 * Requires a prior call to calcMaxBodySize().
100 bool expectedBodyTooLarge(HttpRequest
& request
);
102 int validatorsMatch (HttpReply
const *other
) const;
104 /// adds status line and header to the given Packable
105 /// assumes that `p` can quickly process small additions
106 void packHeadersUsingFastPacker(Packable
&p
) const;
107 /// same as packHeadersUsingFastPacker() but assumes that `p` cannot quickly process small additions
108 void packHeadersUsingSlowPacker(Packable
&p
) const;
110 /** Clone this reply.
111 * Could be done as a copy-contructor but we do not want to accidentally copy a HttpReply..
113 HttpReply
*clone() const override
;
115 void hdrCacheInit() override
;
117 /// whether our Date header value is smaller than theirs
118 /// \returns false if any information is missing
119 bool olderThan(const HttpReply
*them
) const;
121 /// Some response status codes prohibit sending Content-Length (RFC 7230 section 3.3.2).
122 void removeIrrelevantContentLength();
124 void configureContentLengthInterpreter(Http::ContentLengthInterpreter
&) override
;
125 /// parses reply header using Parser
126 bool parseHeader(Http1::Parser
&hp
);
128 /// Parses response status line and headers at the start of the given
129 /// NUL-terminated buffer of the given size. Respects reply_header_max_size.
130 /// Assures pstate becomes Http::Message::psParsed on (and only on) success.
131 /// \returns the number of bytes in a successfully parsed prefix (or zero)
132 /// \retval 0 implies that more data is needed to parse the response prefix
133 size_t parseTerminatedPrefix(const char *, size_t);
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 mutable int64_t bodySizeMax
; /**< cached result of calcMaxBodySize */
159 HttpHdrContRange
*content_range
; ///< parsed Content-Range; nil for non-206 responses!
162 void packFirstLineInto(Packable
* p
, bool) const override
{ sline
.packInto(p
); }
164 bool parseFirstLine(const char *start
, const char *end
) override
;
167 #endif /* SQUID_HTTPREPLY_H */