2 * Copyright (C) 1996-2018 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 "http/forward.h"
17 #include "HttpHeaderRange.h"
22 #include "adaptation/forward.h"
23 #include "adaptation/Initiator.h"
26 class ClientRequestContext
;
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
&);
33 class ClientHttpRequest
35 : public Adaptation::Initiator
, // to start adaptation transactions
36 public BodyConsumer
// to receive reply bodies in request satisf. mode
39 CBDATA_CLASS(ClientHttpRequest
);
42 ClientHttpRequest(ConnStateData
*csd
);
44 /* Not implemented - present to prevent synthetic operations */
45 ClientHttpRequest(ClientHttpRequest
const &);
46 ClientHttpRequest
& operator=(ClientHttpRequest
const &);
48 String
rangeBoundaryStr() const;
50 void updateCounters();
52 MemObject
* memObject() const {
53 return (storeEntry() ? storeEntry()->mem_obj
: nullptr);
55 bool multipartRangeRequest() const;
56 void processRequest();
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
*);
65 ConnStateData
* getConn() const {
66 return (cbdataReferenceValid(conn_
) ? conn_
: nullptr);
68 void setConn(ConnStateData
*aConn
) {
70 cbdataReferenceDone(conn_
);
71 conn_
= cbdataReference(aConn
);
75 /** Details of the client socket which produced us.
76 * Treat as read-only for the lifetime of this HTTP request.
78 Comm::ConnectionPointer clientConnection
;
80 HttpRequest
*request
; /* Parsed URL ... */
83 String store_id
; /* StoreID for transactions where the request member is nil */
86 Out() : offset(0), size(0), headers_sz(0) {}
93 HttpHdrRangeIter range_iter
; /* data for iterating thru range specs */
94 size_t req_sz
; /* raw request size on input, not current request size */
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.
100 AccessLogEntry::Pointer al
; ///< access.log entry
103 Flags() : accel(false), internal(false), done_copying(false), purging(false) {}
112 Redirect() : status(Http::scNone
), location(NULL
) {}
114 Http::StatusCode status
;
119 dlink_list client_stream
;
122 ClientRequestContext
*calloutContext
;
125 /// Build an error reply. For use with the callouts.
126 void calloutsError(const err_type error
, const int errDetail
);
129 // AsyncJob virtual methods
130 virtual bool doneAll() const {
131 return Initiator::doneAll() &&
132 BodyConsumer::doneAll() && false;
134 virtual void callException(const std::exception
&ex
);
138 int64_t maxReplyBodySize_
;
140 StoreEntry
*loggingEntry_
;
141 ConnStateData
* conn_
;
144 /// whether (and how) the request needs to be bumped
145 Ssl::BumpMode sslBumpNeed_
;
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
);
155 void sslBumpEstablish(Comm::Flag errflag
);
161 void startAdaptation(const Adaptation::ServiceGroupPointer
&g
);
162 bool requestSatisfactionMode() const { return request_satisfaction_mode
; }
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);
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
);
175 // BodyConsumer API, called by BodyPipe
176 virtual void noteMoreBodyDataAvailable(BodyPipe::Pointer
);
177 virtual void noteBodyProductionEnded(BodyPipe::Pointer
);
178 virtual void noteBodyProducerAborted(BodyPipe::Pointer
);
180 void endRequestSatisfaction();
181 /// called by StoreEntry when it has more buffer space available
182 void resumeBodyStorage();
185 CbcPointer
<Adaptation::Initiate
> virginHeadSource
;
186 BodyPipe::Pointer adaptedBodySource
;
188 bool request_satisfaction_mode
;
189 int64_t request_satisfaction_offset
;
193 /* client http based routines */
194 char *clientConstructTraceEcho(ClientHttpRequest
*);
196 ACLFilledChecklist
*clientAclChecklistCreate(const acl_access
* acl
,ClientHttpRequest
* http
);
197 int clientHttpRequestStatus(int fd
, ClientHttpRequest
const *http
);
198 void clientAccessCheck(ClientHttpRequest
*);
200 /* ones that should be elsewhere */
201 void tunnelStart(ClientHttpRequest
*);
203 #endif /* SQUID_CLIENTSIDEREQUEST_H */