5 * DEBUG: section 85 Client-side Request Routines
6 * AUTHOR: Robert Collins (Originally Duane Wessels in client_side.c)
8 * SQUID Web Proxy Cache http://www.squid-cache.org/
9 * ----------------------------------------------------------
11 * Squid is the result of efforts by numerous individuals from
12 * the Internet community; see the CONTRIBUTORS file for full
13 * details. Many organizations have provided support for Squid's
14 * development; see the SPONSORS file for full details. Squid is
15 * Copyrighted (C) 2001 by the Regents of the University of
16 * California; see the COPYRIGHT file for full details. Squid
17 * incorporates software developed and/or copyrighted by other
18 * sources; see the CREDITS file for full details.
20 * This program is free software; you can redistribute it and/or modify
21 * it under the terms of the GNU General Public License as published by
22 * the Free Software Foundation; either version 2 of the License, or
23 * (at your option) any later version.
25 * This program is distributed in the hope that it will be useful,
26 * but WITHOUT ANY WARRANTY; without even the implied warranty of
27 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
28 * GNU General Public License for more details.
30 * You should have received a copy of the GNU General Public License
31 * along with this program; if not, write to the Free Software
32 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111, USA.
38 * General logic of request processing:
40 * We run a series of tests to determine if access will be permitted, and to do
41 * any redirection. Then we call into the result clientStream to retrieve data.
42 * From that point on it's up to reply management.
46 #include "acl/FilledChecklist.h"
47 #include "acl/Gadgets.h"
49 #include "adaptation/AccessCheck.h"
50 #include "adaptation/Iterator.h"
51 #include "adaptation/Service.h"
53 #include "adaptation/icap/History.h"
56 #include "auth/UserRequest.h"
57 #include "clientStream.h"
58 #include "client_side.h"
59 #include "client_side_reply.h"
60 #include "client_side_request.h"
61 #include "ClientRequestContext.h"
62 #include "compat/inet_pton.h"
64 #include "HttpReply.h"
65 #include "HttpRequest.h"
66 #include "ip/QosConfig.h"
67 #include "MemObject.h"
68 #include "ProtoPort.h"
70 #include "SquidTime.h"
72 #include "err_detail_type.h"
76 #define comm_close comm_lingering_close
79 static const char *const crlf
= "\r\n";
81 #if FOLLOW_X_FORWARDED_FOR
83 clientFollowXForwardedForCheck(int answer
, void *data
);
84 #endif /* FOLLOW_X_FORWARDED_FOR */
86 CBDATA_CLASS_INIT(ClientRequestContext
);
89 ClientRequestContext::operator new (size_t size
)
91 assert (size
== sizeof(ClientRequestContext
));
92 CBDATA_INIT_TYPE(ClientRequestContext
);
93 ClientRequestContext
*result
= cbdataAlloc(ClientRequestContext
);
98 ClientRequestContext::operator delete (void *address
)
100 ClientRequestContext
*t
= static_cast<ClientRequestContext
*>(address
);
104 /* Local functions */
106 static void clientAccessCheckDoneWrapper(int, void *);
107 static int clientHierarchical(ClientHttpRequest
* http
);
108 static void clientInterpretRequestHeaders(ClientHttpRequest
* http
);
109 static RH clientRedirectDoneWrapper
;
110 static PF checkNoCacheDoneWrapper
;
111 extern "C" CSR clientGetMoreData
;
112 extern "C" CSS clientReplyStatus
;
113 extern "C" CSD clientReplyDetach
;
114 static void checkFailureRatio(err_type
, hier_code
);
116 ClientRequestContext::~ClientRequestContext()
119 * Release our "lock" on our parent, ClientHttpRequest, if we
124 cbdataReferenceDone(http
);
126 debugs(85,3, HERE
<< this << " ClientRequestContext destructed");
129 ClientRequestContext::ClientRequestContext(ClientHttpRequest
*anHttp
) : http(cbdataReference(anHttp
)), acl_checklist (NULL
), redirect_state (REDIRECT_NONE
)
131 http_access_done
= false;
132 redirect_done
= false;
133 no_cache_done
= false;
134 interpreted_req_hdrs
= false;
135 debugs(85,3, HERE
<< this << " ClientRequestContext constructed");
138 CBDATA_CLASS_INIT(ClientHttpRequest
);
141 ClientHttpRequest::operator new (size_t size
)
143 assert (size
== sizeof (ClientHttpRequest
));
144 CBDATA_INIT_TYPE(ClientHttpRequest
);
145 ClientHttpRequest
*result
= cbdataAlloc(ClientHttpRequest
);
150 ClientHttpRequest::operator delete (void *address
)
152 ClientHttpRequest
*t
= static_cast<ClientHttpRequest
*>(address
);
156 ClientHttpRequest::ClientHttpRequest(ConnStateData
* aConn
) :
158 AsyncJob("ClientHttpRequest"),
162 start_time
= current_time
;
164 dlinkAdd(this, &active
, &ClientActiveRequests
);
166 request_satisfaction_mode
= false;
171 * returns true if client specified that the object must come from the cache
172 * without contacting origin server
175 ClientHttpRequest::onlyIfCached()const
178 return request
->cache_control
&&
179 EBIT_TEST(request
->cache_control
->mask
, CC_ONLY_IF_CACHED
);
183 * This function is designed to serve a fairly specific purpose.
184 * Occasionally our vBNS-connected caches can talk to each other, but not
185 * the rest of the world. Here we try to detect frequent failures which
186 * make the cache unusable (e.g. DNS lookup and connect() failures). If
187 * the failure:success ratio goes above 1.0 then we go into "hit only"
188 * mode where we only return UDP_HIT or UDP_MISS_NOFETCH. Neighbors
189 * will only fetch HITs from us if they are using the ICP protocol. We
190 * stay in this mode for 5 minutes.
192 * Duane W., Sept 16, 1996
195 #define FAILURE_MODE_TIME 300
198 checkFailureRatio(err_type etype
, hier_code hcode
)
200 static double magic_factor
= 100.0;
204 if (hcode
== HIER_NONE
)
207 n_good
= magic_factor
/ (1.0 + request_failure_ratio
);
209 n_bad
= magic_factor
- n_good
;
215 case ERR_CONNECT_FAIL
:
216 case ERR_SECURE_CONNECT_FAIL
:
226 request_failure_ratio
= n_bad
/ n_good
;
228 if (hit_only_mode_until
> squid_curtime
)
231 if (request_failure_ratio
< 1.0)
234 debugs(33, 0, "Failure Ratio at "<< std::setw(4)<<
235 std::setprecision(3) << request_failure_ratio
);
237 debugs(33, 0, "Going into hit-only-mode for " <<
238 FAILURE_MODE_TIME
/ 60 << " minutes...");
240 hit_only_mode_until
= squid_curtime
+ FAILURE_MODE_TIME
;
242 request_failure_ratio
= 0.8; /* reset to something less than 1.0 */
245 ClientHttpRequest::~ClientHttpRequest()
247 debugs(33, 3, "httpRequestFree: " << uri
);
248 PROF_start(httpRequestFree
);
250 // Even though freeResources() below may destroy the request,
251 // we no longer set request->body_pipe to NULL here
252 // because we did not initiate that pipe (ConnStateData did)
254 /* the ICP check here was erroneous
255 * - StoreEntry::releaseRequest was always called if entry was valid
257 assert(logType
< LOG_TYPE_MAX
);
264 checkFailureRatio(request
->errType
, al
.hier
.code
);
269 announceInitiatorAbort(virginHeadSource
);
271 if (adaptedBodySource
!= NULL
)
272 stopConsumingFrom(adaptedBodySource
);
276 delete calloutContext
;
279 cbdataReferenceDone(conn_
);
281 /* moving to the next connection is handled by the context free */
282 dlinkDelete(&active
, &ClientActiveRequests
);
284 PROF_stop(httpRequestFree
);
288 * Create a request and kick it off
293 * TODO: Pass in the buffers to be used in the inital Read request, as they are
294 * determined by the user
297 clientBeginRequest(const HttpRequestMethod
& method
, char const *url
, CSCB
* streamcallback
,
298 CSD
* streamdetach
, ClientStreamData streamdata
, HttpHeader
const *header
,
299 char *tailbuf
, size_t taillen
)
302 ClientHttpRequest
*http
= new ClientHttpRequest(NULL
);
303 HttpRequest
*request
;
304 StoreIOBuffer tempBuffer
;
305 http
->start_time
= current_time
;
306 /* this is only used to adjust the connection offset in client_side.c */
308 tempBuffer
.length
= taillen
;
309 tempBuffer
.data
= tailbuf
;
310 /* client stream setup */
311 clientStreamInit(&http
->client_stream
, clientGetMoreData
, clientReplyDetach
,
312 clientReplyStatus
, new clientReplyContext(http
), streamcallback
,
313 streamdetach
, streamdata
, tempBuffer
);
314 /* make it visible in the 'current acctive requests list' */
316 /* internal requests only makes sense in an
317 * accelerator today. TODO: accept flags ? */
318 http
->flags
.accel
= 1;
319 /* allow size for url rewriting */
320 url_sz
= strlen(url
) + Config
.appendDomainLen
+ 5;
321 http
->uri
= (char *)xcalloc(url_sz
, 1);
322 strcpy(http
->uri
, url
);
324 if ((request
= HttpRequest::CreateFromUrlAndMethod(http
->uri
, method
)) == NULL
) {
325 debugs(85, 5, "Invalid URL: " << http
->uri
);
330 * now update the headers in request with our supplied headers. urlParse
331 * should return a blank header set, but we use Update to be sure of
335 request
->header
.update(header
, NULL
);
337 http
->log_uri
= xstrdup(urlCanonicalClean(request
));
339 /* http struct now ready */
342 * build new header list *? TODO
344 request
->flags
.accelerated
= http
->flags
.accel
;
346 request
->flags
.internalclient
= 1;
348 /* this is an internally created
349 * request, not subject to acceleration
350 * target overrides */
352 * FIXME? Do we want to detect and handle internal requests of internal
356 /* Internally created requests cannot have bodies today */
357 request
->content_length
= 0;
359 request
->client_addr
.SetNoAddr();
361 #if FOLLOW_X_FORWARDED_FOR
362 request
->indirect_client_addr
.SetNoAddr();
363 #endif /* FOLLOW_X_FORWARDED_FOR */
365 request
->my_addr
.SetNoAddr(); /* undefined for internal requests */
367 request
->my_addr
.SetPort(0);
369 /* Our version is HTTP/1.1 */
370 HttpVersion
http_ver(1,1);
371 request
->http_ver
= http_ver
;
373 http
->request
= HTTPMSGLOCK(request
);
375 /* optional - skip the access check ? */
376 http
->calloutContext
= new ClientRequestContext(http
);
378 http
->calloutContext
->http_access_done
= false;
380 http
->calloutContext
->redirect_done
= true;
382 http
->calloutContext
->no_cache_done
= true;
390 ClientRequestContext::httpStateIsValid()
392 ClientHttpRequest
*http_
= http
;
394 if (cbdataReferenceValid(http_
))
399 cbdataReferenceDone(http_
);
404 #if FOLLOW_X_FORWARDED_FOR
406 * clientFollowXForwardedForCheck() checks the content of X-Forwarded-For:
407 * against the followXFF ACL, or cleans up and passes control to
408 * clientAccessCheck().
410 * The trust model here is a little ambiguous. So to clarify the logic:
411 * - we may always use the direct client address as the client IP.
412 * - these trust tests merey tell whether we trust given IP enough to believe the
413 * IP string which it appended to the X-Forwarded-For: header.
414 * - if at any point we don't trust what an IP adds we stop looking.
415 * - at that point the current contents of indirect_client_addr are the value set
416 * by the last previously trusted IP.
417 * ++ indirect_client_addr contains the remote direct client from the trusted peers viewpoint.
420 clientFollowXForwardedForCheck(int answer
, void *data
)
422 ClientRequestContext
*calloutContext
= (ClientRequestContext
*) data
;
424 if (!calloutContext
->httpStateIsValid())
427 ClientHttpRequest
*http
= calloutContext
->http
;
428 HttpRequest
*request
= http
->request
;
431 * answer should be be ACCESS_ALLOWED or ACCESS_DENIED if we are
432 * called as a result of ACL checks, or -1 if we are called when
433 * there's nothing left to do.
435 if (answer
== ACCESS_ALLOWED
&&
436 request
->x_forwarded_for_iterator
.size () != 0) {
439 * Remove the last comma-delimited element from the
440 * x_forwarded_for_iterator and use it to repeat the cycle.
443 const char *asciiaddr
;
446 p
= request
->x_forwarded_for_iterator
.termedBuf();
447 l
= request
->x_forwarded_for_iterator
.size();
450 * XXX x_forwarded_for_iterator should really be a list of
451 * IP addresses, but it's a String instead. We have to
452 * walk backwards through the String, biting off the last
453 * comma-delimited part each time. As long as the data is in
454 * a String, we should probably implement and use a variant of
455 * strListGetItem() that walks backwards instead of forwards
456 * through a comma-separated list. But we don't even do that;
457 * we just do the work in-line here.
459 /* skip trailing space and commas */
460 while (l
> 0 && (p
[l
-1] == ',' || xisspace(p
[l
-1])))
462 request
->x_forwarded_for_iterator
.cut(l
);
463 /* look for start of last item in list */
464 while (l
> 0 && ! (p
[l
-1] == ',' || xisspace(p
[l
-1])))
467 if ((addr
= asciiaddr
)) {
468 request
->indirect_client_addr
= addr
;
469 request
->x_forwarded_for_iterator
.cut(l
);
470 calloutContext
->acl_checklist
= clientAclChecklistCreate(Config
.accessList
.followXFF
, http
);
471 if (!Config
.onoff
.acl_uses_indirect_client
) {
472 /* override the default src_addr tested if we have to go deeper than one level into XFF */
473 Filled(calloutContext
->acl_checklist
)->src_addr
= request
->indirect_client_addr
;
475 calloutContext
->acl_checklist
->nonBlockingCheck(clientFollowXForwardedForCheck
, data
);
478 } /*if (answer == ACCESS_ALLOWED &&
479 request->x_forwarded_for_iterator.size () != 0)*/
481 /* clean up, and pass control to clientAccessCheck */
482 if (Config
.onoff
.log_uses_indirect_client
) {
484 * Ensure that the access log shows the indirect client
485 * instead of the direct client.
487 ConnStateData
*conn
= http
->getConn();
488 conn
->log_addr
= request
->indirect_client_addr
;
490 request
->x_forwarded_for_iterator
.clean();
491 request
->flags
.done_follow_x_forwarded_for
= 1;
493 if (answer
!= ACCESS_ALLOWED
&& answer
!= ACCESS_DENIED
) {
494 debugs(28, DBG_CRITICAL
, "ERROR: Processing X-Forwarded-For. Stopping at IP address: " << request
->indirect_client_addr
);
497 /* process actual access ACL as normal. */
498 calloutContext
->clientAccessCheck();
500 #endif /* FOLLOW_X_FORWARDED_FOR */
502 /* This is the entry point for external users of the client_side routines */
504 ClientRequestContext::clientAccessCheck()
506 #if FOLLOW_X_FORWARDED_FOR
507 if (!http
->request
->flags
.done_follow_x_forwarded_for
&&
508 Config
.accessList
.followXFF
&&
509 http
->request
->header
.has(HDR_X_FORWARDED_FOR
)) {
511 /* we always trust the direct client address for actual use */
512 http
->request
->indirect_client_addr
= http
->request
->client_addr
;
513 http
->request
->indirect_client_addr
.SetPort(0);
515 /* setup the XFF iterator for processing */
516 http
->request
->x_forwarded_for_iterator
= http
->request
->header
.getList(HDR_X_FORWARDED_FOR
);
518 /* begin by checking to see if we trust direct client enough to walk XFF */
519 acl_checklist
= clientAclChecklistCreate(Config
.accessList
.followXFF
, http
);
520 acl_checklist
->nonBlockingCheck(clientFollowXForwardedForCheck
, this);
523 #endif /* FOLLOW_X_FORWARDED_FOR */
525 if (Config
.accessList
.http
) {
526 acl_checklist
= clientAclChecklistCreate(Config
.accessList
.http
, http
);
527 acl_checklist
->nonBlockingCheck(clientAccessCheckDoneWrapper
, this);
529 debugs(0, DBG_CRITICAL
, "No http_access configuration found. This will block ALL traffic");
530 clientAccessCheckDone(ACCESS_DENIED
);
535 * Identical in operation to clientAccessCheck() but performed later using different configured ACL list.
536 * The default here is to allow all. Since the earlier http_access should do a default deny all.
537 * This check is just for a last-minute denial based on adapted request headers.
540 ClientRequestContext::clientAccessCheck2()
542 if (Config
.accessList
.adapted_http
) {
543 acl_checklist
= clientAclChecklistCreate(Config
.accessList
.adapted_http
, http
);
544 acl_checklist
->nonBlockingCheck(clientAccessCheckDoneWrapper
, this);
546 debugs(85, 2, HERE
<< "No adapted_http_access configuration.");
547 clientAccessCheckDone(ACCESS_ALLOWED
);
552 clientAccessCheckDoneWrapper(int answer
, void *data
)
554 ClientRequestContext
*calloutContext
= (ClientRequestContext
*) data
;
556 if (!calloutContext
->httpStateIsValid())
559 calloutContext
->clientAccessCheckDone(answer
);
563 ClientRequestContext::clientAccessCheckDone(int answer
)
565 acl_checklist
= NULL
;
568 debugs(85, 2, "The request " <<
569 RequestMethodStr(http
->request
->method
) << " " <<
570 http
->uri
<< " is " <<
571 (answer
== ACCESS_ALLOWED
? "ALLOWED" : "DENIED") <<
572 ", because it matched '" <<
573 (AclMatchedName
? AclMatchedName
: "NO ACL's") << "'" );
574 char const *proxy_auth_msg
= "<null>";
576 if (http
->getConn() != NULL
&& http
->getConn()->auth_user_request
!= NULL
)
577 proxy_auth_msg
= http
->getConn()->auth_user_request
->denyMessage("<null>");
578 else if (http
->request
->auth_user_request
!= NULL
)
579 proxy_auth_msg
= http
->request
->auth_user_request
->denyMessage("<null>");
581 if (answer
!= ACCESS_ALLOWED
) {
583 int require_auth
= (answer
== ACCESS_REQ_PROXY_AUTH
|| aclIsProxyAuth(AclMatchedName
));
584 debugs(85, 5, "Access Denied: " << http
->uri
);
585 debugs(85, 5, "AclMatchedName = " << (AclMatchedName
? AclMatchedName
: "<null>"));
588 debugs(33, 5, "Proxy Auth Message = " << (proxy_auth_msg
? proxy_auth_msg
: "<null>"));
591 * NOTE: get page_id here, based on AclMatchedName because if
592 * USE_DELAY_POOLS is enabled, then AclMatchedName gets clobbered in
593 * the clientCreateStoreEntry() call just below. Pedro Ribeiro
596 page_id
= aclGetDenyInfoPage(&Config
.denyInfoList
, AclMatchedName
, answer
!= ACCESS_REQ_PROXY_AUTH
);
598 http
->logType
= LOG_TCP_DENIED
;
601 if (!http
->flags
.accel
) {
602 /* Proxy authorisation needed */
603 status
= HTTP_PROXY_AUTHENTICATION_REQUIRED
;
605 /* WWW authorisation needed */
606 status
= HTTP_UNAUTHORIZED
;
609 if (page_id
== ERR_NONE
)
610 page_id
= ERR_CACHE_ACCESS_DENIED
;
612 status
= HTTP_FORBIDDEN
;
614 if (page_id
== ERR_NONE
)
615 page_id
= ERR_ACCESS_DENIED
;
618 clientStreamNode
*node
= (clientStreamNode
*)http
->client_stream
.tail
->prev
->data
;
619 clientReplyContext
*repContext
= dynamic_cast<clientReplyContext
*>(node
->data
.getRaw());
621 Ip::Address tmpnoaddr
;
622 tmpnoaddr
.SetNoAddr();
623 repContext
->setReplyToError(page_id
, status
,
624 http
->request
->method
, NULL
,
625 http
->getConn() != NULL
? http
->getConn()->peer
: tmpnoaddr
,
628 http
->getConn() != NULL
&& http
->getConn()->auth_user_request
!= NULL
?
629 http
->getConn()->auth_user_request
: http
->request
->auth_user_request
);
631 node
= (clientStreamNode
*)http
->client_stream
.tail
->data
;
632 clientStreamRead(node
, http
, node
->readBuffer
);
636 /* ACCESS_ALLOWED continues here ... */
637 safe_free(http
->uri
);
639 http
->uri
= xstrdup(urlCanonical(http
->request
));
646 adaptationAclCheckDoneWrapper(Adaptation::ServiceGroupPointer g
, void *data
)
648 ClientRequestContext
*calloutContext
= (ClientRequestContext
*)data
;
650 if (!calloutContext
->httpStateIsValid())
653 calloutContext
->adaptationAclCheckDone(g
);
657 ClientRequestContext::adaptationAclCheckDone(Adaptation::ServiceGroupPointer g
)
659 debugs(93,3,HERE
<< this << " adaptationAclCheckDone called");
663 Adaptation::Icap::History::Pointer ih
= http
->request
->icapHistory();
665 if (http
->getConn() != NULL
) {
666 ih
->rfc931
= http
->getConn()->rfc931
;
668 ih
->ssluser
= sslGetUserEmail(fd_table
[http
->getConn()->fd
].ssl
);
671 ih
->log_uri
= http
->log_uri
;
672 ih
->req_sz
= http
->req_sz
;
677 debugs(85,3, HERE
<< "no adaptation needed");
682 http
->startAdaptation(g
);
688 clientRedirectAccessCheckDone(int answer
, void *data
)
690 ClientRequestContext
*context
= (ClientRequestContext
*)data
;
691 ClientHttpRequest
*http
= context
->http
;
692 context
->acl_checklist
= NULL
;
694 if (answer
== ACCESS_ALLOWED
)
695 redirectStart(http
, clientRedirectDoneWrapper
, context
);
697 context
->clientRedirectDone(NULL
);
701 ClientRequestContext::clientRedirectStart()
703 debugs(33, 5, "clientRedirectStart: '" << http
->uri
<< "'");
705 if (Config
.accessList
.redirector
) {
706 acl_checklist
= clientAclChecklistCreate(Config
.accessList
.redirector
, http
);
707 acl_checklist
->nonBlockingCheck(clientRedirectAccessCheckDone
, this);
709 redirectStart(http
, clientRedirectDoneWrapper
, this);
713 clientHierarchical(ClientHttpRequest
* http
)
715 const char *url
= http
->uri
;
716 HttpRequest
*request
= http
->request
;
717 HttpRequestMethod method
= request
->method
;
718 const wordlist
*p
= NULL
;
721 * IMS needs a private key, so we can use the hierarchy for IMS only if our
722 * neighbors support private keys
725 if (request
->flags
.ims
&& !neighbors_do_private_keys
)
729 * This is incorrect: authenticating requests can be sent via a hierarchy
730 * (they can even be cached if the correct headers are set on the reply)
732 if (request
->flags
.auth
)
735 if (method
== METHOD_TRACE
)
738 if (method
!= METHOD_GET
)
741 /* scan hierarchy_stoplist */
742 for (p
= Config
.hierarchy_stoplist
; p
; p
= p
->next
)
743 if (strstr(url
, p
->key
))
746 if (request
->flags
.loopdetect
)
749 if (request
->protocol
== PROTO_HTTP
)
750 return httpCachable(method
);
752 if (request
->protocol
== PROTO_GOPHER
)
753 return gopherCachable(request
);
755 if (request
->protocol
== PROTO_CACHEOBJ
)
763 clientCheckPinning(ClientHttpRequest
* http
)
765 HttpRequest
*request
= http
->request
;
766 HttpHeader
*req_hdr
= &request
->header
;
767 ConnStateData
*http_conn
= http
->getConn();
769 /* Internal requests such as those from ESI includes may be without
770 * a client connection
775 request
->flags
.connection_auth_disabled
= http_conn
->port
->connection_auth_disabled
;
776 if (!request
->flags
.connection_auth_disabled
) {
777 if (http_conn
->pinning
.fd
!= -1) {
778 if (http_conn
->pinning
.auth
) {
779 request
->flags
.connection_auth
= 1;
780 request
->flags
.auth
= 1;
782 request
->flags
.connection_proxy_auth
= 1;
784 request
->setPinnedConnection(http_conn
);
788 /* check if connection auth is used, and flag as candidate for pinning
790 * Note: we may need to set flags.connection_auth even if the connection
791 * is already pinned if it was pinned earlier due to proxy auth
793 if (!request
->flags
.connection_auth
) {
794 if (req_hdr
->has(HDR_AUTHORIZATION
) || req_hdr
->has(HDR_PROXY_AUTHORIZATION
)) {
795 HttpHeaderPos pos
= HttpHeaderInitPos
;
798 while ((e
= req_hdr
->getEntry(&pos
))) {
799 if (e
->id
== HDR_AUTHORIZATION
|| e
->id
== HDR_PROXY_AUTHORIZATION
) {
800 const char *value
= e
->value
.rawBuf();
801 if (strncasecmp(value
, "NTLM ", 5) == 0
803 strncasecmp(value
, "Negotiate ", 10) == 0
805 strncasecmp(value
, "Kerberos ", 9) == 0) {
806 if (e
->id
== HDR_AUTHORIZATION
) {
807 request
->flags
.connection_auth
= 1;
810 request
->flags
.connection_proxy_auth
= 1;
816 if (may_pin
&& !request
->pinnedConnection()) {
817 request
->setPinnedConnection(http
->getConn());
824 clientInterpretRequestHeaders(ClientHttpRequest
* http
)
826 HttpRequest
*request
= http
->request
;
827 HttpHeader
*req_hdr
= &request
->header
;
831 request
->imslen
= -1;
832 request
->ims
= req_hdr
->getTime(HDR_IF_MODIFIED_SINCE
);
834 if (request
->ims
> 0)
835 request
->flags
.ims
= 1;
837 if (!request
->flags
.ignore_cc
) {
838 if (req_hdr
->has(HDR_PRAGMA
)) {
839 String s
= req_hdr
->getList(HDR_PRAGMA
);
841 if (strListIsMember(&s
, "no-cache", ','))
847 if (request
->cache_control
)
848 if (EBIT_TEST(request
->cache_control
->mask
, CC_NO_CACHE
))
852 * Work around for supporting the Reload button in IE browsers when Squid
853 * is used as an accelerator or transparent proxy, by turning accelerated
854 * IMS request to no-cache requests. Now knows about IE 5.5 fix (is
855 * actually only fixed in SP1, but we can't tell whether we are talking to
856 * SP1 or not so all 5.5 versions are treated 'normally').
858 if (Config
.onoff
.ie_refresh
) {
859 if (http
->flags
.accel
&& request
->flags
.ims
) {
860 if ((str
= req_hdr
->getStr(HDR_USER_AGENT
))) {
861 if (strstr(str
, "MSIE 5.01") != NULL
)
863 else if (strstr(str
, "MSIE 5.0") != NULL
)
865 else if (strstr(str
, "MSIE 4.") != NULL
)
867 else if (strstr(str
, "MSIE 3.") != NULL
)
874 if (request
->method
== METHOD_OTHER
) {
879 #if USE_HTTP_VIOLATIONS
881 if (Config
.onoff
.reload_into_ims
)
882 request
->flags
.nocache_hack
= 1;
883 else if (refresh_nocache_hack
)
884 request
->flags
.nocache_hack
= 1;
888 request
->flags
.nocache
= 1;
891 /* ignore range header in non-GETs or non-HEADs */
892 if (request
->method
== METHOD_GET
|| request
->method
== METHOD_HEAD
) {
893 // XXX: initialize if we got here without HttpRequest::parseHeader()
895 request
->range
= req_hdr
->getRange();
897 if (request
->range
) {
898 request
->flags
.range
= 1;
899 clientStreamNode
*node
= (clientStreamNode
*)http
->client_stream
.tail
->data
;
900 /* XXX: This is suboptimal. We should give the stream the range set,
901 * and thereby let the top of the stream set the offset when the
902 * size becomes known. As it is, we will end up requesting from 0
903 * for evey -X range specification.
904 * RBC - this may be somewhat wrong. We should probably set the range
905 * iter up at this point.
907 node
->readBuffer
.offset
= request
->range
->lowestOffset(0);
908 http
->range_iter
.pos
= request
->range
->begin();
909 http
->range_iter
.valid
= true;
913 /* Only HEAD and GET requests permit a Range or Request-Range header.
914 * If these headers appear on any other type of request, delete them now.
917 req_hdr
->delById(HDR_RANGE
);
918 req_hdr
->delById(HDR_REQUEST_RANGE
);
919 delete request
->range
;
920 request
->range
= NULL
;
923 if (req_hdr
->has(HDR_AUTHORIZATION
))
924 request
->flags
.auth
= 1;
926 clientCheckPinning(http
);
928 if (request
->login
[0] != '\0')
929 request
->flags
.auth
= 1;
931 if (req_hdr
->has(HDR_VIA
)) {
932 String s
= req_hdr
->getList(HDR_VIA
);
934 * ThisCache cannot be a member of Via header, "1.0 ThisCache" can.
935 * Note ThisCache2 has a space prepended to the hostname so we don't
936 * accidentally match super-domains.
939 if (strListIsSubstr(&s
, ThisCache2
, ',')) {
940 debugObj(33, 1, "WARNING: Forwarding loop detected for:\n",
941 request
, (ObjPackMethod
) & httpRequestPack
);
942 request
->flags
.loopdetect
= 1;
946 fvdbCountVia(s
.termedBuf());
954 \todo --enable-useragent-log and --enable-referer-log. We should
955 probably drop those two as the custom log formats accomplish pretty much the same thing..
957 #if USE_USERAGENT_LOG
958 if ((str
= req_hdr
->getStr(HDR_USER_AGENT
)))
959 logUserAgent(fqdnFromAddr(http
->getConn()->log_addr
), str
);
964 if ((str
= req_hdr
->getStr(HDR_REFERER
)))
965 logReferer(fqdnFromAddr(http
->getConn()->log_addr
), str
, http
->log_uri
);
970 if (req_hdr
->has(HDR_X_FORWARDED_FOR
)) {
971 String s
= req_hdr
->getList(HDR_X_FORWARDED_FOR
);
972 fvdbCountForw(s
.termedBuf());
978 request
->flags
.cachable
= http
->request
->cacheable();
980 if (clientHierarchical(http
))
981 request
->flags
.hierarchical
= 1;
983 debugs(85, 5, "clientInterpretRequestHeaders: REQ_NOCACHE = " <<
984 (request
->flags
.nocache
? "SET" : "NOT SET"));
985 debugs(85, 5, "clientInterpretRequestHeaders: REQ_CACHABLE = " <<
986 (request
->flags
.cachable
? "SET" : "NOT SET"));
987 debugs(85, 5, "clientInterpretRequestHeaders: REQ_HIERARCHICAL = " <<
988 (request
->flags
.hierarchical
? "SET" : "NOT SET"));
993 clientRedirectDoneWrapper(void *data
, char *result
)
995 ClientRequestContext
*calloutContext
= (ClientRequestContext
*)data
;
997 if (!calloutContext
->httpStateIsValid())
1000 calloutContext
->clientRedirectDone(result
);
1004 ClientRequestContext::clientRedirectDone(char *result
)
1006 HttpRequest
*new_request
= NULL
;
1007 HttpRequest
*old_request
= http
->request
;
1008 debugs(85, 5, "clientRedirectDone: '" << http
->uri
<< "' result=" << (result
? result
: "NULL"));
1009 assert(redirect_state
== REDIRECT_PENDING
);
1010 redirect_state
= REDIRECT_DONE
;
1013 http_status status
= (http_status
) atoi(result
);
1015 if (status
== HTTP_MOVED_PERMANENTLY
1016 || status
== HTTP_MOVED_TEMPORARILY
1017 || status
== HTTP_SEE_OTHER
1018 || status
== HTTP_TEMPORARY_REDIRECT
) {
1021 if ((t
= strchr(result
, ':')) != NULL
) {
1022 http
->redirect
.status
= status
;
1023 http
->redirect
.location
= xstrdup(t
+ 1);
1024 // TODO: validate the URL produced here is RFC 2616 compliant absolute URI
1026 if (old_request
->http_ver
< HttpVersion(1,1))
1027 debugs(85, DBG_CRITICAL
, "ERROR: URL-rewrite produces invalid 302 redirect Location: " << result
);
1029 debugs(85, DBG_CRITICAL
, "ERROR: URL-rewrite produces invalid 303 redirect Location: " << result
);
1031 } else if (strcmp(result
, http
->uri
)) {
1032 if (!(new_request
= HttpRequest::CreateFromUrlAndMethod(result
, old_request
->method
)))
1033 debugs(85, DBG_CRITICAL
, "ERROR: URL-rewrite produces invalid request: " <<
1034 old_request
->method
<< " " << result
<< " HTTP/1.1");
1039 safe_free(http
->uri
);
1040 http
->uri
= xstrdup(urlCanonical(new_request
));
1041 new_request
->http_ver
= old_request
->http_ver
;
1042 new_request
->header
.append(&old_request
->header
);
1043 new_request
->client_addr
= old_request
->client_addr
;
1044 #if FOLLOW_X_FORWARDED_FOR
1045 new_request
->indirect_client_addr
= old_request
->indirect_client_addr
;
1046 #endif /* FOLLOW_X_FORWARDED_FOR */
1047 new_request
->my_addr
= old_request
->my_addr
;
1048 new_request
->flags
= old_request
->flags
;
1049 new_request
->flags
.redirected
= 1;
1050 new_request
->auth_user_request
= old_request
->auth_user_request
;
1052 if (old_request
->body_pipe
!= NULL
) {
1053 new_request
->body_pipe
= old_request
->body_pipe
;
1054 old_request
->body_pipe
= NULL
;
1055 debugs(0,0,HERE
<< "redirecting body_pipe " << new_request
->body_pipe
<< " from request " << old_request
<< " to " << new_request
);
1058 new_request
->content_length
= old_request
->content_length
;
1059 new_request
->extacl_user
= old_request
->extacl_user
;
1060 new_request
->extacl_passwd
= old_request
->extacl_passwd
;
1061 new_request
->flags
.proxy_keepalive
= old_request
->flags
.proxy_keepalive
;
1062 HTTPMSGUNLOCK(old_request
);
1063 http
->request
= HTTPMSGLOCK(new_request
);
1066 /* FIXME PIPELINE: This is innacurate during pipelining */
1068 if (http
->getConn() != NULL
)
1069 fd_note(http
->getConn()->fd
, http
->uri
);
1076 /** Test cache allow/deny configuration
1077 * Sets flags.cachable=1 if caching is not denied.
1080 ClientRequestContext::checkNoCache()
1082 if (Config
.accessList
.noCache
) {
1083 acl_checklist
= clientAclChecklistCreate(Config
.accessList
.noCache
, http
);
1084 acl_checklist
->nonBlockingCheck(checkNoCacheDoneWrapper
, this);
1086 /* unless otherwise specified, we try to cache. */
1087 checkNoCacheDone(1);
1092 checkNoCacheDoneWrapper(int answer
, void *data
)
1094 ClientRequestContext
*calloutContext
= (ClientRequestContext
*) data
;
1096 if (!calloutContext
->httpStateIsValid())
1099 calloutContext
->checkNoCacheDone(answer
);
1103 ClientRequestContext::checkNoCacheDone(int answer
)
1105 acl_checklist
= NULL
;
1106 http
->request
->flags
.cachable
= answer
;
1111 * Identify requests that do not go through the store and client side stream
1112 * and forward them to the appropriate location. All other requests, request
1116 ClientHttpRequest::processRequest()
1118 debugs(85, 4, "clientProcessRequest: " << RequestMethodStr(request
->method
) << " '" << uri
<< "'");
1121 if (request
->method
== METHOD_CONNECT
&& sslBumpNeeded()) {
1127 if (request
->method
== METHOD_CONNECT
&& !redirect
.status
) {
1128 logType
= LOG_TCP_MISS
;
1129 getConn()->stopReading(); // tunnels read for themselves
1130 tunnelStart(this, &out
.size
, &al
.http
.code
);
1138 ClientHttpRequest::httpStart()
1140 PROF_start(httpStart
);
1141 logType
= LOG_TAG_NONE
;
1142 debugs(85, 4, "ClientHttpRequest::httpStart: " << log_tags
[logType
] << " for '" << uri
<< "'");
1144 /* no one should have touched this */
1145 assert(out
.offset
== 0);
1146 /* Use the Stream Luke */
1147 clientStreamNode
*node
= (clientStreamNode
*)client_stream
.tail
->data
;
1148 clientStreamRead(node
, this, node
->readBuffer
);
1149 PROF_stop(httpStart
);
1154 // determines whether we should bump the CONNECT request
1156 ClientHttpRequest::sslBumpNeeded() const
1158 if (!getConn()->port
->sslBump
|| !Config
.accessList
.ssl_bump
)
1161 debugs(85, 5, HERE
<< "SslBump possible, checking ACL");
1163 ACLFilledChecklist
check(Config
.accessList
.ssl_bump
, request
, NULL
);
1164 check
.src_addr
= request
->client_addr
;
1165 check
.my_addr
= request
->my_addr
;
1166 return check
.fastCheck() == 1;
1169 // called when comm_write has completed
1171 SslBumpEstablish(int, char *, size_t, comm_err_t errflag
, int, void *data
)
1173 ClientHttpRequest
*r
= static_cast<ClientHttpRequest
*>(data
);
1174 debugs(85, 5, HERE
<< "responded to CONNECT: " << r
<< " ? " << errflag
);
1176 assert(r
&& cbdataReferenceValid(r
));
1177 r
->sslBumpEstablish(errflag
);
1181 ClientHttpRequest::sslBumpEstablish(comm_err_t errflag
)
1183 // Bail out quickly on COMM_ERR_CLOSING - close handlers will tidy up
1184 if (errflag
== COMM_ERR_CLOSING
)
1188 getConn()->startClosing("CONNECT response failure in SslBump");
1192 getConn()->switchToHttps();
1196 ClientHttpRequest::sslBumpStart()
1198 debugs(85, 5, HERE
<< "ClientHttpRequest::sslBumpStart");
1200 // send an HTTP 200 response to kick client SSL negotiation
1201 const int fd
= getConn()->fd
;
1202 debugs(33, 7, HERE
<< "Confirming CONNECT tunnel on FD " << fd
);
1204 // TODO: Unify with tunnel.cc and add a Server(?) header
1205 static const char *const conn_established
=
1206 "HTTP/1.0 200 Connection established\r\n\r\n";
1207 comm_write(fd
, conn_established
, strlen(conn_established
),
1208 &SslBumpEstablish
, this, NULL
);
1214 ClientHttpRequest::gotEnough() const
1216 /** TODO: should be querying the stream. */
1217 int64_t contentLength
=
1218 memObject()->getReply()->bodySize(request
->method
);
1219 assert(contentLength
>= 0);
1221 if (out
.offset
< contentLength
)
1228 ClientHttpRequest::storeEntry(StoreEntry
*newEntry
)
1234 ClientHttpRequest::loggingEntry(StoreEntry
*newEntry
)
1237 loggingEntry_
->unlock();
1239 loggingEntry_
= newEntry
;
1242 loggingEntry_
->lock();
1246 * doCallouts() - This function controls the order of "callout"
1247 * executions, including non-blocking access control checks, the
1248 * redirector, and ICAP. Previously, these callouts were chained
1249 * together such that "clientAccessCheckDone()" would call
1250 * "clientRedirectStart()" and so on.
1252 * The ClientRequestContext (aka calloutContext) class holds certain
1253 * state data for the callout/callback operations. Previously
1254 * ClientHttpRequest would sort of hand off control to ClientRequestContext
1255 * for a short time. ClientRequestContext would then delete itself
1256 * and pass control back to ClientHttpRequest when all callouts
1259 * This caused some problems for ICAP because we want to make the
1260 * ICAP callout after checking ACLs, but before checking the no_cache
1261 * list. We can't stuff the ICAP state into the ClientRequestContext
1262 * class because we still need the ICAP state after ClientRequestContext
1265 * Note that ClientRequestContext is created before the first call
1268 * If one of the callouts notices that ClientHttpRequest is no
1269 * longer valid, it should call cbdataReferenceDone() so that
1270 * ClientHttpRequest's reference count goes to zero and it will get
1271 * deleted. ClientHttpRequest will then delete ClientRequestContext.
1273 * Note that we set the _done flags here before actually starting
1274 * the callout. This is strictly for convenience.
1277 extern tos_t
aclMapTOS (acl_tos
* head
, ACLChecklist
* ch
);
1278 extern nfmark_t
aclMapNfmark (acl_nfmark
* head
, ACLChecklist
* ch
);
1281 ClientHttpRequest::doCallouts()
1283 assert(calloutContext
);
1285 /*Save the original request for logging purposes*/
1286 if (!calloutContext
->http
->al
.request
)
1287 calloutContext
->http
->al
.request
= HTTPMSGLOCK(request
);
1289 if (!calloutContext
->http_access_done
) {
1290 debugs(83, 3, HERE
<< "Doing calloutContext->clientAccessCheck()");
1291 calloutContext
->http_access_done
= true;
1292 calloutContext
->clientAccessCheck();
1297 if (!calloutContext
->adaptation_acl_check_done
) {
1298 calloutContext
->adaptation_acl_check_done
= true;
1299 if (Adaptation::AccessCheck::Start(
1300 Adaptation::methodReqmod
, Adaptation::pointPreCache
,
1301 request
, NULL
, adaptationAclCheckDoneWrapper
, calloutContext
))
1302 return; // will call callback
1306 if (!calloutContext
->redirect_done
) {
1307 calloutContext
->redirect_done
= true;
1308 assert(calloutContext
->redirect_state
== REDIRECT_NONE
);
1310 if (Config
.Program
.redirect
) {
1311 debugs(83, 3, HERE
<< "Doing calloutContext->clientRedirectStart()");
1312 calloutContext
->redirect_state
= REDIRECT_PENDING
;
1313 calloutContext
->clientRedirectStart();
1318 if (!calloutContext
->adapted_http_access_done
) {
1319 debugs(83, 3, HERE
<< "Doing calloutContext->clientAccessCheck2()");
1320 calloutContext
->adapted_http_access_done
= true;
1321 calloutContext
->clientAccessCheck2();
1325 if (!calloutContext
->interpreted_req_hdrs
) {
1326 debugs(83, 3, HERE
<< "Doing clientInterpretRequestHeaders()");
1327 calloutContext
->interpreted_req_hdrs
= 1;
1328 clientInterpretRequestHeaders(this);
1331 if (!calloutContext
->no_cache_done
) {
1332 calloutContext
->no_cache_done
= true;
1334 if (Config
.accessList
.noCache
&& request
->flags
.cachable
) {
1335 debugs(83, 3, HERE
<< "Doing calloutContext->checkNoCache()");
1336 calloutContext
->checkNoCache();
1341 if (!calloutContext
->tosToClientDone
) {
1342 calloutContext
->tosToClientDone
= true;
1343 if (getConn() != NULL
) {
1344 ACLFilledChecklist
ch(NULL
, request
, NULL
);
1345 ch
.src_addr
= request
->client_addr
;
1346 ch
.my_addr
= request
->my_addr
;
1347 tos_t tos
= aclMapTOS(Ip::Qos::TheConfig
.tosToClient
, &ch
);
1349 Ip::Qos::setSockTos(getConn()->fd
, tos
);
1353 if (!calloutContext
->nfmarkToClientDone
) {
1354 calloutContext
->nfmarkToClientDone
= true;
1355 if (getConn() != NULL
) {
1356 ACLFilledChecklist
ch(NULL
, request
, NULL
);
1357 ch
.src_addr
= request
->client_addr
;
1358 ch
.my_addr
= request
->my_addr
;
1359 nfmark_t mark
= aclMapNfmark(Ip::Qos::TheConfig
.nfmarkToClient
, &ch
);
1361 Ip::Qos::setSockNfmark(getConn()->fd
, mark
);
1365 cbdataReferenceDone(calloutContext
->http
);
1366 delete calloutContext
;
1367 calloutContext
= NULL
;
1370 headersLog(0, 1, request
->method
, request
);
1373 debugs(83, 3, HERE
<< "calling processRequest()");
1377 Adaptation::Icap::History::Pointer ih
= request
->icapHistory();
1379 ih
->logType
= logType
;
1384 #include "client_side_request.cci"
1388 /// Initiate an asynchronous adaptation transaction which will call us back.
1390 ClientHttpRequest::startAdaptation(const Adaptation::ServiceGroupPointer
&g
)
1392 debugs(85, 3, HERE
<< "adaptation needed for " << this);
1393 assert(!virginHeadSource
);
1394 assert(!adaptedBodySource
);
1395 virginHeadSource
= initiateAdaptation(
1396 new Adaptation::Iterator(request
, NULL
, g
));
1398 // we could try to guess whether we can bypass this adaptation
1399 // initiation failure, but it should not really happen
1400 Must(initiated(virginHeadSource
));
1404 ClientHttpRequest::noteAdaptationAnswer(HttpMsg
*msg
)
1406 assert(cbdataReferenceValid(this)); // indicates bug
1409 if (HttpRequest
*new_req
= dynamic_cast<HttpRequest
*>(msg
)) {
1411 * Replace the old request with the new request.
1413 HTTPMSGUNLOCK(request
);
1414 request
= HTTPMSGLOCK(new_req
);
1416 * Store the new URI for logging
1419 uri
= xstrdup(urlCanonical(request
));
1420 setLogUri(this, urlCanonicalClean(request
));
1421 assert(request
->method
.id());
1422 } else if (HttpReply
*new_rep
= dynamic_cast<HttpReply
*>(msg
)) {
1423 debugs(85,3,HERE
<< "REQMOD reply is HTTP reply");
1425 // subscribe to receive reply body
1426 if (new_rep
->body_pipe
!= NULL
) {
1427 adaptedBodySource
= new_rep
->body_pipe
;
1428 int consumer_ok
= adaptedBodySource
->setConsumerIfNotLate(this);
1429 assert(consumer_ok
);
1432 clientStreamNode
*node
= (clientStreamNode
*)client_stream
.tail
->prev
->data
;
1433 clientReplyContext
*repContext
= dynamic_cast<clientReplyContext
*>(node
->data
.getRaw());
1434 repContext
->createStoreEntry(request
->method
, request
->flags
);
1436 EBIT_CLR(storeEntry()->flags
, ENTRY_FWD_HDR_WAIT
);
1437 request_satisfaction_mode
= true;
1438 request_satisfaction_offset
= 0;
1439 storeEntry()->replaceHttpReply(new_rep
);
1440 storeEntry()->timestampsSet();
1442 if (!adaptedBodySource
) // no body
1443 storeEntry()->complete();
1444 clientGetMoreData(node
, this);
1447 // we are done with getting headers (but may be receiving body)
1448 clearAdaptation(virginHeadSource
);
1450 if (!request_satisfaction_mode
)
1455 ClientHttpRequest::noteAdaptationQueryAbort(bool final
)
1457 clearAdaptation(virginHeadSource
);
1458 assert(!adaptedBodySource
);
1459 handleAdaptationFailure(ERR_DETAIL_ICAP_REQMOD_ABORT
, !final
);
1463 ClientHttpRequest::noteMoreBodyDataAvailable(BodyPipe::Pointer
)
1465 assert(request_satisfaction_mode
);
1466 assert(adaptedBodySource
!= NULL
);
1468 if (const size_t contentSize
= adaptedBodySource
->buf().contentSize()) {
1469 BodyPipeCheckout
bpc(*adaptedBodySource
);
1470 const StoreIOBuffer
ioBuf(&bpc
.buf
, request_satisfaction_offset
);
1471 storeEntry()->write(ioBuf
);
1472 // assume can write everything
1473 request_satisfaction_offset
+= contentSize
;
1474 bpc
.buf
.consume(contentSize
);
1478 if (adaptedBodySource
->exhausted())
1479 endRequestSatisfaction();
1480 // else wait for more body data
1484 ClientHttpRequest::noteBodyProductionEnded(BodyPipe::Pointer
)
1486 assert(!virginHeadSource
);
1487 if (adaptedBodySource
!= NULL
) { // did not end request satisfaction yet
1488 // We do not expect more because noteMoreBodyDataAvailable always
1489 // consumes everything. We do not even have a mechanism to consume
1490 // leftovers after noteMoreBodyDataAvailable notifications seize.
1491 assert(adaptedBodySource
->exhausted());
1492 endRequestSatisfaction();
1497 ClientHttpRequest::endRequestSatisfaction()
1499 debugs(85,4, HERE
<< this << " ends request satisfaction");
1500 assert(request_satisfaction_mode
);
1501 stopConsumingFrom(adaptedBodySource
);
1503 // TODO: anything else needed to end store entry formation correctly?
1504 storeEntry()->complete();
1508 ClientHttpRequest::noteBodyProducerAborted(BodyPipe::Pointer
)
1510 assert(!virginHeadSource
);
1511 stopConsumingFrom(adaptedBodySource
);
1512 handleAdaptationFailure(ERR_DETAIL_ICAP_RESPMOD_CLT_SIDE_BODY
);
1516 ClientHttpRequest::handleAdaptationFailure(int errDetail
, bool bypassable
)
1518 debugs(85,3, HERE
<< "handleAdaptationFailure(" << bypassable
<< ")");
1520 const bool usedStore
= storeEntry() && !storeEntry()->isEmpty();
1521 const bool usedPipe
= request
->body_pipe
!= NULL
&&
1522 request
->body_pipe
->consumedSize() > 0;
1524 if (bypassable
&& !usedStore
&& !usedPipe
) {
1525 debugs(85,3, HERE
<< "ICAP REQMOD callout failed, bypassing: " << calloutContext
);
1531 debugs(85,3, HERE
<< "ICAP REQMOD callout failed, responding with error");
1533 clientStreamNode
*node
= (clientStreamNode
*)client_stream
.tail
->prev
->data
;
1534 clientReplyContext
*repContext
= dynamic_cast<clientReplyContext
*>(node
->data
.getRaw());
1537 // The original author of the code also wanted to pass an errno to
1538 // setReplyToError, but it seems unlikely that the errno reflects the
1539 // true cause of the error at this point, so I did not pass it.
1542 ConnStateData
* c
= getConn();
1543 repContext
->setReplyToError(ERR_ICAP_FAILURE
, HTTP_INTERNAL_SERVER_ERROR
,
1544 request
->method
, NULL
,
1545 (c
!= NULL
? c
->peer
: noAddr
), request
, NULL
,
1546 (c
!= NULL
&& c
->auth_user_request
!= NULL
?
1547 c
->auth_user_request
: request
->auth_user_request
));
1549 request
->detailError(ERR_ICAP_FAILURE
, errDetail
);
1551 node
= (clientStreamNode
*)client_stream
.tail
->data
;
1552 clientStreamRead(node
, this, node
->readBuffer
);