]> git.ipfire.org Git - thirdparty/squid.git/blob - src/client_side_request.h
SourceFormat Enforcement
[thirdparty/squid.git] / src / client_side_request.h
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_CLIENTSIDEREQUEST_H
10 #define SQUID_CLIENTSIDEREQUEST_H
11
12 #include "AccessLogEntry.h"
13 #include "acl/forward.h"
14 #include "client_side.h"
15 #include "clientStream.h"
16 #include "HttpHeaderRange.h"
17 #include "LogTags.h"
18
19 #if USE_ADAPTATION
20 #include "adaptation/forward.h"
21 #include "adaptation/Initiator.h"
22 class HttpMsg;
23 #endif
24
25 class ClientRequestContext;
26 class ConnStateData;
27 class MemObject;
28
29 /* client_side_request.c - client side request related routines (pure logic) */
30 int clientBeginRequest(const HttpRequestMethod&, char const *, CSCB *, CSD *, ClientStreamData, HttpHeader const *, char *, size_t);
31
32 class ClientHttpRequest
33 #if USE_ADAPTATION
34 : public Adaptation::Initiator, // to start adaptation transactions
35 public BodyConsumer // to receive reply bodies in request satisf. mode
36 #endif
37 {
38 CBDATA_CLASS(ClientHttpRequest);
39
40 public:
41 ClientHttpRequest(ConnStateData *csd);
42 ~ClientHttpRequest();
43 /* Not implemented - present to prevent synthetic operations */
44 ClientHttpRequest(ClientHttpRequest const &);
45 ClientHttpRequest& operator=(ClientHttpRequest const &);
46
47 String rangeBoundaryStr() const;
48 void freeResources();
49 void updateCounters();
50 void logRequest();
51 _SQUID_INLINE_ MemObject * memObject() const;
52 bool multipartRangeRequest() const;
53 void processRequest();
54 void httpStart();
55 bool onlyIfCached()const;
56 bool gotEnough() const;
57 _SQUID_INLINE_ StoreEntry *storeEntry() const;
58 void storeEntry(StoreEntry *);
59 _SQUID_INLINE_ StoreEntry *loggingEntry() const;
60 void loggingEntry(StoreEntry *);
61
62 _SQUID_INLINE_ ConnStateData * getConn() const;
63 _SQUID_INLINE_ void setConn(ConnStateData *);
64
65 /** Details of the client socket which produced us.
66 * Treat as read-only for the lifetime of this HTTP request.
67 */
68 Comm::ConnectionPointer clientConnection;
69
70 HttpRequest *request; /* Parsed URL ... */
71 char *uri;
72 char *log_uri;
73 String store_id; /* StoreID for transactions where the request member is nil */
74
75 struct Out {
76 Out() : offset(0), size(0), headers_sz(0) {}
77
78 int64_t offset;
79 uint64_t size;
80 size_t headers_sz;
81 } out;
82
83 HttpHdrRangeIter range_iter; /* data for iterating thru range specs */
84 size_t req_sz; /* raw request size on input, not current request size */
85
86 /// the processing tags associated with this request transaction.
87 // NP: still an enum so each stage altering it must take care when replacing it.
88 LogTags logType;
89
90 AccessLogEntry::Pointer al; ///< access.log entry
91
92 struct Flags {
93 Flags() : accel(false), internal(false), done_copying(false), purging(false) {}
94
95 bool accel;
96 bool internal;
97 bool done_copying;
98 bool purging;
99 } flags;
100
101 struct Redirect {
102 Redirect() : status(Http::scNone), location(NULL) {}
103
104 Http::StatusCode status;
105 char *location;
106 } redirect;
107
108 dlink_node active;
109 dlink_list client_stream;
110 int mRangeCLen();
111
112 ClientRequestContext *calloutContext;
113 void doCallouts();
114
115 /// Build an error reply. For use with the callouts.
116 void calloutsError(const err_type error, const int errDetail);
117
118 #if USE_ADAPTATION
119 // AsyncJob virtual methods
120 virtual bool doneAll() const {
121 return Initiator::doneAll() &&
122 BodyConsumer::doneAll() && false;
123 }
124 #endif
125
126 private:
127 int64_t maxReplyBodySize_;
128 StoreEntry *entry_;
129 StoreEntry *loggingEntry_;
130 ConnStateData * conn_;
131
132 #if USE_OPENSSL
133 /// whether (and how) the request needs to be bumped
134 Ssl::BumpMode sslBumpNeed_;
135
136 public:
137 /// returns raw sslBump mode value
138 Ssl::BumpMode sslBumpNeed() const { return sslBumpNeed_; }
139 /// returns true if and only if the request needs to be bumped
140 bool sslBumpNeeded() const { return sslBumpNeed_ == Ssl::bumpServerFirst || sslBumpNeed_ == Ssl::bumpClientFirst || sslBumpNeed_ == Ssl::bumpBump || sslBumpNeed_ == Ssl::bumpPeek || sslBumpNeed_ == Ssl::bumpStare; }
141 /// set the sslBumpNeeded state
142 void sslBumpNeed(Ssl::BumpMode mode);
143 void sslBumpStart();
144 void sslBumpEstablish(Comm::Flag errflag);
145 #endif
146
147 #if USE_ADAPTATION
148
149 public:
150 void startAdaptation(const Adaptation::ServiceGroupPointer &g);
151 bool requestSatisfactionMode() const { return request_satisfaction_mode; }
152
153 private:
154 /// Handles an adaptation client request failure.
155 /// Bypasses the error if possible, or build an error reply.
156 void handleAdaptationFailure(int errDetail, bool bypassable = false);
157
158 // Adaptation::Initiator API
159 virtual void noteAdaptationAnswer(const Adaptation::Answer &answer);
160 void handleAdaptedHeader(HttpMsg *msg);
161 void handleAdaptationBlock(const Adaptation::Answer &answer);
162 virtual void noteAdaptationAclCheckDone(Adaptation::ServiceGroupPointer group);
163
164 // BodyConsumer API, called by BodyPipe
165 virtual void noteMoreBodyDataAvailable(BodyPipe::Pointer);
166 virtual void noteBodyProductionEnded(BodyPipe::Pointer);
167 virtual void noteBodyProducerAborted(BodyPipe::Pointer);
168
169 void endRequestSatisfaction();
170 /// called by StoreEntry when it has more buffer space available
171 void resumeBodyStorage();
172
173 private:
174 CbcPointer<Adaptation::Initiate> virginHeadSource;
175 BodyPipe::Pointer adaptedBodySource;
176
177 bool request_satisfaction_mode;
178 int64_t request_satisfaction_offset;
179 #endif
180 };
181
182 /* client http based routines */
183 char *clientConstructTraceEcho(ClientHttpRequest *);
184
185 ACLFilledChecklist *clientAclChecklistCreate(const acl_access * acl,ClientHttpRequest * http);
186 int clientHttpRequestStatus(int fd, ClientHttpRequest const *http);
187 void clientAccessCheck(ClientHttpRequest *);
188
189 /* ones that should be elsewhere */
190 void tunnelStart(ClientHttpRequest *);
191
192 #if _USE_INLINE_
193 #include "client_side_request.cci"
194 #include "Store.h"
195 #endif
196
197 #endif /* SQUID_CLIENTSIDEREQUEST_H */
198