]> 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-2015 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 {
76 int64_t offset;
77 int64_t size;
78 size_t headers_sz;
79 } out;
80
81 HttpHdrRangeIter range_iter; /* data for iterating thru range specs */
82 size_t req_sz; /* raw request size on input, not current request size */
83
84 /// the processing tags associated with this request transaction.
85 // NP: still an enum so each stage altering it must take care when replacing it.
86 LogTags logType;
87
88 AccessLogEntry::Pointer al; ///< access.log entry
89
90 struct {
91 bool accel;
92 //bool intercepted; //XXX: it's apparently never used.
93 //bool spoof_client_ip; //XXX: it's apparently never used.
94 bool internal;
95 bool done_copying;
96 bool purging;
97 } flags;
98
99 struct {
100 Http::StatusCode status;
101 char *location;
102 } redirect;
103
104 dlink_node active;
105 dlink_list client_stream;
106 int mRangeCLen();
107
108 ClientRequestContext *calloutContext;
109 void doCallouts();
110
111 /// Build an error reply. For use with the callouts.
112 void calloutsError(const err_type error, const int errDetail);
113
114 #if USE_ADAPTATION
115 // AsyncJob virtual methods
116 virtual bool doneAll() const {
117 return Initiator::doneAll() &&
118 BodyConsumer::doneAll() && false;
119 }
120 #endif
121
122 private:
123 int64_t maxReplyBodySize_;
124 StoreEntry *entry_;
125 StoreEntry *loggingEntry_;
126 ConnStateData * conn_;
127
128 #if USE_OPENSSL
129 /// whether (and how) the request needs to be bumped
130 Ssl::BumpMode sslBumpNeed_;
131
132 public:
133 /// returns raw sslBump mode value
134 Ssl::BumpMode sslBumpNeed() const { return sslBumpNeed_; }
135 /// returns true if and only if the request needs to be bumped
136 bool sslBumpNeeded() const { return sslBumpNeed_ == Ssl::bumpServerFirst || sslBumpNeed_ == Ssl::bumpClientFirst || sslBumpNeed_ == Ssl::bumpBump || sslBumpNeed_ == Ssl::bumpPeek || sslBumpNeed_ == Ssl::bumpStare; }
137 /// set the sslBumpNeeded state
138 void sslBumpNeed(Ssl::BumpMode mode);
139 void sslBumpStart();
140 void sslBumpEstablish(Comm::Flag errflag);
141 #endif
142
143 #if USE_ADAPTATION
144
145 public:
146 void startAdaptation(const Adaptation::ServiceGroupPointer &g);
147
148 private:
149 /// Handles an adaptation client request failure.
150 /// Bypasses the error if possible, or build an error reply.
151 void handleAdaptationFailure(int errDetail, bool bypassable = false);
152
153 // Adaptation::Initiator API
154 virtual void noteAdaptationAnswer(const Adaptation::Answer &answer);
155 void handleAdaptedHeader(HttpMsg *msg);
156 void handleAdaptationBlock(const Adaptation::Answer &answer);
157 virtual void noteAdaptationAclCheckDone(Adaptation::ServiceGroupPointer group);
158
159 // BodyConsumer API, called by BodyPipe
160 virtual void noteMoreBodyDataAvailable(BodyPipe::Pointer);
161 virtual void noteBodyProductionEnded(BodyPipe::Pointer);
162 virtual void noteBodyProducerAborted(BodyPipe::Pointer);
163
164 void endRequestSatisfaction();
165 /// called by StoreEntry when it has more buffer space available
166 void resumeBodyStorage();
167
168 private:
169 CbcPointer<Adaptation::Initiate> virginHeadSource;
170 BodyPipe::Pointer adaptedBodySource;
171
172 bool request_satisfaction_mode;
173 int64_t request_satisfaction_offset;
174 #endif
175 };
176
177 /* client http based routines */
178 char *clientConstructTraceEcho(ClientHttpRequest *);
179
180 ACLFilledChecklist *clientAclChecklistCreate(const acl_access * acl,ClientHttpRequest * http);
181 int clientHttpRequestStatus(int fd, ClientHttpRequest const *http);
182 void clientAccessCheck(ClientHttpRequest *);
183
184 /* ones that should be elsewhere */
185 void tunnelStart(ClientHttpRequest *, int64_t *, int *, const AccessLogEntry::Pointer &al);
186
187 #if _USE_INLINE_
188 #include "client_side_request.cci"
189 #include "Store.h"
190 #endif
191
192 #endif /* SQUID_CLIENTSIDEREQUEST_H */
193