]> git.ipfire.org Git - thirdparty/squid.git/blob - src/ICAP/ICAPClientRespmodPrecache.cc
- Replaced BodyReader with BodyPipe. BodyReader was a
[thirdparty/squid.git] / src / ICAP / ICAPClientRespmodPrecache.cc
1 #include "squid.h"
2 #include "http.h"
3 #include "MsgPipeData.h"
4 #include "HttpRequest.h"
5 #include "HttpReply.h"
6 #include "ICAPClientRespmodPrecache.h"
7 #include "ICAPClient.h"
8 #include "ICAPServiceRep.h"
9
10 CBDATA_CLASS_INIT(ICAPClientRespmodPrecache);
11
12 ICAPClientRespmodPrecache::ICAPClientRespmodPrecache(ICAPServiceRep::Pointer aService):
13 ICAPClientVector(aService, "ICAPClientRespmodPrecache"), serverState(NULL)
14 {
15 }
16
17 void ICAPClientRespmodPrecache::startRespMod(ServerStateData *aServerState, HttpRequest *request, HttpReply *reply)
18 {
19 serverState = cbdataReference(aServerState);
20 startMod(serverState, request, reply);
21 }
22
23 // ICAP client starts sending adapted response
24 // ICAP client has received new HTTP headers (if any) at this point
25 void ICAPClientRespmodPrecache::noteSourceStart(MsgPipe *p)
26 {
27 debugs(93,3, HERE << "ICAPClientRespmodPrecache::noteSourceStart() called");
28
29 HttpReply *reply = dynamic_cast<HttpReply*>(adapted->data->header);
30 /*
31 * The ICAP reply MUST have a new HTTP reply header, or else
32 * it is an invalid ICAP message. Invalid ICAP messages should
33 * be handled prior to this point.
34 */
35 assert(reply); // check that ICAP xaction created the right object
36 assert(reply == adapted->data->header);
37
38 /*
39 * Examine the HTTP reply headers to find out if there is an associated
40 * body. We should probably check the ICAP Encapsulated header values
41 * as well.
42 */
43 ssize_t dummy;
44 bool expect_body = reply->expectingBody(virgin->data->cause->method, dummy);
45
46 if (!serverState->takeAdaptedHeaders(reply)) // deletes us
47 return;
48
49 if (expect_body)
50 noteSourceProgress(p);
51 else
52 noteSourceFinish(p);
53 }
54
55 // ICAP client sends more data
56 void ICAPClientRespmodPrecache::noteSourceProgress(MsgPipe *p)
57 {
58 debug(93,3)("ICAPClientRespmodPrecache::noteSourceProgress() called\n");
59 //tell ServerStateData to store a fresh portion of the adapted response
60
61 assert(serverState);
62
63 if (p->data->body->hasContent()) {
64 if (!serverState->takeAdaptedBody(p->data->body))
65 return;
66
67 // HttpStateData::takeAdaptedBody does not detect when we have enough,
68 // so we always notify source that there more buffer space is available
69 if (p->data->body->hasPotentialSpace())
70 adapted->sendSinkNeed();
71 }
72 }
73
74 void
75 ICAPClientRespmodPrecache::tellSpaceAvailable()
76 {
77 serverState->icapSpaceAvailable();
78 }
79
80 void
81 ICAPClientRespmodPrecache::tellDoneAdapting()
82 {
83 serverState->finishAdapting(); // deletes us
84 }
85
86 void
87 ICAPClientRespmodPrecache::tellAbortAdapting()
88 {
89 debug(93,3)("ICAPClientReqmodPrecache::tellAbortAdapting() called\n");
90 // tell ClientHttpRequest that we are aborting ICAP processing prematurely
91 serverState->abortAdapting(); // deletes us
92 }
93