Client.h
Go to the documentation of this file.
1 /*
2  * Copyright (C) 1996-2017 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 private:
85  void serverComplete2();
86  bool completed = false;
88 protected:
89  // kids customize these
90  virtual void haveParsedReplyHeaders();
91  virtual void completeForwarding();
93  // BodyConsumer for HTTP: consume request body.
94  bool startRequestBodyFlow();
97  virtual void handleRequestBodyProducerAborted() = 0;
98 
99  // sending of the request body to the server
100  void sendMoreRequestBody();
101  // has body; kids overwrite to increment I/O stats counters
102  virtual void sentRequestBody(const CommIoCbParams &io) = 0;
103  virtual void doneSendingRequestBody() = 0;
104 
107  virtual void closeServer() = 0;
108  virtual bool doneWithServer() const = 0;
109  virtual bool mayReadVirginReplyBody() const = 0;
111 
113  bool abortOnBadEntry(const char *abortReason);
114 
115  bool blockCaching();
116 
117 #if USE_ADAPTATION
119  void adaptVirginReplyBody(const char *buf, ssize_t len);
120  void cleanAdaptation();
121  virtual bool doneWithAdaptation() const;
123  // BodyConsumer for ICAP: consume adapted response body.
127 
130  void handleAdaptationBlocked(const Adaptation::Answer &answer);
131  void handleAdaptationAborted(bool bypassable = false);
133 
135  void resumeBodyStorage();
138 #endif
139 
140 protected:
141  const HttpReply *virginReply() const;
144 
147 
148  // Kids use these to stuff data into the response instead of messing with the entry directly
149  void adaptOrFinalizeReply();
150  void addVirginReplyBody(const char *buf, ssize_t len);
151  void storeReplyBody(const char *buf, ssize_t len);
153  size_t replyBodySpace(const MemBuf &readBuf, const size_t minSpace) const;
155  size_t calcBufferSpaceToReserve(const size_t space, const size_t wantSpace) const;
156 
157  void adjustBodyBytesRead(const int64_t delta);
158 
159  // These should be private
160  int64_t currentOffset = 0;
163 public: // should not be
164  StoreEntry *entry = nullptr;
167 
168 protected:
172 #if USE_ADAPTATION
178  bool startedAdaptation = false;
179 #endif
181 
184  const char *doneWithFwd = nullptr;
185 
186 private:
188  void maybePurgeOthers();
189 
192 };
193 
194 #endif /* SQUID_SRC_CLIENTS_CLIENT_H */
195 
summarizes adaptation service answer for the noteAdaptationAnswer() API
Definition: Answer.h:22
bool startedAdaptation
Definition: Client.h:178
MemBuf * responseBodyBuffer
Definition: Client.h:161
void handleRequestBodyProductionEnded()
Definition: Client.cc:306
virtual const Comm::ConnectionPointer & dataConnection() const =0
void handleAdaptationBlocked(const Adaptation::Answer &answer)
Definition: Client.cc:876
bool startRequestBodyFlow()
Definition: Client.cc:216
virtual bool abortOnData(const char *reason)
Definition: Client.cc:288
size_t calcBufferSpaceToReserve(const size_t space, const size_t wantSpace) const
determine how much space the buffer needs to reserve
Definition: Client.cc:1003
void adaptOrFinalizeReply()
Definition: Client.cc:945
virtual bool getMoreRequestBody(MemBuf &buf)
either fill buf with available [encoded] request body bytes or return false
Definition: Client.cc:415
virtual void noteMoreBodySpaceAvailable(BodyPipe::Pointer)
Definition: Client.cc:637
void handleMoreRequestBodyAvailable()
Definition: Client.cc:296
const HttpReply * virginReply() const
Definition: Client.cc:111
void serverComplete()
Definition: Client.cc:157
void handleMoreAdaptedBodyAvailable()
Definition: Client.cc:733
StoreEntry * entry
Definition: Client.h:164
void storeReplyBody(const char *buf, ssize_t len)
Definition: Client.cc:994
Definition: Client.h:29
virtual void noteAdaptationAclCheckDone(Adaptation::ServiceGroupPointer group)
Definition: Client.cc:906
void handleAdaptedHeader(Http::Message *msg)
Definition: Client.cc:683
virtual bool doneWithServer() const =0
virtual void noteAdaptationAnswer(const Adaptation::Answer &answer)
Definition: Client.cc:663
virtual void processReplyBody()=0
virtual ~Client()
Definition: Client.cc:49
HttpReply * theVirginReply
Definition: Client.h:190
void resumeBodyStorage()
called by StoreEntry when it has more buffer space available
Definition: Client.cc:717
void maybePurgeOthers()
Definition: Client.cc:486
virtual void noteBodyProducerAborted(BodyPipe::Pointer)
Definition: Client.cc:275
void sendMoreRequestBody()
Definition: Client.cc:389
AsyncCall::Pointer requestSender
Definition: Client.h:170
void sendBodyIsTooLargeError()
Definition: Client.cc:934
Client(FwdState *)
Definition: Client.cc:40
void handleAdaptedBodyProducerAborted()
Definition: Client.cc:799
virtual void noteBodyProductionEnded(BodyPipe::Pointer)
Definition: Client.cc:261
virtual void abortAll(const char *reason)=0
abnormal transaction termination; reason is for debugging only
BodyPipe::Pointer virginBodyDestination
Definition: Client.h:173
virtual void noteBodyConsumerAborted(BodyPipe::Pointer)
Definition: Client.cc:651
virtual void haveParsedReplyHeaders()
called when we have final (possibly adapted) reply headers; kids extend
Definition: Client.cc:507
FwdState::Pointer fwd
Definition: Client.h:165
void serverComplete2()
Definition: Client.cc:179
virtual void handleRequestBodyProducerAborted()=0
Definition: Client.cc:328
bool handledEarlyAdaptationAbort()
Definition: Client.cc:856
void startAdaptation(const Adaptation::ServiceGroupPointer &group, HttpRequest *cause)
Initiate an asynchronous adaptation transaction which will call us back.
Definition: Client.cc:544
virtual void sentRequestBody(const CommIoCbParams &io)=0
Definition: Client.cc:341
BodyPipe::Pointer requestBodySource
Definition: Client.h:169
virtual HttpRequestPointer originalRequest()
a hack to reach HttpStateData::orignal_request
Definition: Client.cc:536
virtual bool doneAll() const
whether positive goal has been reached
Definition: Client.cc:194
common parts of HttpRequest and HttpReply
Definition: Message.h:24
void adjustBodyBytesRead(const int64_t delta)
initializes bodyBytesRead stats if needed and applies delta
Definition: Client.cc:963
void cleanAdaptation()
Definition: Client.cc:570
virtual bool mayReadVirginReplyBody() const =0
whether we may receive more virgin response body bytes
virtual void completeForwarding()
Definition: Client.cc:207
bool blockCaching()
whether to prevent caching of an otherwise cachable response
Definition: Client.cc:519
virtual void closeServer()=0
virtual void maybeReadVirginBody()=0
read response data from the network
int64_t currentOffset
Definition: Client.h:160
void handleAdaptedBodyProductionEnded()
Definition: Client.cc:780
void addVirginReplyBody(const char *buf, ssize_t len)
Definition: Client.cc:978
int unsigned int const char *desc STUB void int len
Definition: stub_fd.cc:20
void const char * buf
Definition: stub_helper.cc:16
virtual void doneSendingRequestBody()=0
Definition: Client.cc:317
HttpRequestPointer request
Definition: Client.h:166
HttpReply * theFinalReply
Definition: Client.h:191
HttpReply * setVirginReply(HttpReply *r)
Definition: Client.cc:118
HttpReply * setFinalReply(HttpReply *r)
Definition: Client.cc:136
bool receivedWholeRequestBody
handleRequestBodyProductionEnded called
Definition: Client.h:180
Definition: MemBuf.h:23
void adaptVirginReplyBody(const char *buf, ssize_t len)
Definition: Client.cc:595
BodyPipe::Pointer adaptedBodySource
Definition: Client.h:175
CbcPointer< Adaptation::Initiate > adaptedHeadSource
Definition: Client.h:174
bool adaptationAccessCheckPending
Definition: Client.h:177
virtual void swanSong()
Definition: Client.cc:70
void handleAdaptationCompleted()
Definition: Client.cc:821
size_t replyBodySpace(const MemBuf &readBuf, const size_t minSpace) const
Definition: Client.cc:1038
virtual void noteMoreBodyDataAvailable(BodyPipe::Pointer)
Definition: Client.cc:247
bool abortOnBadEntry(const char *abortReason)
Entry-dependent callbacks use this check to quit if the entry went bad.
Definition: Client.cc:235
HttpReply * finalReply()
Definition: Client.cc:129
virtual bool doneWithAdaptation() const
Definition: Client.cc:587
void endAdaptedBodyConsumption()
called when the entire adapted response body is consumed
Definition: Client.cc:792
const char * doneWithFwd
Definition: Client.h:184
void handleAdaptationAborted(bool bypassable=false)
Definition: Client.cc:840
bool completed
Definition: Client.h:86

 

Introduction

Documentation

Support

Miscellaneous

Web Site Translations

Mirrors