5 * AUTHOR: Duane Wessels
7 * SQUID Web Proxy Cache http://www.squid-cache.org/
8 * ----------------------------------------------------------
10 * Squid is the result of efforts by numerous individuals from
11 * the Internet community; see the CONTRIBUTORS file for full
12 * details. Many organizations have provided support for Squid's
13 * development; see the SPONSORS file for full details. Squid is
14 * Copyrighted (C) 2001 by the Regents of the University of
15 * California; see the COPYRIGHT file for full details. Squid
16 * incorporates software developed and/or copyrighted by other
17 * sources; see the CREDITS file for full details.
19 * This program is free software; you can redistribute it and/or modify
20 * it under the terms of the GNU General Public License as published by
21 * the Free Software Foundation; either version 2 of the License, or
22 * (at your option) any later version.
24 * This program is distributed in the hope that it will be useful,
25 * but WITHOUT ANY WARRANTY; without even the implied warranty of
26 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
27 * GNU General Public License for more details.
29 * You should have received a copy of the GNU General Public License
30 * along with this program; if not, write to the Free Software
31 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111, USA.
36 #include "base/TextException.h"
37 #include "comm/Connection.h"
38 #include "comm/forward.h"
41 //#include "fde.h" /* for fd_table[fd].closing */
42 #include "HttpRequest.h"
43 #include "HttpReply.h"
44 #include "errorpage.h"
45 #include "err_detail_type.h"
46 #include "SquidTime.h"
49 #include "adaptation/AccessCheck.h"
50 #include "adaptation/Iterator.h"
53 // implemented in client_side_reply.cc until sides have a common parent
54 extern void purgeEntriesByUrl(HttpRequest
* req
, const char *url
);
57 ServerStateData::ServerStateData(FwdState
*theFwdState
): AsyncJob("ServerStateData"),
60 adaptedHeadSource(NULL
),
61 adaptationAccessCheckPending(false),
62 startedAdaptation(false),
64 receivedWholeRequestBody(false)
71 request
= HTTPMSGLOCK(fwd
->request
);
74 ServerStateData::~ServerStateData()
76 // paranoid: check that swanSong has been called
77 assert(!requestBodySource
);
79 assert(!virginBodyDestination
);
80 assert(!adaptedBodySource
);
85 HTTPMSGUNLOCK(request
);
86 HTTPMSGUNLOCK(theVirginReply
);
87 HTTPMSGUNLOCK(theFinalReply
);
89 fwd
= NULL
; // refcounted
91 if (responseBodyBuffer
!= NULL
) {
92 delete responseBodyBuffer
;
93 responseBodyBuffer
= NULL
;
98 ServerStateData::swanSong()
100 // get rid of our piping obligations
101 if (requestBodySource
!= NULL
)
102 stopConsumingFrom(requestBodySource
);
108 BodyConsumer::swanSong();
110 Initiator::swanSong();
111 BodyProducer::swanSong();
114 // paranoid: check that swanSong has been called
115 // extra paranoid: yeah, I really mean it. they MUST pass here.
116 assert(!requestBodySource
);
118 assert(!virginBodyDestination
);
119 assert(!adaptedBodySource
);
125 ServerStateData::virginReply()
127 assert(theVirginReply
);
128 return theVirginReply
;
132 ServerStateData::virginReply() const
134 assert(theVirginReply
);
135 return theVirginReply
;
139 ServerStateData::setVirginReply(HttpReply
*rep
)
141 debugs(11,5, HERE
<< this << " setting virgin reply to " << rep
);
142 assert(!theVirginReply
);
144 theVirginReply
= HTTPMSGLOCK(rep
);
145 return theVirginReply
;
149 ServerStateData::finalReply()
151 assert(theFinalReply
);
152 return theFinalReply
;
156 ServerStateData::setFinalReply(HttpReply
*rep
)
158 debugs(11,5, HERE
<< this << " setting final reply to " << rep
);
160 assert(!theFinalReply
);
162 theFinalReply
= HTTPMSGLOCK(rep
);
164 entry
->replaceHttpReply(theFinalReply
);
165 haveParsedReplyHeaders();
167 return theFinalReply
;
170 // called when no more server communication is expected; may quit
172 ServerStateData::serverComplete()
174 debugs(11,5,HERE
<< "serverComplete " << this);
176 if (!doneWithServer()) {
178 assert(doneWithServer());
183 HttpRequest
*r
= originalRequest();
184 r
->hier
.total_response_time
= r
->hier
.first_conn_start
.tv_sec
?
185 tvSubMsec(r
->hier
.first_conn_start
, current_time
) : -1;
187 if (requestBodySource
!= NULL
)
188 stopConsumingFrom(requestBodySource
);
190 if (responseBodyBuffer
!= NULL
)
197 ServerStateData::serverComplete2()
199 debugs(11,5,HERE
<< "serverComplete2 " << this);
202 if (virginBodyDestination
!= NULL
)
203 stopProducingFor(virginBodyDestination
, true);
205 if (!doneWithAdaptation())
209 completeForwarding();
213 // When we are done talking to the primary server, we may be still talking
214 // to the ICAP service. And vice versa. Here, we quit only if we are done
216 void ServerStateData::quitIfAllDone()
219 if (!doneWithAdaptation()) {
220 debugs(11,5, HERE
<< "transaction not done: still talking to ICAP");
225 if (!doneWithServer()) {
226 debugs(11,5, HERE
<< "transaction not done: still talking to server");
230 debugs(11,3, HERE
<< "transaction done");
232 deleteThis("ServerStateData::quitIfAllDone");
235 // FTP side overloads this to work around multiple calls to fwd->complete
237 ServerStateData::completeForwarding()
239 debugs(11,5, HERE
<< "completing forwarding for " << fwd
);
244 // Register to receive request body
245 bool ServerStateData::startRequestBodyFlow()
247 HttpRequest
*r
= originalRequest();
248 assert(r
->body_pipe
!= NULL
);
249 requestBodySource
= r
->body_pipe
;
250 if (requestBodySource
->setConsumerIfNotLate(this)) {
251 debugs(11,3, HERE
<< "expecting request body from " <<
252 requestBodySource
->status());
256 debugs(11,3, HERE
<< "aborting on partially consumed request body: " <<
257 requestBodySource
->status());
258 requestBodySource
= NULL
;
262 // Entry-dependent callbacks use this check to quit if the entry went bad
264 ServerStateData::abortOnBadEntry(const char *abortReason
)
266 if (entry
->isAccepting())
269 debugs(11,5, HERE
<< "entry is not Accepting!");
270 abortTransaction(abortReason
);
274 // more request or adapted response body is available
276 ServerStateData::noteMoreBodyDataAvailable(BodyPipe::Pointer bp
)
279 if (adaptedBodySource
== bp
) {
280 handleMoreAdaptedBodyAvailable();
284 handleMoreRequestBodyAvailable();
287 // the entire request or adapted response body was provided, successfully
289 ServerStateData::noteBodyProductionEnded(BodyPipe::Pointer bp
)
292 if (adaptedBodySource
== bp
) {
293 handleAdaptedBodyProductionEnded();
297 handleRequestBodyProductionEnded();
300 // premature end of the request or adapted response body production
302 ServerStateData::noteBodyProducerAborted(BodyPipe::Pointer bp
)
305 if (adaptedBodySource
== bp
) {
306 handleAdaptedBodyProducerAborted();
310 handleRequestBodyProducerAborted();
314 // more origin request body data is available
316 ServerStateData::handleMoreRequestBodyAvailable()
319 sendMoreRequestBody();
321 debugs(9,3, HERE
<< "waiting for request body write to complete");
324 // there will be no more handleMoreRequestBodyAvailable calls
326 ServerStateData::handleRequestBodyProductionEnded()
328 receivedWholeRequestBody
= true;
330 doneSendingRequestBody();
332 debugs(9,3, HERE
<< "waiting for request body write to complete");
335 // called when we are done sending request body; kids extend this
337 ServerStateData::doneSendingRequestBody()
339 debugs(9,3, HERE
<< "done sending request body");
340 assert(requestBodySource
!= NULL
);
341 stopConsumingFrom(requestBodySource
);
346 // called when body producers aborts; kids extend this
348 ServerStateData::handleRequestBodyProducerAborted()
350 if (requestSender
!= NULL
)
351 debugs(9,3, HERE
<< "fyi: request body aborted while we were sending");
353 fwd
->dontRetry(true); // the problem is not with the server
354 stopConsumingFrom(requestBodySource
); // requestSender, if any, will notice
359 // called when we wrote request headers(!) or a part of the body
361 ServerStateData::sentRequestBody(const CommIoCbParams
&io
)
363 debugs(11, 5, "sentRequestBody: FD " << io
.fd
<< ": size " << io
.size
<< ": errflag " << io
.flag
<< ".");
364 debugs(32,3,HERE
<< "sentRequestBody called");
366 requestSender
= NULL
;
369 fd_bytes(io
.fd
, io
.size
, FD_WRITE
);
370 kb_incr(&statCounter
.server
.all
.kbytes_out
, io
.size
);
371 // kids should increment their counters
374 if (io
.flag
== COMM_ERR_CLOSING
)
377 if (!requestBodySource
) {
378 debugs(9,3, HERE
<< "detected while-we-were-sending abort");
379 return; // do nothing;
383 debugs(11, 1, "sentRequestBody error: FD " << io
.fd
<< ": " << xstrerr(errno
));
385 err
= errorCon(ERR_WRITE_ERROR
, HTTP_BAD_GATEWAY
, fwd
->request
);
388 abortTransaction("I/O error while sending request body");
392 if (EBIT_TEST(entry
->flags
, ENTRY_ABORTED
)) {
393 abortTransaction("store entry aborted while sending request body");
397 if (!requestBodySource
->exhausted())
398 sendMoreRequestBody();
399 else if (receivedWholeRequestBody
)
400 doneSendingRequestBody();
402 debugs(9,3, HERE
<< "waiting for body production end or abort");
406 ServerStateData::sendMoreRequestBody()
408 assert(requestBodySource
!= NULL
);
409 assert(!requestSender
);
411 const Comm::ConnectionPointer conn
= dataDescriptor();
413 if (!Comm::IsConnOpen(conn
)) {
414 debugs(9,3, HERE
<< "cannot send request body to closing " << conn
);
415 return; // wait for the kid's close handler; TODO: assert(closer);
419 if (getMoreRequestBody(buf
) && buf
.contentSize() > 0) {
420 debugs(9,3, HERE
<< "will write " << buf
.contentSize() << " request body bytes");
421 typedef CommCbMemFunT
<ServerStateData
, CommIoCbParams
> Dialer
;
422 requestSender
= JobCallback(93,3, Dialer
, this, ServerStateData::sentRequestBody
);
423 comm_write_mbuf(conn
, &buf
, requestSender
);
425 debugs(9,3, HERE
<< "will wait for more request body bytes or eof");
426 requestSender
= NULL
;
430 /// either fill buf with available [encoded] request body bytes or return false
432 ServerStateData::getMoreRequestBody(MemBuf
&buf
)
434 // default implementation does not encode request body content
435 Must(requestBodySource
!= NULL
);
436 return requestBodySource
->getMoreData(buf
);
439 // Compares hosts in urls, returns false if different, no sheme, or no host.
441 sameUrlHosts(const char *url1
, const char *url2
)
443 // XXX: Want urlHostname() here, but it uses static storage and copying
444 const char *host1
= strchr(url1
, ':');
445 const char *host2
= strchr(url2
, ':');
447 if (host1
&& host2
) {
448 // skip scheme slashes
452 } while (*host1
== '/' && *host2
== '/');
455 return false; // no host
457 // increment while the same until we reach the end of the URL/host
458 while (*host1
&& *host1
!= '/' && *host1
== *host2
) {
462 return *host1
== *host2
;
465 return false; // no URL scheme
468 // purges entries that match the value of a given HTTP [response] header
470 purgeEntriesByHeader(HttpRequest
*req
, const char *reqUrl
, HttpMsg
*rep
, http_hdr_type hdr
)
472 const char *hdrUrl
, *absUrl
;
475 hdrUrl
= rep
->header
.getStr(hdr
);
476 if (hdrUrl
== NULL
) {
481 * If the URL is relative, make it absolute so we can find it.
482 * If it's absolute, make sure the host parts match to avoid DOS attacks
483 * as per RFC 2616 13.10.
485 if (urlIsRelative(hdrUrl
)) {
486 absUrl
= urlMakeAbsolute(req
, hdrUrl
);
487 if (absUrl
!= NULL
) {
490 } else if (!sameUrlHosts(reqUrl
, hdrUrl
)) {
494 purgeEntriesByUrl(req
, hdrUrl
);
496 if (absUrl
!= NULL
) {
501 // some HTTP methods should purge matching cache entries
503 ServerStateData::maybePurgeOthers()
505 // only some HTTP methods should purge matching cache entries
506 if (!request
->method
.purgesOthers())
509 // and probably only if the response was successful
510 if (theFinalReply
->sline
.status
>= 400)
513 // XXX: should we use originalRequest() here?
514 const char *reqUrl
= urlCanonical(request
);
515 debugs(88, 5, "maybe purging due to " << RequestMethodStr(request
->method
) << ' ' << reqUrl
);
516 purgeEntriesByUrl(request
, reqUrl
);
517 purgeEntriesByHeader(request
, reqUrl
, theFinalReply
, HDR_LOCATION
);
518 purgeEntriesByHeader(request
, reqUrl
, theFinalReply
, HDR_CONTENT_LOCATION
);
521 // called (usually by kids) when we have final (possibly adapted) reply headers
523 ServerStateData::haveParsedReplyHeaders()
530 ServerStateData::originalRequest()
536 /// Initiate an asynchronous adaptation transaction which will call us back.
538 ServerStateData::startAdaptation(const Adaptation::ServiceGroupPointer
&group
, HttpRequest
*cause
)
540 debugs(11, 5, "ServerStateData::startAdaptation() called");
541 // check whether we should be sending a body as well
542 // start body pipe to feed ICAP transaction if needed
543 assert(!virginBodyDestination
);
544 HttpReply
*vrep
= virginReply();
545 assert(!vrep
->body_pipe
);
547 if (vrep
->expectingBody(cause
->method
, size
) && size
) {
548 virginBodyDestination
= new BodyPipe(this);
549 vrep
->body_pipe
= virginBodyDestination
;
550 debugs(93, 6, HERE
<< "will send virgin reply body to " <<
551 virginBodyDestination
<< "; size: " << size
);
553 virginBodyDestination
->setBodySize(size
);
556 adaptedHeadSource
= initiateAdaptation(
557 new Adaptation::Iterator(vrep
, cause
, group
));
558 startedAdaptation
= initiated(adaptedHeadSource
);
559 Must(startedAdaptation
);
562 // properly cleans up ICAP-related state
563 // may be called multiple times
564 void ServerStateData::cleanAdaptation()
566 debugs(11,5, HERE
<< "cleaning ICAP; ACL: " << adaptationAccessCheckPending
);
568 if (virginBodyDestination
!= NULL
)
569 stopProducingFor(virginBodyDestination
, false);
571 announceInitiatorAbort(adaptedHeadSource
);
573 if (adaptedBodySource
!= NULL
)
574 stopConsumingFrom(adaptedBodySource
);
576 if (!adaptationAccessCheckPending
) // we cannot cancel a pending callback
577 assert(doneWithAdaptation()); // make sure the two methods are in sync
581 ServerStateData::doneWithAdaptation() const
583 return !adaptationAccessCheckPending
&&
584 !virginBodyDestination
&& !adaptedHeadSource
&& !adaptedBodySource
;
587 // sends virgin reply body to ICAP, buffering excesses if needed
589 ServerStateData::adaptVirginReplyBody(const char *data
, ssize_t len
)
591 assert(startedAdaptation
);
593 if (!virginBodyDestination
) {
594 debugs(11,3, HERE
<< "ICAP does not want more virgin body");
598 // grow overflow area if already overflowed
599 if (responseBodyBuffer
) {
600 responseBodyBuffer
->append(data
, len
);
601 data
= responseBodyBuffer
->content();
602 len
= responseBodyBuffer
->contentSize();
605 const ssize_t putSize
= virginBodyDestination
->putMoreData(data
, len
);
609 // if we had overflow area, shrink it as necessary
610 if (responseBodyBuffer
) {
611 if (putSize
== responseBodyBuffer
->contentSize()) {
612 delete responseBodyBuffer
;
613 responseBodyBuffer
= NULL
;
615 responseBodyBuffer
->consume(putSize
);
620 // if we did not have an overflow area, create it as needed
622 assert(!responseBodyBuffer
);
623 responseBodyBuffer
= new MemBuf
;
624 responseBodyBuffer
->init(4096, SQUID_TCP_SO_RCVBUF
* 10);
625 responseBodyBuffer
->append(data
, len
);
629 // can supply more virgin response body data
631 ServerStateData::noteMoreBodySpaceAvailable(BodyPipe::Pointer
)
633 if (responseBodyBuffer
) {
634 addVirginReplyBody(NULL
, 0); // kick the buffered fragment alive again
635 if (completed
&& !responseBodyBuffer
) {
640 maybeReadVirginBody();
643 // the consumer of our virgin response body aborted
645 ServerStateData::noteBodyConsumerAborted(BodyPipe::Pointer
)
647 stopProducingFor(virginBodyDestination
, false);
649 // do not force closeServer here in case we need to bypass AdaptationQueryAbort
651 if (doneWithAdaptation()) // we may still be receiving adapted response
652 handleAdaptationCompleted();
655 // received adapted response headers (body may follow)
657 ServerStateData::noteAdaptationAnswer(HttpMsg
*msg
)
659 clearAdaptation(adaptedHeadSource
); // we do not expect more messages
661 if (abortOnBadEntry("entry went bad while waiting for adapted headers"))
664 HttpReply
*rep
= dynamic_cast<HttpReply
*>(msg
);
666 debugs(11,5, HERE
<< this << " setting adapted reply to " << rep
);
669 assert(!adaptedBodySource
);
670 if (rep
->body_pipe
!= NULL
) {
671 // subscribe to receive adapted body
672 adaptedBodySource
= rep
->body_pipe
;
673 // assume that ICAP does not auto-consume on failures
674 assert(adaptedBodySource
->setConsumerIfNotLate(this));
677 if (doneWithAdaptation()) // we may still be sending virgin response
678 handleAdaptationCompleted();
682 // will not receive adapted response headers (and, hence, body)
684 ServerStateData::noteAdaptationQueryAbort(bool final
)
686 clearAdaptation(adaptedHeadSource
);
687 handleAdaptationAborted(!final
);
690 // more adapted response body is available
692 ServerStateData::handleMoreAdaptedBodyAvailable()
694 const size_t contentSize
= adaptedBodySource
->buf().contentSize();
696 debugs(11,5, HERE
<< "consuming " << contentSize
<< " bytes of adapted " <<
697 "response body at offset " << adaptedBodySource
->consumedSize());
699 if (abortOnBadEntry("entry refuses adapted body"))
703 BodyPipeCheckout
bpc(*adaptedBodySource
);
704 const StoreIOBuffer
ioBuf(&bpc
.buf
, currentOffset
);
705 currentOffset
+= bpc
.buf
.size
;
707 bpc
.buf
.consume(contentSize
);
711 // the entire adapted response body was produced, successfully
713 ServerStateData::handleAdaptedBodyProductionEnded()
715 stopConsumingFrom(adaptedBodySource
);
717 if (abortOnBadEntry("entry went bad while waiting for adapted body eof"))
720 handleAdaptationCompleted();
723 // premature end of the adapted response body
724 void ServerStateData::handleAdaptedBodyProducerAborted()
726 stopConsumingFrom(adaptedBodySource
);
727 handleAdaptationAborted();
730 // common part of noteAdaptationAnswer and handleAdaptedBodyProductionEnded
732 ServerStateData::handleAdaptationCompleted()
734 debugs(11,5, HERE
<< "handleAdaptationCompleted");
737 // We stop reading origin response because we have no place to put it and
738 // cannot use it. If some origin servers do not like that or if we want to
739 // reuse more pconns, we can add code to discard unneeded origin responses.
740 if (!doneWithServer()) {
741 debugs(11,3, HERE
<< "closing origin conn due to ICAP completion");
745 completeForwarding();
750 // common part of noteAdaptation*Aborted and noteBodyConsumerAborted methods
752 ServerStateData::handleAdaptationAborted(bool bypassable
)
754 debugs(11,5, HERE
<< "handleAdaptationAborted; bypassable: " << bypassable
<<
755 ", entry empty: " << entry
->isEmpty());
757 if (abortOnBadEntry("entry went bad while ICAP aborted"))
760 // TODO: bypass if possible
762 if (entry
->isEmpty()) {
763 debugs(11,9, HERE
<< "creating ICAP error entry after ICAP failure");
764 ErrorState
*err
= errorCon(ERR_ICAP_FAILURE
, HTTP_INTERNAL_SERVER_ERROR
, request
);
765 err
->xerrno
= ERR_DETAIL_ICAP_RESPMOD_EARLY
;
767 fwd
->dontRetry(true);
768 } else if (request
) { // update logged info directly
769 request
->detailError(ERR_ICAP_FAILURE
, ERR_DETAIL_ICAP_RESPMOD_LATE
);
772 abortTransaction("ICAP failure");
776 ServerStateData::adaptationAclCheckDone(Adaptation::ServiceGroupPointer group
)
778 adaptationAccessCheckPending
= false;
780 if (abortOnBadEntry("entry went bad while waiting for ICAP ACL check"))
783 // TODO: Should nonICAP and postICAP path check this on the server-side?
784 // That check now only happens on client-side, in processReplyAccess().
785 if (virginReply()->expectedBodyTooLarge(*request
)) {
786 sendBodyIsTooLargeError();
789 // TODO: Should we check receivedBodyTooLarge on the server-side as well?
792 debugs(11,3, HERE
<< "no adapation needed");
793 setFinalReply(virginReply());
798 startAdaptation(group
, originalRequest());
803 ServerStateData::adaptationAclCheckDoneWrapper(Adaptation::ServiceGroupPointer group
, void *data
)
805 ServerStateData
*state
= (ServerStateData
*)data
;
806 state
->adaptationAclCheckDone(group
);
811 ServerStateData::sendBodyIsTooLargeError()
813 ErrorState
*err
= errorCon(ERR_TOO_BIG
, HTTP_FORBIDDEN
, request
);
816 fwd
->dontRetry(true);
817 abortTransaction("Virgin body too large.");
820 // TODO: when HttpStateData sends all errors to ICAP,
821 // we should be able to move this at the end of setVirginReply().
823 ServerStateData::adaptOrFinalizeReply()
826 // TODO: merge with client side and return void to hide the on/off logic?
827 // The callback can be called with a NULL service if adaptation is off.
828 adaptationAccessCheckPending
= Adaptation::AccessCheck::Start(
829 Adaptation::methodRespmod
, Adaptation::pointPreCache
,
830 request
, virginReply(), adaptationAclCheckDoneWrapper
, this);
831 debugs(11,5, HERE
<< "adaptationAccessCheckPending=" << adaptationAccessCheckPending
);
832 if (adaptationAccessCheckPending
)
836 setFinalReply(virginReply());
839 /// initializes bodyBytesRead stats if needed and applies delta
841 ServerStateData::adjustBodyBytesRead(const int64_t delta
)
843 int64_t &bodyBytesRead
= originalRequest()->hier
.bodyBytesRead
;
845 // if we got here, do not log a dash even if we got nothing from the server
846 if (bodyBytesRead
< 0)
849 bodyBytesRead
+= delta
; // supports negative and zero deltas
851 // check for overflows ("infinite" response?) and undeflows (a bug)
852 Must(bodyBytesRead
>= 0);
856 ServerStateData::addVirginReplyBody(const char *data
, ssize_t len
)
858 adjustBodyBytesRead(len
);
861 assert(!adaptationAccessCheckPending
); // or would need to buffer while waiting
862 if (startedAdaptation
) {
863 adaptVirginReplyBody(data
, len
);
867 storeReplyBody(data
, len
);
870 // writes virgin or adapted reply body to store
872 ServerStateData::storeReplyBody(const char *data
, ssize_t len
)
874 // write even if len is zero to push headers towards the client side
875 entry
->write (StoreIOBuffer(len
, currentOffset
, (char*)data
));
877 currentOffset
+= len
;
880 size_t ServerStateData::replyBodySpace(const MemBuf
&readBuf
,
881 const size_t minSpace
) const
883 size_t space
= readBuf
.spaceSize(); // available space w/o heroic measures
884 if (space
< minSpace
) {
885 const size_t maxSpace
= readBuf
.potentialSpaceSize(); // absolute best
886 space
= min(minSpace
, maxSpace
); // do not promise more than asked
890 if (responseBodyBuffer
) {
891 return 0; // Stop reading if already overflowed waiting for ICAP to catch up
894 if (virginBodyDestination
!= NULL
) {
896 * BodyPipe buffer has a finite size limit. We
897 * should not read more data from the network than will fit
898 * into the pipe buffer or we _lose_ what did not fit if
899 * the response ends sooner that BodyPipe frees up space:
900 * There is no code to keep pumping data into the pipe once
901 * response ends and serverComplete() is called.
903 * If the pipe is totally full, don't register the read handler.
904 * The BodyPipe will call our noteMoreBodySpaceAvailable() method
905 * when it has free space again.
907 size_t adaptation_space
=
908 virginBodyDestination
->buf().potentialSpaceSize();
910 debugs(11,9, "ServerStateData may read up to min(" <<
911 adaptation_space
<< ", " << space
<< ") bytes");
913 if (adaptation_space
< space
)
914 space
= adaptation_space
;