Client.h
Go to the documentation of this file.
1 /*
2  * Copyright (C) 1996-2022 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_SRC_CLIENTS_CLIENT_H
10 #define SQUID_SRC_CLIENTS_CLIENT_H
11 
12 #include "base/AsyncJob.h"
13 #include "BodyPipe.h"
14 #include "CommCalls.h"
15 #include "FwdState.h"
16 #include "http/forward.h"
17 #include "StoreIOBuffer.h"
18 #if USE_ADAPTATION
19 #include "adaptation/forward.h"
20 #include "adaptation/Initiator.h"
21 #endif
22 
29 class Client:
30 #if USE_ADAPTATION
31  public Adaptation::Initiator,
32  public BodyProducer,
33 #endif
34  public BodyConsumer
35 {
36 
37 public:
38  Client(FwdState *);
39  virtual ~Client();
40 
42  virtual const Comm::ConnectionPointer & dataConnection() const = 0;
43 
44  // BodyConsumer: consume request body or adapted response body.
45  // The implementation just calls the corresponding HTTP or ICAP handle*()
46  // method, depending on the pipe.
50 
52  virtual void maybeReadVirginBody() = 0;
53 
55  virtual void abortAll(const char *reason) = 0;
56 
60  virtual bool abortOnData(const char *reason);
61 
64 
65 #if USE_ADAPTATION
66  // Adaptation::Initiator API: start an ICAP transaction and receive adapted headers.
67  virtual void noteAdaptationAnswer(const Adaptation::Answer &answer);
69 
70  // BodyProducer: provide virgin response body to ICAP.
73 #endif
74  virtual bool getMoreRequestBody(MemBuf &buf);
75  virtual void processReplyBody() = 0;
76 
77 //AsyncJob virtual methods
78  virtual void swanSong();
79  virtual bool doneAll() const;
80 
81 public: // should be protected
82  void serverComplete();
84  void markParsedVirginReplyAsWhole(const char *reasonWeAreSure);
87 
88 private:
89  void serverComplete2();
90  bool completed = false;
92 protected:
93  // kids customize these
94  virtual void haveParsedReplyHeaders();
95  virtual void completeForwarding();
97  // BodyConsumer for HTTP: consume request body.
98  bool startRequestBodyFlow();
101  virtual void handleRequestBodyProducerAborted() = 0;
102 
103  // sending of the request body to the server
104  void sendMoreRequestBody();
105  // has body; kids overwrite to increment I/O stats counters
106  virtual void sentRequestBody(const CommIoCbParams &io) = 0;
107  virtual void doneSendingRequestBody() = 0;
108 
111  virtual void closeServer() = 0;
112  virtual bool doneWithServer() const = 0;
113  virtual bool mayReadVirginReplyBody() const = 0;
115 
118  virtual void noteDelayAwareReadChance() = 0;
119 
121  bool abortOnBadEntry(const char *abortReason);
122 
123  bool blockCaching();
124 
125 #if USE_ADAPTATION
127  void adaptVirginReplyBody(const char *buf, ssize_t len);
128  void cleanAdaptation();
129  virtual bool doneWithAdaptation() const;
131  // BodyConsumer for ICAP: consume adapted response body.
135 
138  void handleAdaptationBlocked(const Adaptation::Answer &answer);
139  void handleAdaptationAborted(bool bypassable = false);
141 
143  void resumeBodyStorage();
146 #endif
147 
148 protected:
149  const HttpReply *virginReply() const;
152 
155 
156  // Kids use these to stuff data into the response instead of messing with the entry directly
157  void adaptOrFinalizeReply();
158  void addVirginReplyBody(const char *buf, ssize_t len);
159  void storeReplyBody(const char *buf, ssize_t len);
161  size_t replyBodySpace(const MemBuf &readBuf, const size_t minSpace) const;
163  size_t calcBufferSpaceToReserve(const size_t space, const size_t wantSpace) const;
164 
165  void adjustBodyBytesRead(const int64_t delta);
166 
169  void delayRead();
170 
171  // These should be private
172  int64_t currentOffset = 0;
175 public: // should not be
176  StoreEntry *entry = nullptr;
179 
180 protected:
184 #if USE_ADAPTATION
190  bool startedAdaptation = false;
191 
194 #endif
196 
199  const char *doneWithFwd = nullptr;
200 
201 private:
203  void maybePurgeOthers();
204 
207 };
208 
209 #endif /* SQUID_SRC_CLIENTS_CLIENT_H */
210 
virtual void noteMoreBodyDataAvailable(BodyPipe::Pointer)
Definition: Client.cc:270
void handleMoreRequestBodyAvailable()
Definition: Client.cc:319
void storeReplyBody(const char *buf, ssize_t len)
Definition: Client.cc:1054
HttpReply * theVirginReply
Definition: Client.h:205
virtual bool getMoreRequestBody(MemBuf &buf)
either fill buf with available [encoded] request body bytes or return false
Definition: Client.cc:438
StoreEntry * entry
Definition: Client.h:176
void delayRead()
Definition: Client.cc:1029
common parts of HttpRequest and HttpReply
Definition: Message.h:26
Definition: Client.h:35
void endAdaptedBodyConsumption()
called when the entire adapted response body is consumed
Definition: Client.cc:830
void adaptVirginReplyBody(const char *buf, ssize_t len)
Definition: Client.cc:629
virtual void swanSong()
Definition: Client.cc:68
bool completed
Definition: Client.h:90
AsyncCall::Pointer requestSender
Definition: Client.h:182
Client(FwdState *)
Definition: Client.cc:38
void handleAdaptationCompleted()
Definition: Client.cc:866
virtual void handleRequestBodyProducerAborted()=0
Definition: Client.cc:351
virtual void abortAll(const char *reason)=0
abnormal transaction termination; reason is for debugging only
void maybePurgeOthers()
Definition: Client.cc:516
void serverComplete2()
Definition: Client.cc:202
BodyPipe::Pointer requestBodySource
Definition: Client.h:181
virtual void noteBodyConsumerAborted(BodyPipe::Pointer)
Definition: Client.cc:685
virtual const Comm::ConnectionPointer & dataConnection() const =0
void cleanAdaptation()
Definition: Client.cc:604
void adjustBodyBytesRead(const int64_t delta)
initializes bodyBytesRead stats if needed and applies delta
Definition: Client.cc:1014
virtual void noteMoreBodySpaceAvailable(BodyPipe::Pointer)
Definition: Client.cc:671
void adaptOrFinalizeReply()
Definition: Client.cc:996
MemBuf * responseBodyBuffer
Definition: Client.h:173
virtual void noteBodyProductionEnded(BodyPipe::Pointer)
Definition: Client.cc:284
BodyPipe::Pointer virginBodyDestination
Definition: Client.h:185
bool startRequestBodyFlow()
Definition: Client.cc:239
virtual void haveParsedReplyHeaders()
called when we have final (possibly adapted) reply headers; kids extend
Definition: Client.cc:537
int64_t currentOffset
Definition: Client.h:172
virtual bool mayReadVirginReplyBody() const =0
whether we may receive more virgin response body bytes
virtual void noteAdaptationAclCheckDone(Adaptation::ServiceGroupPointer group)
Definition: Client.cc:957
void serverComplete()
Definition: Client.cc:180
virtual void completeForwarding()
Definition: Client.cc:230
void handleMoreAdaptedBodyAvailable()
Definition: Client.cc:768
void handleAdaptedHeader(Http::Message *msg)
Definition: Client.cc:717
virtual void doneSendingRequestBody()=0
Definition: Client.cc:340
void resumeBodyStorage()
called by StoreEntry when it has more buffer space available
Definition: Client.cc:752
const HttpReply * virginReply() const
Definition: Client.cc:109
HttpReply * theFinalReply
Definition: Client.h:206
bool blockCaching()
whether to prevent caching of an otherwise cachable response
Definition: Client.cc:552
virtual void noteBodyProducerAborted(BodyPipe::Pointer)
Definition: Client.cc:298
virtual void noteAdaptationAnswer(const Adaptation::Answer &answer)
Definition: Client.cc:697
virtual void processReplyBody()=0
Definition: MemBuf.h:24
void handleAdaptedBodyProducerAborted()
Definition: Client.cc:845
virtual ~Client()
Definition: Client.cc:47
void sendMoreRequestBody()
Definition: Client.cc:412
FwdState::Pointer fwd
Definition: Client.h:177
bool handledEarlyAdaptationAbort()
Definition: Client.cc:901
HttpReply * setFinalReply(HttpReply *r)
Definition: Client.cc:136
virtual HttpRequestPointer originalRequest()
a hack to reach HttpStateData::orignal_request
Definition: Client.cc:570
bool adaptationAccessCheckPending
Definition: Client.h:189
HttpReply * setVirginReply(HttpReply *r)
Definition: Client.cc:116
bool receivedWholeRequestBody
handleRequestBodyProductionEnded called
Definition: Client.h:195
HttpReply * finalReply()
Definition: Client.cc:129
virtual void noteDelayAwareReadChance()=0
bool abortOnBadEntry(const char *abortReason)
Entry-dependent callbacks use this check to quit if the entry went bad.
Definition: Client.cc:258
summarizes adaptation service answer for the noteAdaptationAnswer() API
Definition: Answer.h:23
void markParsedVirginReplyAsWhole(const char *reasonWeAreSure)
Definition: Client.cc:158
BodyPipe::Pointer adaptedBodySource
Definition: Client.h:187
virtual bool doneAll() const
whether positive goal has been reached
Definition: Client.cc:217
virtual bool doneWithAdaptation() const
Definition: Client.cc:621
void sendBodyIsTooLargeError()
Definition: Client.cc:985
size_t calcBufferSpaceToReserve(const size_t space, const size_t wantSpace) const
determine how much space the buffer needs to reserve
Definition: Client.cc:1063
void startAdaptation(const Adaptation::ServiceGroupPointer &group, HttpRequest *cause)
Initiate an asynchronous adaptation transaction which will call us back.
Definition: Client.cc:578
void handleAdaptationAborted(bool bypassable=false)
Definition: Client.cc:885
void addVirginReplyBody(const char *buf, ssize_t len)
Definition: Client.cc:1038
const char * doneWithFwd
Definition: Client.h:199
virtual void sentRequestBody(const CommIoCbParams &io)=0
Definition: Client.cc:364
void handleRequestBodyProductionEnded()
Definition: Client.cc:329
virtual void maybeReadVirginBody()=0
read response data from the network
virtual void closeServer()=0
virtual bool abortOnData(const char *reason)
Definition: Client.cc:311
void handleAdaptedBodyProductionEnded()
Definition: Client.cc:815
bool startedAdaptation
Definition: Client.h:190
bool receivedWholeAdaptedReply
handleAdaptedBodyProductionEnded() was called
Definition: Client.h:193
CbcPointer< Adaptation::Initiate > adaptedHeadSource
Definition: Client.h:186
size_t replyBodySpace(const MemBuf &readBuf, const size_t minSpace) const
Definition: Client.cc:1098
void handleAdaptationBlocked(const Adaptation::Answer &answer)
Definition: Client.cc:924
HttpRequestPointer request
Definition: Client.h:178
virtual bool doneWithServer() const =0

 

Introduction

Documentation

Support

Miscellaneous

Web Site Translations

Mirrors