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