2 * Copyright (C) 1996-2017 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_CLIENTSIDEREQUEST_H
10 #define SQUID_CLIENTSIDEREQUEST_H
12 #include "AccessLogEntry.h"
13 #include "acl/forward.h"
14 #include "client_side.h"
15 #include "clientStream.h"
16 #include "HttpHeaderRange.h"
20 #include "adaptation/forward.h"
21 #include "adaptation/Initiator.h"
25 class ClientRequestContext
;
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);
32 class ClientHttpRequest
34 : public Adaptation::Initiator
, // to start adaptation transactions
35 public BodyConsumer
// to receive reply bodies in request satisf. mode
38 CBDATA_CLASS(ClientHttpRequest
);
41 ClientHttpRequest(ConnStateData
*csd
);
43 /* Not implemented - present to prevent synthetic operations */
44 ClientHttpRequest(ClientHttpRequest
const &);
45 ClientHttpRequest
& operator=(ClientHttpRequest
const &);
47 String
rangeBoundaryStr() const;
49 void updateCounters();
51 _SQUID_INLINE_ MemObject
* memObject() const;
52 bool multipartRangeRequest() const;
53 void processRequest();
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
*);
62 _SQUID_INLINE_ ConnStateData
* getConn() const;
63 _SQUID_INLINE_
void setConn(ConnStateData
*);
65 /** Details of the client socket which produced us.
66 * Treat as read-only for the lifetime of this HTTP request.
68 Comm::ConnectionPointer clientConnection
;
70 HttpRequest
*request
; /* Parsed URL ... */
73 String store_id
; /* StoreID for transactions where the request member is nil */
76 Out() : offset(0), size(0), headers_sz(0) {}
83 HttpHdrRangeIter range_iter
; /* data for iterating thru range specs */
84 size_t req_sz
; /* raw request size on input, not current request size */
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.
90 AccessLogEntry::Pointer al
; ///< access.log entry
93 Flags() : accel(false), internal(false), done_copying(false), purging(false) {}
102 Redirect() : status(Http::scNone
), location(NULL
) {}
104 Http::StatusCode status
;
109 dlink_list client_stream
;
112 ClientRequestContext
*calloutContext
;
115 /// Build an error reply. For use with the callouts.
116 void calloutsError(const err_type error
, const int errDetail
);
119 // AsyncJob virtual methods
120 virtual bool doneAll() const {
121 return Initiator::doneAll() &&
122 BodyConsumer::doneAll() && false;
127 int64_t maxReplyBodySize_
;
129 StoreEntry
*loggingEntry_
;
130 ConnStateData
* conn_
;
133 /// whether (and how) the request needs to be bumped
134 Ssl::BumpMode sslBumpNeed_
;
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
);
144 void sslBumpEstablish(Comm::Flag errflag
);
150 void startAdaptation(const Adaptation::ServiceGroupPointer
&g
);
151 bool requestSatisfactionMode() const { return request_satisfaction_mode
; }
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);
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
);
164 // BodyConsumer API, called by BodyPipe
165 virtual void noteMoreBodyDataAvailable(BodyPipe::Pointer
);
166 virtual void noteBodyProductionEnded(BodyPipe::Pointer
);
167 virtual void noteBodyProducerAborted(BodyPipe::Pointer
);
169 void endRequestSatisfaction();
170 /// called by StoreEntry when it has more buffer space available
171 void resumeBodyStorage();
174 CbcPointer
<Adaptation::Initiate
> virginHeadSource
;
175 BodyPipe::Pointer adaptedBodySource
;
177 bool request_satisfaction_mode
;
178 int64_t request_satisfaction_offset
;
182 /* client http based routines */
183 char *clientConstructTraceEcho(ClientHttpRequest
*);
185 ACLFilledChecklist
*clientAclChecklistCreate(const acl_access
* acl
,ClientHttpRequest
* http
);
186 int clientHttpRequestStatus(int fd
, ClientHttpRequest
const *http
);
187 void clientAccessCheck(ClientHttpRequest
*);
189 /* ones that should be elsewhere */
190 void tunnelStart(ClientHttpRequest
*);
193 #include "client_side_request.cci"
197 #endif /* SQUID_CLIENTSIDEREQUEST_H */