2 * Copyright (C) 1996-2017 The Squid Software Foundation and contributors
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.
9 /* DEBUG: section 85 Client-side Request Routines */
12 * General logic of request processing:
14 * We run a series of tests to determine if access will be permitted, and to do
15 * any redirection. Then we call into the result clientStream to retrieve data.
16 * From that point on it's up to reply management.
20 #include "acl/FilledChecklist.h"
21 #include "acl/Gadgets.h"
22 #include "anyp/PortCfg.h"
23 #include "base/AsyncJobCalls.h"
24 #include "client_side.h"
25 #include "client_side_reply.h"
26 #include "client_side_request.h"
27 #include "ClientRequestContext.h"
28 #include "clientStream.h"
29 #include "comm/Connection.h"
30 #include "comm/Write.h"
31 #include "err_detail_type.h"
32 #include "errorpage.h"
35 #include "format/Token.h"
38 #include "helper/Reply.h"
40 #include "http/Stream.h"
41 #include "HttpHdrCc.h"
42 #include "HttpReply.h"
43 #include "HttpRequest.h"
44 #include "ip/QosConfig.h"
46 #include "log/access_log.h"
47 #include "MemObject.h"
49 #include "profiler/Profiler.h"
51 #include "SquidConfig.h"
52 #include "SquidTime.h"
59 #include "auth/UserRequest.h"
62 #include "adaptation/AccessCheck.h"
63 #include "adaptation/Answer.h"
64 #include "adaptation/Iterator.h"
65 #include "adaptation/Service.h"
67 #include "adaptation/icap/History.h"
71 #include "ssl/ServerBump.h"
72 #include "ssl/support.h"
76 #define comm_close comm_lingering_close
79 static const char *const crlf
= "\r\n";
81 #if FOLLOW_X_FORWARDED_FOR
82 static void clientFollowXForwardedForCheck(allow_t answer
, void *data
);
83 #endif /* FOLLOW_X_FORWARDED_FOR */
85 ErrorState
*clientBuildError(err_type
, Http::StatusCode
, char const *url
, Ip::Address
&, HttpRequest
*);
87 CBDATA_CLASS_INIT(ClientRequestContext
);
91 static void clientAccessCheckDoneWrapper(allow_t
, void *);
93 static void sslBumpAccessCheckDoneWrapper(allow_t
, void *);
95 static int clientHierarchical(ClientHttpRequest
* http
);
96 static void clientInterpretRequestHeaders(ClientHttpRequest
* http
);
97 static HLPCB clientRedirectDoneWrapper
;
98 static HLPCB clientStoreIdDoneWrapper
;
99 static void checkNoCacheDoneWrapper(allow_t
, void *);
100 SQUIDCEXTERN CSR clientGetMoreData
;
101 SQUIDCEXTERN CSS clientReplyStatus
;
102 SQUIDCEXTERN CSD clientReplyDetach
;
103 static void checkFailureRatio(err_type
, hier_code
);
105 ClientRequestContext::~ClientRequestContext()
108 * Release our "lock" on our parent, ClientHttpRequest, if we
113 cbdataReferenceDone(http
);
116 debugs(85,3, "ClientRequestContext destructed, this=" << this);
119 ClientRequestContext::ClientRequestContext(ClientHttpRequest
*anHttp
) :
120 http(cbdataReference(anHttp
)),
122 redirect_state(REDIRECT_NONE
),
123 store_id_state(REDIRECT_NONE
),
124 host_header_verify_done(false),
125 http_access_done(false),
126 adapted_http_access_done(false),
128 adaptation_acl_check_done(false),
130 redirect_done(false),
131 store_id_done(false),
132 no_cache_done(false),
133 interpreted_req_hdrs(false),
134 tosToClientDone(false),
135 nfmarkToClientDone(false),
137 sslBumpCheckDone(false),
140 readNextRequest(false)
142 debugs(85, 3, "ClientRequestContext constructed, this=" << this);
145 CBDATA_CLASS_INIT(ClientHttpRequest
);
147 ClientHttpRequest::ClientHttpRequest(ConnStateData
* aConn
) :
149 AsyncJob("ClientHttpRequest"),
155 logType(LOG_TAG_NONE
),
156 calloutContext(NULL
),
157 maxReplyBodySize_(0),
162 , sslBumpNeed_(Ssl::bumpEnd
)
165 , request_satisfaction_mode(false)
166 , request_satisfaction_offset(0)
170 al
= new AccessLogEntry
;
171 al
->cache
.start_time
= current_time
;
173 al
->tcpClient
= clientConnection
= aConn
->clientConnection
;
174 al
->cache
.port
= aConn
->port
;
175 al
->cache
.caddr
= aConn
->log_addr
;
178 if (aConn
->clientConnection
!= NULL
&& aConn
->clientConnection
->isOpen()) {
179 if (auto ssl
= fd_table
[aConn
->clientConnection
->fd
].ssl
.get())
180 al
->cache
.sslClientCert
.resetWithoutLocking(SSL_get_peer_certificate(ssl
));
184 dlinkAdd(this, &active
, &ClientActiveRequests
);
188 * returns true if client specified that the object must come from the cache
189 * without contacting origin server
192 ClientHttpRequest::onlyIfCached()const
195 return request
->cache_control
&&
196 request
->cache_control
->hasOnlyIfCached();
200 * This function is designed to serve a fairly specific purpose.
201 * Occasionally our vBNS-connected caches can talk to each other, but not
202 * the rest of the world. Here we try to detect frequent failures which
203 * make the cache unusable (e.g. DNS lookup and connect() failures). If
204 * the failure:success ratio goes above 1.0 then we go into "hit only"
205 * mode where we only return UDP_HIT or UDP_MISS_NOFETCH. Neighbors
206 * will only fetch HITs from us if they are using the ICP protocol. We
207 * stay in this mode for 5 minutes.
209 * Duane W., Sept 16, 1996
212 checkFailureRatio(err_type etype
, hier_code hcode
)
214 // Can be set at compile time with -D compiler flag
215 #ifndef FAILURE_MODE_TIME
216 #define FAILURE_MODE_TIME 300
219 if (hcode
== HIER_NONE
)
222 // don't bother when ICP is disabled.
223 if (Config
.Port
.icp
<= 0)
226 static double magic_factor
= 100.0;
230 n_good
= magic_factor
/ (1.0 + request_failure_ratio
);
232 n_bad
= magic_factor
- n_good
;
238 case ERR_CONNECT_FAIL
:
239 case ERR_SECURE_CONNECT_FAIL
:
249 request_failure_ratio
= n_bad
/ n_good
;
251 if (hit_only_mode_until
> squid_curtime
)
254 if (request_failure_ratio
< 1.0)
257 debugs(33, DBG_CRITICAL
, "WARNING: Failure Ratio at "<< std::setw(4)<<
258 std::setprecision(3) << request_failure_ratio
);
260 debugs(33, DBG_CRITICAL
, "WARNING: ICP going into HIT-only mode for " <<
261 FAILURE_MODE_TIME
/ 60 << " minutes...");
263 hit_only_mode_until
= squid_curtime
+ FAILURE_MODE_TIME
;
265 request_failure_ratio
= 0.8; /* reset to something less than 1.0 */
268 ClientHttpRequest::~ClientHttpRequest()
270 debugs(33, 3, "httpRequestFree: " << uri
);
271 PROF_start(httpRequestFree
);
273 // Even though freeResources() below may destroy the request,
274 // we no longer set request->body_pipe to NULL here
275 // because we did not initiate that pipe (ConnStateData did)
277 /* the ICP check here was erroneous
278 * - StoreEntry::releaseRequest was always called if entry was valid
286 checkFailureRatio(request
->errType
, al
->hier
.code
);
291 announceInitiatorAbort(virginHeadSource
);
293 if (adaptedBodySource
!= NULL
)
294 stopConsumingFrom(adaptedBodySource
);
298 delete calloutContext
;
300 clientConnection
= NULL
;
303 cbdataReferenceDone(conn_
);
305 /* moving to the next connection is handled by the context free */
306 dlinkDelete(&active
, &ClientActiveRequests
);
308 PROF_stop(httpRequestFree
);
312 * Create a request and kick it off
317 * TODO: Pass in the buffers to be used in the inital Read request, as they are
318 * determined by the user
321 clientBeginRequest(const HttpRequestMethod
& method
, char const *url
, CSCB
* streamcallback
,
322 CSD
* streamdetach
, ClientStreamData streamdata
, HttpHeader
const *header
,
323 char *tailbuf
, size_t taillen
)
326 ClientHttpRequest
*http
= new ClientHttpRequest(NULL
);
327 HttpRequest
*request
;
328 StoreIOBuffer tempBuffer
;
329 if (http
->al
!= NULL
)
330 http
->al
->cache
.start_time
= current_time
;
331 /* this is only used to adjust the connection offset in client_side.c */
333 tempBuffer
.length
= taillen
;
334 tempBuffer
.data
= tailbuf
;
335 /* client stream setup */
336 clientStreamInit(&http
->client_stream
, clientGetMoreData
, clientReplyDetach
,
337 clientReplyStatus
, new clientReplyContext(http
), streamcallback
,
338 streamdetach
, streamdata
, tempBuffer
);
339 /* make it visible in the 'current acctive requests list' */
341 /* internal requests only makes sense in an
342 * accelerator today. TODO: accept flags ? */
343 http
->flags
.accel
= true;
344 /* allow size for url rewriting */
345 url_sz
= strlen(url
) + Config
.appendDomainLen
+ 5;
346 http
->uri
= (char *)xcalloc(url_sz
, 1);
347 strcpy(http
->uri
, url
);
349 if ((request
= HttpRequest::CreateFromUrl(http
->uri
, method
)) == NULL
) {
350 debugs(85, 5, "Invalid URL: " << http
->uri
);
355 * now update the headers in request with our supplied headers. urlParse
356 * should return a blank header set, but we use Update to be sure of
360 request
->header
.update(header
);
362 http
->log_uri
= xstrdup(urlCanonicalClean(request
));
364 /* http struct now ready */
367 * build new header list *? TODO
369 request
->flags
.accelerated
= http
->flags
.accel
;
371 request
->flags
.internalClient
= true;
373 /* this is an internally created
374 * request, not subject to acceleration
375 * target overrides */
377 * FIXME? Do we want to detect and handle internal requests of internal
381 /* Internally created requests cannot have bodies today */
382 request
->content_length
= 0;
384 request
->client_addr
.setNoAddr();
386 #if FOLLOW_X_FORWARDED_FOR
387 request
->indirect_client_addr
.setNoAddr();
388 #endif /* FOLLOW_X_FORWARDED_FOR */
390 request
->my_addr
.setNoAddr(); /* undefined for internal requests */
392 request
->my_addr
.port(0);
394 request
->http_ver
= Http::ProtocolVersion();
396 http
->request
= request
;
397 HTTPMSGLOCK(http
->request
);
399 /* optional - skip the access check ? */
400 http
->calloutContext
= new ClientRequestContext(http
);
402 http
->calloutContext
->http_access_done
= false;
404 http
->calloutContext
->redirect_done
= true;
406 http
->calloutContext
->no_cache_done
= true;
414 ClientRequestContext::httpStateIsValid()
416 ClientHttpRequest
*http_
= http
;
418 if (cbdataReferenceValid(http_
))
423 cbdataReferenceDone(http_
);
428 #if FOLLOW_X_FORWARDED_FOR
430 * clientFollowXForwardedForCheck() checks the content of X-Forwarded-For:
431 * against the followXFF ACL, or cleans up and passes control to
432 * clientAccessCheck().
434 * The trust model here is a little ambiguous. So to clarify the logic:
435 * - we may always use the direct client address as the client IP.
436 * - these trust tests merey tell whether we trust given IP enough to believe the
437 * IP string which it appended to the X-Forwarded-For: header.
438 * - if at any point we don't trust what an IP adds we stop looking.
439 * - at that point the current contents of indirect_client_addr are the value set
440 * by the last previously trusted IP.
441 * ++ indirect_client_addr contains the remote direct client from the trusted peers viewpoint.
444 clientFollowXForwardedForCheck(allow_t answer
, void *data
)
446 ClientRequestContext
*calloutContext
= (ClientRequestContext
*) data
;
448 if (!calloutContext
->httpStateIsValid())
451 ClientHttpRequest
*http
= calloutContext
->http
;
452 HttpRequest
*request
= http
->request
;
455 * answer should be be ACCESS_ALLOWED or ACCESS_DENIED if we are
456 * called as a result of ACL checks, or -1 if we are called when
457 * there's nothing left to do.
459 if (answer
== ACCESS_ALLOWED
&&
460 request
->x_forwarded_for_iterator
.size () != 0) {
463 * Remove the last comma-delimited element from the
464 * x_forwarded_for_iterator and use it to repeat the cycle.
467 const char *asciiaddr
;
470 p
= request
->x_forwarded_for_iterator
.termedBuf();
471 l
= request
->x_forwarded_for_iterator
.size();
474 * XXX x_forwarded_for_iterator should really be a list of
475 * IP addresses, but it's a String instead. We have to
476 * walk backwards through the String, biting off the last
477 * comma-delimited part each time. As long as the data is in
478 * a String, we should probably implement and use a variant of
479 * strListGetItem() that walks backwards instead of forwards
480 * through a comma-separated list. But we don't even do that;
481 * we just do the work in-line here.
483 /* skip trailing space and commas */
484 while (l
> 0 && (p
[l
-1] == ',' || xisspace(p
[l
-1])))
486 request
->x_forwarded_for_iterator
.cut(l
);
487 /* look for start of last item in list */
488 while (l
> 0 && ! (p
[l
-1] == ',' || xisspace(p
[l
-1])))
491 if ((addr
= asciiaddr
)) {
492 request
->indirect_client_addr
= addr
;
493 request
->x_forwarded_for_iterator
.cut(l
);
494 calloutContext
->acl_checklist
= clientAclChecklistCreate(Config
.accessList
.followXFF
, http
);
495 if (!Config
.onoff
.acl_uses_indirect_client
) {
496 /* override the default src_addr tested if we have to go deeper than one level into XFF */
497 Filled(calloutContext
->acl_checklist
)->src_addr
= request
->indirect_client_addr
;
499 calloutContext
->acl_checklist
->nonBlockingCheck(clientFollowXForwardedForCheck
, data
);
502 } /*if (answer == ACCESS_ALLOWED &&
503 request->x_forwarded_for_iterator.size () != 0)*/
505 /* clean up, and pass control to clientAccessCheck */
506 if (Config
.onoff
.log_uses_indirect_client
) {
508 * Ensure that the access log shows the indirect client
509 * instead of the direct client.
511 ConnStateData
*conn
= http
->getConn();
512 conn
->log_addr
= request
->indirect_client_addr
;
513 http
->al
->cache
.caddr
= conn
->log_addr
;
515 request
->x_forwarded_for_iterator
.clean();
516 request
->flags
.done_follow_x_forwarded_for
= true;
518 if (answer
!= ACCESS_ALLOWED
&& answer
!= ACCESS_DENIED
) {
519 debugs(28, DBG_CRITICAL
, "ERROR: Processing X-Forwarded-For. Stopping at IP address: " << request
->indirect_client_addr
);
522 /* process actual access ACL as normal. */
523 calloutContext
->clientAccessCheck();
525 #endif /* FOLLOW_X_FORWARDED_FOR */
528 hostHeaderIpVerifyWrapper(const ipcache_addrs
* ia
, const Dns::LookupDetails
&dns
, void *data
)
530 ClientRequestContext
*c
= static_cast<ClientRequestContext
*>(data
);
531 c
->hostHeaderIpVerify(ia
, dns
);
535 ClientRequestContext::hostHeaderIpVerify(const ipcache_addrs
* ia
, const Dns::LookupDetails
&dns
)
537 Comm::ConnectionPointer clientConn
= http
->getConn()->clientConnection
;
539 // note the DNS details for the transaction stats.
540 http
->request
->recordLookup(dns
);
542 if (ia
!= NULL
&& ia
->count
> 0) {
543 // Is the NAT destination IP in DNS?
544 for (int i
= 0; i
< ia
->count
; ++i
) {
545 if (clientConn
->local
.matchIPAddr(ia
->in_addrs
[i
]) == 0) {
546 debugs(85, 3, HERE
<< "validate IP " << clientConn
->local
<< " possible from Host:");
547 http
->request
->flags
.hostVerified
= true;
551 debugs(85, 3, HERE
<< "validate IP " << clientConn
->local
<< " non-match from Host: IP " << ia
->in_addrs
[i
]);
554 debugs(85, 3, HERE
<< "FAIL: validate IP " << clientConn
->local
<< " possible from Host:");
555 hostHeaderVerifyFailed("local IP", "any domain IP");
559 ClientRequestContext::hostHeaderVerifyFailed(const char *A
, const char *B
)
561 // IP address validation for Host: failed. Admin wants to ignore them.
562 // NP: we do not yet handle CONNECT tunnels well, so ignore for them
563 if (!Config
.onoff
.hostStrictVerify
&& http
->request
->method
!= Http::METHOD_CONNECT
) {
564 debugs(85, 3, "SECURITY ALERT: Host header forgery detected on " << http
->getConn()->clientConnection
<<
565 " (" << A
<< " does not match " << B
<< ") on URL: " << http
->request
->effectiveRequestUri());
567 // NP: it is tempting to use 'flags.noCache' but that is all about READing cache data.
568 // The problems here are about WRITE for new cache content, which means flags.cachable
569 http
->request
->flags
.cachable
= false; // MUST NOT cache (for now)
570 // XXX: when we have updated the cache key to base on raw-IP + URI this cacheable limit can go.
571 http
->request
->flags
.hierarchical
= false; // MUST NOT pass to peers (for now)
572 // XXX: when we have sorted out the best way to relay requests properly to peers this hierarchical limit can go.
577 debugs(85, DBG_IMPORTANT
, "SECURITY ALERT: Host header forgery detected on " <<
578 http
->getConn()->clientConnection
<< " (" << A
<< " does not match " << B
<< ")");
579 if (const char *ua
= http
->request
->header
.getStr(Http::HdrType::USER_AGENT
))
580 debugs(85, DBG_IMPORTANT
, "SECURITY ALERT: By user agent: " << ua
);
581 debugs(85, DBG_IMPORTANT
, "SECURITY ALERT: on URL: " << http
->request
->effectiveRequestUri());
583 // IP address validation for Host: failed. reject the connection.
584 clientStreamNode
*node
= (clientStreamNode
*)http
->client_stream
.tail
->prev
->data
;
585 clientReplyContext
*repContext
= dynamic_cast<clientReplyContext
*>(node
->data
.getRaw());
587 repContext
->setReplyToError(ERR_CONFLICT_HOST
, Http::scConflict
,
588 http
->request
->method
, NULL
,
589 http
->getConn()->clientConnection
->remote
,
593 http
->getConn() != NULL
&& http
->getConn()->getAuth() != NULL
?
594 http
->getConn()->getAuth() : http
->request
->auth_user_request
);
598 node
= (clientStreamNode
*)http
->client_stream
.tail
->data
;
599 clientStreamRead(node
, http
, node
->readBuffer
);
603 ClientRequestContext::hostHeaderVerify()
605 // Require a Host: header.
606 const char *host
= http
->request
->header
.getStr(Http::HdrType::HOST
);
609 // TODO: dump out the HTTP/1.1 error about missing host header.
610 // otherwise this is fine, can't forge a header value when its not even set.
611 debugs(85, 3, HERE
<< "validate skipped with no Host: header present.");
616 if (http
->request
->flags
.internal
) {
617 // TODO: kill this when URL handling allows partial URLs out of accel mode
618 // and we no longer screw with the URL just to add our internal host there
619 debugs(85, 6, HERE
<< "validate skipped due to internal composite URL.");
624 // Locate if there is a port attached, strip ready for IP lookup
625 char *portStr
= NULL
;
626 char *hostB
= xstrdup(host
);
628 if (host
[0] == '[') {
630 portStr
= strchr(hostB
, ']');
631 if (portStr
&& *(++portStr
) != ':') {
635 // Domain or IPv4 literal with port
636 portStr
= strrchr(hostB
, ':');
641 *portStr
= '\0'; // strip the ':'
642 if (*(++portStr
) != '\0') {
644 int64_t ret
= strtoll(portStr
, &end
, 10);
645 if (end
== portStr
|| *end
!= '\0' || ret
< 1 || ret
> 0xFFFF) {
646 // invalid port details. Replace the ':'
650 port
= (ret
& 0xFFFF);
654 debugs(85, 3, "validate host=" << host
<< ", port=" << port
<< ", portStr=" << (portStr
?portStr
:"NULL"));
655 if (http
->request
->flags
.intercepted
|| http
->request
->flags
.interceptTproxy
) {
656 // verify the Host: port (if any) matches the apparent destination
657 if (portStr
&& port
!= http
->getConn()->clientConnection
->local
.port()) {
658 debugs(85, 3, "FAIL on validate port " << http
->getConn()->clientConnection
->local
.port() <<
659 " matches Host: port " << port
<< " (" << portStr
<< ")");
660 hostHeaderVerifyFailed("intercepted port", portStr
);
662 // XXX: match the scheme default port against the apparent destination
664 // verify the destination DNS is one of the Host: headers IPs
665 ipcache_nbgethostbyname(host
, hostHeaderIpVerifyWrapper
, this);
667 } else if (!Config
.onoff
.hostStrictVerify
) {
668 debugs(85, 3, "validate skipped.");
670 } else if (strlen(host
) != strlen(http
->request
->url
.host())) {
671 // Verify forward-proxy requested URL domain matches the Host: header
672 debugs(85, 3, "FAIL on validate URL domain length " << http
->request
->url
.host() << " matches Host: " << host
);
673 hostHeaderVerifyFailed(host
, http
->request
->url
.host());
674 } else if (matchDomainName(host
, http
->request
->url
.host()) != 0) {
675 // Verify forward-proxy requested URL domain matches the Host: header
676 debugs(85, 3, "FAIL on validate URL domain " << http
->request
->url
.host() << " matches Host: " << host
);
677 hostHeaderVerifyFailed(host
, http
->request
->url
.host());
678 } else if (portStr
&& port
!= http
->request
->url
.port()) {
679 // Verify forward-proxy requested URL domain matches the Host: header
680 debugs(85, 3, "FAIL on validate URL port " << http
->request
->url
.port() << " matches Host: port " << portStr
);
681 hostHeaderVerifyFailed("URL port", portStr
);
682 } else if (!portStr
&& http
->request
->method
!= Http::METHOD_CONNECT
&& http
->request
->url
.port() != http
->request
->url
.getScheme().defaultPort()) {
683 // Verify forward-proxy requested URL domain matches the Host: header
684 // Special case: we don't have a default-port to check for CONNECT. Assume URL is correct.
685 debugs(85, 3, "FAIL on validate URL port " << http
->request
->url
.port() << " matches Host: default port " << http
->request
->url
.getScheme().defaultPort());
686 hostHeaderVerifyFailed("URL port", "default port");
689 debugs(85, 3, "validate passed.");
690 http
->request
->flags
.hostVerified
= true;
696 /* This is the entry point for external users of the client_side routines */
698 ClientRequestContext::clientAccessCheck()
700 #if FOLLOW_X_FORWARDED_FOR
701 if (!http
->request
->flags
.doneFollowXff() &&
702 Config
.accessList
.followXFF
&&
703 http
->request
->header
.has(Http::HdrType::X_FORWARDED_FOR
)) {
705 /* we always trust the direct client address for actual use */
706 http
->request
->indirect_client_addr
= http
->request
->client_addr
;
707 http
->request
->indirect_client_addr
.port(0);
709 /* setup the XFF iterator for processing */
710 http
->request
->x_forwarded_for_iterator
= http
->request
->header
.getList(Http::HdrType::X_FORWARDED_FOR
);
712 /* begin by checking to see if we trust direct client enough to walk XFF */
713 acl_checklist
= clientAclChecklistCreate(Config
.accessList
.followXFF
, http
);
714 acl_checklist
->nonBlockingCheck(clientFollowXForwardedForCheck
, this);
719 if (Config
.accessList
.http
) {
720 acl_checklist
= clientAclChecklistCreate(Config
.accessList
.http
, http
);
721 acl_checklist
->nonBlockingCheck(clientAccessCheckDoneWrapper
, this);
723 debugs(0, DBG_CRITICAL
, "No http_access configuration found. This will block ALL traffic");
724 clientAccessCheckDone(ACCESS_DENIED
);
729 * Identical in operation to clientAccessCheck() but performed later using different configured ACL list.
730 * The default here is to allow all. Since the earlier http_access should do a default deny all.
731 * This check is just for a last-minute denial based on adapted request headers.
734 ClientRequestContext::clientAccessCheck2()
736 if (Config
.accessList
.adapted_http
) {
737 acl_checklist
= clientAclChecklistCreate(Config
.accessList
.adapted_http
, http
);
738 acl_checklist
->nonBlockingCheck(clientAccessCheckDoneWrapper
, this);
740 debugs(85, 2, HERE
<< "No adapted_http_access configuration. default: ALLOW");
741 clientAccessCheckDone(ACCESS_ALLOWED
);
746 clientAccessCheckDoneWrapper(allow_t answer
, void *data
)
748 ClientRequestContext
*calloutContext
= (ClientRequestContext
*) data
;
750 if (!calloutContext
->httpStateIsValid())
753 calloutContext
->clientAccessCheckDone(answer
);
757 ClientRequestContext::clientAccessCheckDone(const allow_t
&answer
)
759 acl_checklist
= NULL
;
761 Http::StatusCode status
;
762 debugs(85, 2, "The request " << http
->request
->method
<< ' ' <<
763 http
->uri
<< " is " << answer
<<
764 "; last ACL checked: " << (AclMatchedName
? AclMatchedName
: "[none]"));
767 char const *proxy_auth_msg
= "<null>";
768 if (http
->getConn() != NULL
&& http
->getConn()->getAuth() != NULL
)
769 proxy_auth_msg
= http
->getConn()->getAuth()->denyMessage("<null>");
770 else if (http
->request
->auth_user_request
!= NULL
)
771 proxy_auth_msg
= http
->request
->auth_user_request
->denyMessage("<null>");
774 if (answer
!= ACCESS_ALLOWED
) {
775 // auth has a grace period where credentials can be expired but okay not to challenge.
777 /* Send an auth challenge or error */
778 // XXX: do we still need aclIsProxyAuth() ?
779 bool auth_challenge
= (answer
== ACCESS_AUTH_REQUIRED
|| aclIsProxyAuth(AclMatchedName
));
780 debugs(85, 5, "Access Denied: " << http
->uri
);
781 debugs(85, 5, "AclMatchedName = " << (AclMatchedName
? AclMatchedName
: "<null>"));
784 debugs(33, 5, "Proxy Auth Message = " << (proxy_auth_msg
? proxy_auth_msg
: "<null>"));
788 * NOTE: get page_id here, based on AclMatchedName because if
789 * USE_DELAY_POOLS is enabled, then AclMatchedName gets clobbered in
790 * the clientCreateStoreEntry() call just below. Pedro Ribeiro
793 page_id
= aclGetDenyInfoPage(&Config
.denyInfoList
, AclMatchedName
, answer
!= ACCESS_AUTH_REQUIRED
);
795 http
->logType
= LOG_TCP_DENIED
;
797 if (auth_challenge
) {
799 if (http
->request
->flags
.sslBumped
) {
800 /*SSL Bumped request, authentication is not possible*/
801 status
= Http::scForbidden
;
802 } else if (!http
->flags
.accel
) {
803 /* Proxy authorisation needed */
804 status
= Http::scProxyAuthenticationRequired
;
806 /* WWW authorisation needed */
807 status
= Http::scUnauthorized
;
810 // need auth, but not possible to do.
811 status
= Http::scForbidden
;
813 if (page_id
== ERR_NONE
)
814 page_id
= ERR_CACHE_ACCESS_DENIED
;
816 status
= Http::scForbidden
;
818 if (page_id
== ERR_NONE
)
819 page_id
= ERR_ACCESS_DENIED
;
822 Ip::Address tmpnoaddr
;
823 tmpnoaddr
.setNoAddr();
824 error
= clientBuildError(page_id
, status
,
826 http
->getConn() != NULL
? http
->getConn()->clientConnection
->remote
: tmpnoaddr
,
831 error
->auth_user_request
=
832 http
->getConn() != NULL
&& http
->getConn()->getAuth() != NULL
?
833 http
->getConn()->getAuth() : http
->request
->auth_user_request
;
836 readNextRequest
= true;
839 /* ACCESS_ALLOWED continues here ... */
841 http
->uri
= SBufToCstring(http
->request
->effectiveRequestUri());
847 ClientHttpRequest::noteAdaptationAclCheckDone(Adaptation::ServiceGroupPointer g
)
849 debugs(93,3,HERE
<< this << " adaptationAclCheckDone called");
852 Adaptation::Icap::History::Pointer ih
= request
->icapHistory();
854 if (getConn() != NULL
&& getConn()->clientConnection
!= NULL
) {
855 ih
->rfc931
= getConn()->clientConnection
->rfc931
;
857 if (getConn()->clientConnection
->isOpen()) {
858 ih
->ssluser
= sslGetUserEmail(fd_table
[getConn()->clientConnection
->fd
].ssl
.get());
862 ih
->log_uri
= log_uri
;
868 debugs(85,3, HERE
<< "no adaptation needed");
879 clientRedirectAccessCheckDone(allow_t answer
, void *data
)
881 ClientRequestContext
*context
= (ClientRequestContext
*)data
;
882 ClientHttpRequest
*http
= context
->http
;
883 context
->acl_checklist
= NULL
;
885 if (answer
== ACCESS_ALLOWED
)
886 redirectStart(http
, clientRedirectDoneWrapper
, context
);
888 Helper::Reply
const nilReply(Helper::Error
);
889 context
->clientRedirectDone(nilReply
);
894 ClientRequestContext::clientRedirectStart()
896 debugs(33, 5, HERE
<< "'" << http
->uri
<< "'");
897 http
->al
->syncNotes(http
->request
);
898 if (Config
.accessList
.redirector
) {
899 acl_checklist
= clientAclChecklistCreate(Config
.accessList
.redirector
, http
);
900 acl_checklist
->nonBlockingCheck(clientRedirectAccessCheckDone
, this);
902 redirectStart(http
, clientRedirectDoneWrapper
, this);
906 * This methods handles Access checks result of StoreId access list.
907 * Will handle as "ERR" (no change) in a case Access is not allowed.
910 clientStoreIdAccessCheckDone(allow_t answer
, void *data
)
912 ClientRequestContext
*context
= static_cast<ClientRequestContext
*>(data
);
913 ClientHttpRequest
*http
= context
->http
;
914 context
->acl_checklist
= NULL
;
916 if (answer
== ACCESS_ALLOWED
)
917 storeIdStart(http
, clientStoreIdDoneWrapper
, context
);
919 debugs(85, 3, "access denied expected ERR reply handling: " << answer
);
920 Helper::Reply
const nilReply(Helper::Error
);
921 context
->clientStoreIdDone(nilReply
);
926 * Start locating an alternative storeage ID string (if any) from admin
927 * configured helper program. This is an asynchronous operation terminating in
928 * ClientRequestContext::clientStoreIdDone() when completed.
931 ClientRequestContext::clientStoreIdStart()
933 debugs(33, 5,"'" << http
->uri
<< "'");
935 if (Config
.accessList
.store_id
) {
936 acl_checklist
= clientAclChecklistCreate(Config
.accessList
.store_id
, http
);
937 acl_checklist
->nonBlockingCheck(clientStoreIdAccessCheckDone
, this);
939 storeIdStart(http
, clientStoreIdDoneWrapper
, this);
943 clientHierarchical(ClientHttpRequest
* http
)
945 HttpRequest
*request
= http
->request
;
946 HttpRequestMethod method
= request
->method
;
948 // intercepted requests MUST NOT (yet) be sent to peers unless verified
949 if (!request
->flags
.hostVerified
&& (request
->flags
.intercepted
|| request
->flags
.interceptTproxy
))
953 * IMS needs a private key, so we can use the hierarchy for IMS only if our
954 * neighbors support private keys
957 if (request
->flags
.ims
&& !neighbors_do_private_keys
)
961 * This is incorrect: authenticating requests can be sent via a hierarchy
962 * (they can even be cached if the correct headers are set on the reply)
964 if (request
->flags
.auth
)
967 if (method
== Http::METHOD_TRACE
)
970 if (method
!= Http::METHOD_GET
)
973 if (request
->flags
.loopDetected
)
976 if (request
->url
.getScheme() == AnyP::PROTO_HTTP
)
977 return method
.respMaybeCacheable();
979 if (request
->url
.getScheme() == AnyP::PROTO_GOPHER
)
980 return gopherCachable(request
);
982 if (request
->url
.getScheme() == AnyP::PROTO_CACHE_OBJECT
)
989 clientCheckPinning(ClientHttpRequest
* http
)
991 HttpRequest
*request
= http
->request
;
992 HttpHeader
*req_hdr
= &request
->header
;
993 ConnStateData
*http_conn
= http
->getConn();
995 /* Internal requests such as those from ESI includes may be without
996 * a client connection
1001 request
->flags
.connectionAuthDisabled
= http_conn
->port
->connection_auth_disabled
;
1002 if (!request
->flags
.connectionAuthDisabled
) {
1003 if (Comm::IsConnOpen(http_conn
->pinning
.serverConnection
)) {
1004 if (http_conn
->pinning
.auth
) {
1005 request
->flags
.connectionAuth
= true;
1006 request
->flags
.auth
= true;
1008 request
->flags
.connectionProxyAuth
= true;
1010 // These should already be linked correctly.
1011 assert(request
->clientConnectionManager
== http_conn
);
1015 /* check if connection auth is used, and flag as candidate for pinning
1017 * Note: we may need to set flags.connectionAuth even if the connection
1018 * is already pinned if it was pinned earlier due to proxy auth
1020 if (!request
->flags
.connectionAuth
) {
1021 if (req_hdr
->has(Http::HdrType::AUTHORIZATION
) || req_hdr
->has(Http::HdrType::PROXY_AUTHORIZATION
)) {
1022 HttpHeaderPos pos
= HttpHeaderInitPos
;
1025 while ((e
= req_hdr
->getEntry(&pos
))) {
1026 if (e
->id
== Http::HdrType::AUTHORIZATION
|| e
->id
== Http::HdrType::PROXY_AUTHORIZATION
) {
1027 const char *value
= e
->value
.rawBuf();
1028 if (strncasecmp(value
, "NTLM ", 5) == 0
1030 strncasecmp(value
, "Negotiate ", 10) == 0
1032 strncasecmp(value
, "Kerberos ", 9) == 0) {
1033 if (e
->id
== Http::HdrType::AUTHORIZATION
) {
1034 request
->flags
.connectionAuth
= true;
1037 request
->flags
.connectionProxyAuth
= true;
1043 if (may_pin
&& !request
->pinnedConnection()) {
1044 // These should already be linked correctly. Just need the ServerConnection to pinn.
1045 assert(request
->clientConnectionManager
== http_conn
);
1052 clientInterpretRequestHeaders(ClientHttpRequest
* http
)
1054 HttpRequest
*request
= http
->request
;
1055 HttpHeader
*req_hdr
= &request
->header
;
1056 bool no_cache
= false;
1058 request
->imslen
= -1;
1059 request
->ims
= req_hdr
->getTime(Http::HdrType::IF_MODIFIED_SINCE
);
1061 if (request
->ims
> 0)
1062 request
->flags
.ims
= true;
1064 if (!request
->flags
.ignoreCc
) {
1065 if (request
->cache_control
) {
1066 if (request
->cache_control
->hasNoCache())
1069 // RFC 2616: treat Pragma:no-cache as if it was Cache-Control:no-cache when Cache-Control is missing
1070 } else if (req_hdr
->has(Http::HdrType::PRAGMA
))
1071 no_cache
= req_hdr
->hasListMember(Http::HdrType::PRAGMA
,"no-cache",',');
1074 if (request
->method
== Http::METHOD_OTHER
) {
1079 #if USE_HTTP_VIOLATIONS
1081 if (Config
.onoff
.reload_into_ims
)
1082 request
->flags
.nocacheHack
= true;
1083 else if (refresh_nocache_hack
)
1084 request
->flags
.nocacheHack
= true;
1088 request
->flags
.noCache
= true;
1091 /* ignore range header in non-GETs or non-HEADs */
1092 if (request
->method
== Http::METHOD_GET
|| request
->method
== Http::METHOD_HEAD
) {
1093 // XXX: initialize if we got here without HttpRequest::parseHeader()
1094 if (!request
->range
)
1095 request
->range
= req_hdr
->getRange();
1097 if (request
->range
) {
1098 request
->flags
.isRanged
= true;
1099 clientStreamNode
*node
= (clientStreamNode
*)http
->client_stream
.tail
->data
;
1100 /* XXX: This is suboptimal. We should give the stream the range set,
1101 * and thereby let the top of the stream set the offset when the
1102 * size becomes known. As it is, we will end up requesting from 0
1103 * for evey -X range specification.
1104 * RBC - this may be somewhat wrong. We should probably set the range
1105 * iter up at this point.
1107 node
->readBuffer
.offset
= request
->range
->lowestOffset(0);
1108 http
->range_iter
.pos
= request
->range
->begin();
1109 http
->range_iter
.end
= request
->range
->end();
1110 http
->range_iter
.valid
= true;
1114 /* Only HEAD and GET requests permit a Range or Request-Range header.
1115 * If these headers appear on any other type of request, delete them now.
1118 req_hdr
->delById(Http::HdrType::RANGE
);
1119 req_hdr
->delById(Http::HdrType::REQUEST_RANGE
);
1120 request
->ignoreRange("neither HEAD nor GET");
1123 if (req_hdr
->has(Http::HdrType::AUTHORIZATION
))
1124 request
->flags
.auth
= true;
1126 clientCheckPinning(http
);
1128 if (!request
->url
.userInfo().isEmpty())
1129 request
->flags
.auth
= true;
1131 if (req_hdr
->has(Http::HdrType::VIA
)) {
1132 String s
= req_hdr
->getList(Http::HdrType::VIA
);
1134 * ThisCache cannot be a member of Via header, "1.1 ThisCache" can.
1135 * Note ThisCache2 has a space prepended to the hostname so we don't
1136 * accidentally match super-domains.
1139 if (strListIsSubstr(&s
, ThisCache2
, ',')) {
1140 debugObj(33, 1, "WARNING: Forwarding loop detected for:\n",
1141 request
, (ObjPackMethod
) & httpRequestPack
);
1142 request
->flags
.loopDetected
= true;
1146 fvdbCountVia(s
.termedBuf());
1155 if (req_hdr
->has(Http::HdrType::X_FORWARDED_FOR
)) {
1156 String s
= req_hdr
->getList(Http::HdrType::X_FORWARDED_FOR
);
1157 fvdbCountForw(s
.termedBuf());
1163 request
->flags
.cachable
= http
->request
->maybeCacheable();
1165 if (clientHierarchical(http
))
1166 request
->flags
.hierarchical
= true;
1168 debugs(85, 5, "clientInterpretRequestHeaders: REQ_NOCACHE = " <<
1169 (request
->flags
.noCache
? "SET" : "NOT SET"));
1170 debugs(85, 5, "clientInterpretRequestHeaders: REQ_CACHABLE = " <<
1171 (request
->flags
.cachable
? "SET" : "NOT SET"));
1172 debugs(85, 5, "clientInterpretRequestHeaders: REQ_HIERARCHICAL = " <<
1173 (request
->flags
.hierarchical
? "SET" : "NOT SET"));
1178 clientRedirectDoneWrapper(void *data
, const Helper::Reply
&result
)
1180 ClientRequestContext
*calloutContext
= (ClientRequestContext
*)data
;
1182 if (!calloutContext
->httpStateIsValid())
1185 calloutContext
->clientRedirectDone(result
);
1189 clientStoreIdDoneWrapper(void *data
, const Helper::Reply
&result
)
1191 ClientRequestContext
*calloutContext
= (ClientRequestContext
*)data
;
1193 if (!calloutContext
->httpStateIsValid())
1196 calloutContext
->clientStoreIdDone(result
);
1200 ClientRequestContext::clientRedirectDone(const Helper::Reply
&reply
)
1202 HttpRequest
*old_request
= http
->request
;
1203 debugs(85, 5, HERE
<< "'" << http
->uri
<< "' result=" << reply
);
1204 assert(redirect_state
== REDIRECT_PENDING
);
1205 redirect_state
= REDIRECT_DONE
;
1207 // Put helper response Notes into the transaction state record (ALE) eventually
1208 // do it early to ensure that no matter what the outcome the notes are present.
1210 http
->al
->syncNotes(old_request
);
1212 UpdateRequestNotes(http
->getConn(), *old_request
, reply
.notes
);
1214 switch (reply
.result
) {
1215 case Helper::TimedOut
:
1216 if (Config
.onUrlRewriteTimeout
.action
!= toutActBypass
) {
1217 http
->calloutsError(ERR_GATEWAY_FAILURE
, ERR_DETAIL_REDIRECTOR_TIMEDOUT
);
1218 debugs(85, DBG_IMPORTANT
, "ERROR: URL rewrite helper: Timedout");
1222 case Helper::Unknown
:
1224 // Handler in redirect.cc should have already mapped Unknown
1225 // IF it contained valid entry for the old URL-rewrite helper protocol
1226 debugs(85, DBG_IMPORTANT
, "ERROR: URL rewrite helper returned invalid result code. Wrong helper? " << reply
);
1229 case Helper::BrokenHelper
:
1230 debugs(85, DBG_IMPORTANT
, "ERROR: URL rewrite helper: " << reply
);
1234 // no change to be done.
1237 case Helper::Okay
: {
1238 // #1: redirect with a specific status code OK status=NNN url="..."
1239 // #2: redirect with a default status code OK url="..."
1240 // #3: re-write the URL OK rewrite-url="..."
1242 const char *statusNote
= reply
.notes
.findFirst("status");
1243 const char *urlNote
= reply
.notes
.findFirst("url");
1245 if (urlNote
!= NULL
) {
1246 // HTTP protocol redirect to be done.
1248 // TODO: change default redirect status for appropriate requests
1249 // Squid defaults to 302 status for now for better compatibility with old clients.
1250 // HTTP/1.0 client should get 302 (Http::scFound)
1251 // HTTP/1.1 client contacting reverse-proxy should get 307 (Http::scTemporaryRedirect)
1252 // HTTP/1.1 client being diverted by forward-proxy should get 303 (Http::scSeeOther)
1253 Http::StatusCode status
= Http::scFound
;
1254 if (statusNote
!= NULL
) {
1255 const char * result
= statusNote
;
1256 status
= static_cast<Http::StatusCode
>(atoi(result
));
1259 if (status
== Http::scMovedPermanently
1260 || status
== Http::scFound
1261 || status
== Http::scSeeOther
1262 || status
== Http::scPermanentRedirect
1263 || status
== Http::scTemporaryRedirect
) {
1264 http
->redirect
.status
= status
;
1265 http
->redirect
.location
= xstrdup(urlNote
);
1266 // TODO: validate the URL produced here is RFC 2616 compliant absolute URI
1268 debugs(85, DBG_CRITICAL
, "ERROR: URL-rewrite produces invalid " << status
<< " redirect Location: " << urlNote
);
1271 // URL-rewrite wanted. Ew.
1272 urlNote
= reply
.notes
.findFirst("rewrite-url");
1274 // prevent broken helpers causing too much damage. If old URL == new URL skip the re-write.
1275 if (urlNote
!= NULL
&& strcmp(urlNote
, http
->uri
)) {
1276 // XXX: validate the URL properly *without* generating a whole new request object right here.
1277 // XXX: the clone() should be done only AFTER we know the new URL is valid.
1278 HttpRequest
*new_request
= old_request
->clone();
1279 if (urlParse(old_request
->method
, const_cast<char*>(urlNote
), *new_request
)) {
1280 debugs(61, 2, "URL-rewriter diverts URL from " << old_request
->effectiveRequestUri() << " to " << new_request
->effectiveRequestUri());
1282 // update the new request to flag the re-writing was done on it
1283 new_request
->flags
.redirected
= true;
1285 // unlink bodypipe from the old request. Not needed there any longer.
1286 if (old_request
->body_pipe
!= NULL
) {
1287 old_request
->body_pipe
= NULL
;
1288 debugs(61,2, HERE
<< "URL-rewriter diverts body_pipe " << new_request
->body_pipe
<<
1289 " from request " << old_request
<< " to " << new_request
);
1292 // update the current working ClientHttpRequest fields
1294 http
->uri
= SBufToCstring(new_request
->effectiveRequestUri());
1295 HTTPMSGUNLOCK(old_request
);
1296 http
->request
= new_request
;
1297 HTTPMSGLOCK(http
->request
);
1299 debugs(85, DBG_CRITICAL
, "ERROR: URL-rewrite produces invalid request: " <<
1300 old_request
->method
<< " " << urlNote
<< " " << old_request
->http_ver
);
1309 /* FIXME PIPELINE: This is innacurate during pipelining */
1311 if (http
->getConn() != NULL
&& Comm::IsConnOpen(http
->getConn()->clientConnection
))
1312 fd_note(http
->getConn()->clientConnection
->fd
, http
->uri
);
1320 * This method handles the different replies from StoreID helper.
1323 ClientRequestContext::clientStoreIdDone(const Helper::Reply
&reply
)
1325 HttpRequest
*old_request
= http
->request
;
1326 debugs(85, 5, "'" << http
->uri
<< "' result=" << reply
);
1327 assert(store_id_state
== REDIRECT_PENDING
);
1328 store_id_state
= REDIRECT_DONE
;
1330 // Put helper response Notes into the transaction state record (ALE) eventually
1331 // do it early to ensure that no matter what the outcome the notes are present.
1333 http
->al
->syncNotes(old_request
);
1335 UpdateRequestNotes(http
->getConn(), *old_request
, reply
.notes
);
1337 switch (reply
.result
) {
1338 case Helper::Unknown
:
1340 // Handler in redirect.cc should have already mapped Unknown
1341 // IF it contained valid entry for the old helper protocol
1342 debugs(85, DBG_IMPORTANT
, "ERROR: storeID helper returned invalid result code. Wrong helper? " << reply
);
1345 case Helper::TimedOut
:
1346 // Timeouts for storeID are not implemented
1347 case Helper::BrokenHelper
:
1348 debugs(85, DBG_IMPORTANT
, "ERROR: storeID helper: " << reply
);
1352 // no change to be done.
1355 case Helper::Okay
: {
1356 const char *urlNote
= reply
.notes
.findFirst("store-id");
1358 // prevent broken helpers causing too much damage. If old URL == new URL skip the re-write.
1359 if (urlNote
!= NULL
&& strcmp(urlNote
, http
->uri
) ) {
1360 // Debug section required for some very specific cases.
1361 debugs(85, 9, "Setting storeID with: " << urlNote
);
1362 http
->request
->store_id
= urlNote
;
1363 http
->store_id
= urlNote
;
1372 /** Test cache allow/deny configuration
1373 * Sets flags.cachable=1 if caching is not denied.
1376 ClientRequestContext::checkNoCache()
1378 if (Config
.accessList
.noCache
) {
1379 acl_checklist
= clientAclChecklistCreate(Config
.accessList
.noCache
, http
);
1380 acl_checklist
->nonBlockingCheck(checkNoCacheDoneWrapper
, this);
1382 /* unless otherwise specified, we try to cache. */
1383 checkNoCacheDone(ACCESS_ALLOWED
);
1388 checkNoCacheDoneWrapper(allow_t answer
, void *data
)
1390 ClientRequestContext
*calloutContext
= (ClientRequestContext
*) data
;
1392 if (!calloutContext
->httpStateIsValid())
1395 calloutContext
->checkNoCacheDone(answer
);
1399 ClientRequestContext::checkNoCacheDone(const allow_t
&answer
)
1401 acl_checklist
= NULL
;
1402 if (answer
== ACCESS_DENIED
) {
1403 http
->request
->flags
.noCache
= true; // dont read reply from cache
1404 http
->request
->flags
.cachable
= false; // dont store reply into cache
1411 ClientRequestContext::sslBumpAccessCheck()
1413 if (!http
->getConn()) {
1414 http
->al
->ssl
.bumpMode
= Ssl::bumpEnd
; // SslBump does not apply; log -
1418 const Ssl::BumpMode bumpMode
= http
->getConn()->sslBumpMode
;
1419 if (http
->request
->flags
.forceTunnel
) {
1420 debugs(85, 5, "not needed; already decided to tunnel " << http
->getConn());
1421 if (bumpMode
!= Ssl::bumpEnd
)
1422 http
->al
->ssl
.bumpMode
= bumpMode
; // inherited from bumped connection
1426 // If SSL connection tunneling or bumping decision has been made, obey it.
1427 if (bumpMode
!= Ssl::bumpEnd
) {
1428 debugs(85, 5, HERE
<< "SslBump already decided (" << bumpMode
<<
1429 "), " << "ignoring ssl_bump for " << http
->getConn());
1431 // We need the following "if" for transparently bumped TLS connection,
1432 // because in this case we are running ssl_bump access list before
1433 // the doCallouts runs. It can be removed after the bug #4340 fixed.
1434 // We do not want to proceed to bumping steps:
1435 // - if the TLS connection with the client is already established
1436 // because we are accepting normal HTTP requests on TLS port,
1437 // or because of the client-first bumping mode
1438 // - When the bumping is already started
1439 if (!http
->getConn()->switchedToHttps() &&
1440 !http
->getConn()->serverBump())
1441 http
->sslBumpNeed(bumpMode
); // for processRequest() to bump if needed and not already bumped
1442 http
->al
->ssl
.bumpMode
= bumpMode
; // inherited from bumped connection
1446 // If we have not decided yet, decide whether to bump now.
1448 // Bumping here can only start with a CONNECT request on a bumping port
1449 // (bumping of intercepted SSL conns is decided before we get 1st request).
1450 // We also do not bump redirected CONNECT requests.
1451 if (http
->request
->method
!= Http::METHOD_CONNECT
|| http
->redirect
.status
||
1452 !Config
.accessList
.ssl_bump
||
1453 !http
->getConn()->port
->flags
.tunnelSslBumping
) {
1454 http
->al
->ssl
.bumpMode
= Ssl::bumpEnd
; // SslBump does not apply; log -
1455 debugs(85, 5, HERE
<< "cannot SslBump this request");
1459 // Do not bump during authentication: clients would not proxy-authenticate
1460 // if we delay a 407 response and respond with 200 OK to CONNECT.
1461 if (error
&& error
->httpStatus
== Http::scProxyAuthenticationRequired
) {
1462 http
->al
->ssl
.bumpMode
= Ssl::bumpEnd
; // SslBump does not apply; log -
1463 debugs(85, 5, HERE
<< "no SslBump during proxy authentication");
1468 debugs(85, 5, "SslBump applies. Force bump action on error " << errorTypeName(error
->type
));
1469 http
->sslBumpNeed(Ssl::bumpBump
);
1470 http
->al
->ssl
.bumpMode
= Ssl::bumpBump
;
1474 debugs(85, 5, HERE
<< "SslBump possible, checking ACL");
1476 ACLFilledChecklist
*aclChecklist
= clientAclChecklistCreate(Config
.accessList
.ssl_bump
, http
);
1477 aclChecklist
->nonBlockingCheck(sslBumpAccessCheckDoneWrapper
, this);
1482 * A wrapper function to use the ClientRequestContext::sslBumpAccessCheckDone method
1483 * as ACLFilledChecklist callback
1486 sslBumpAccessCheckDoneWrapper(allow_t answer
, void *data
)
1488 ClientRequestContext
*calloutContext
= static_cast<ClientRequestContext
*>(data
);
1490 if (!calloutContext
->httpStateIsValid())
1492 calloutContext
->sslBumpAccessCheckDone(answer
);
1496 ClientRequestContext::sslBumpAccessCheckDone(const allow_t
&answer
)
1498 if (!httpStateIsValid())
1501 const Ssl::BumpMode bumpMode
= answer
== ACCESS_ALLOWED
?
1502 static_cast<Ssl::BumpMode
>(answer
.kind
) : Ssl::bumpSplice
;
1503 http
->sslBumpNeed(bumpMode
); // for processRequest() to bump if needed
1504 http
->al
->ssl
.bumpMode
= bumpMode
; // for logging
1506 if (bumpMode
== Ssl::bumpTerminate
) {
1507 const Comm::ConnectionPointer clientConn
= http
->getConn() ? http
->getConn()->clientConnection
: nullptr;
1508 if (Comm::IsConnOpen(clientConn
)) {
1509 debugs(85, 3, "closing after Ssl::bumpTerminate ");
1510 clientConn
->close();
1520 * Identify requests that do not go through the store and client side stream
1521 * and forward them to the appropriate location. All other requests, request
1525 ClientHttpRequest::processRequest()
1527 debugs(85, 4, request
->method
<< ' ' << uri
);
1529 const bool untouchedConnect
= request
->method
== Http::METHOD_CONNECT
&& !redirect
.status
;
1532 if (untouchedConnect
&& sslBumpNeeded()) {
1533 assert(!request
->flags
.forceTunnel
);
1539 if (untouchedConnect
|| request
->flags
.forceTunnel
) {
1540 getConn()->stopReading(); // tunnels read for themselves
1549 ClientHttpRequest::httpStart()
1551 PROF_start(httpStart
);
1552 logType
= LOG_TAG_NONE
;
1553 debugs(85, 4, logType
.c_str() << " for '" << uri
<< "'");
1555 /* no one should have touched this */
1556 assert(out
.offset
== 0);
1557 /* Use the Stream Luke */
1558 clientStreamNode
*node
= (clientStreamNode
*)client_stream
.tail
->data
;
1559 clientStreamRead(node
, this, node
->readBuffer
);
1560 PROF_stop(httpStart
);
1566 ClientHttpRequest::sslBumpNeed(Ssl::BumpMode mode
)
1568 debugs(83, 3, HERE
<< "sslBump required: "<< Ssl::bumpMode(mode
));
1569 sslBumpNeed_
= mode
;
1572 // called when comm_write has completed
1574 SslBumpEstablish(const Comm::ConnectionPointer
&, char *, size_t, Comm::Flag errflag
, int, void *data
)
1576 ClientHttpRequest
*r
= static_cast<ClientHttpRequest
*>(data
);
1577 debugs(85, 5, HERE
<< "responded to CONNECT: " << r
<< " ? " << errflag
);
1579 assert(r
&& cbdataReferenceValid(r
));
1580 r
->sslBumpEstablish(errflag
);
1584 ClientHttpRequest::sslBumpEstablish(Comm::Flag errflag
)
1586 // Bail out quickly on Comm::ERR_CLOSING - close handlers will tidy up
1587 if (errflag
== Comm::ERR_CLOSING
)
1591 debugs(85, 3, HERE
<< "CONNECT response failure in SslBump: " << errflag
);
1592 getConn()->clientConnection
->close();
1596 // We lack HttpReply which logRequest() uses to log the status code.
1597 // TODO: Use HttpReply instead of the "200 Connection established" string.
1598 al
->http
.code
= 200;
1601 // Preserve authentication info for the ssl-bumped request
1602 if (request
->auth_user_request
!= NULL
)
1603 getConn()->setAuth(request
->auth_user_request
, "SSL-bumped CONNECT");
1606 assert(sslBumpNeeded());
1607 getConn()->switchToHttps(request
, sslBumpNeed_
);
1611 ClientHttpRequest::sslBumpStart()
1613 debugs(85, 5, HERE
<< "Confirming " << Ssl::bumpMode(sslBumpNeed_
) <<
1614 "-bumped CONNECT tunnel on FD " << getConn()->clientConnection
);
1615 getConn()->sslBumpMode
= sslBumpNeed_
;
1617 AsyncCall::Pointer bumpCall
= commCbCall(85, 5, "ClientSocketContext::sslBumpEstablish",
1618 CommIoCbPtrFun(&SslBumpEstablish
, this));
1620 if (request
->flags
.interceptTproxy
|| request
->flags
.intercepted
) {
1621 CommIoCbParams
¶ms
= GetCommParams
<CommIoCbParams
>(bumpCall
);
1622 params
.flag
= Comm::OK
;
1623 params
.conn
= getConn()->clientConnection
;
1624 ScheduleCallHere(bumpCall
);
1628 // send an HTTP 200 response to kick client SSL negotiation
1629 // TODO: Unify with tunnel.cc and add a Server(?) header
1630 static const char *const conn_established
= "HTTP/1.1 200 Connection established\r\n\r\n";
1631 Comm::Write(getConn()->clientConnection
, conn_established
, strlen(conn_established
), bumpCall
, NULL
);
1637 ClientHttpRequest::gotEnough() const
1639 /** TODO: should be querying the stream. */
1640 int64_t contentLength
=
1641 memObject()->getReply()->bodySize(request
->method
);
1642 assert(contentLength
>= 0);
1644 if (out
.offset
< contentLength
)
1651 ClientHttpRequest::storeEntry(StoreEntry
*newEntry
)
1657 ClientHttpRequest::loggingEntry(StoreEntry
*newEntry
)
1660 loggingEntry_
->unlock("ClientHttpRequest::loggingEntry");
1662 loggingEntry_
= newEntry
;
1665 loggingEntry_
->lock("ClientHttpRequest::loggingEntry");
1669 * doCallouts() - This function controls the order of "callout"
1670 * executions, including non-blocking access control checks, the
1671 * redirector, and ICAP. Previously, these callouts were chained
1672 * together such that "clientAccessCheckDone()" would call
1673 * "clientRedirectStart()" and so on.
1675 * The ClientRequestContext (aka calloutContext) class holds certain
1676 * state data for the callout/callback operations. Previously
1677 * ClientHttpRequest would sort of hand off control to ClientRequestContext
1678 * for a short time. ClientRequestContext would then delete itself
1679 * and pass control back to ClientHttpRequest when all callouts
1682 * This caused some problems for ICAP because we want to make the
1683 * ICAP callout after checking ACLs, but before checking the no_cache
1684 * list. We can't stuff the ICAP state into the ClientRequestContext
1685 * class because we still need the ICAP state after ClientRequestContext
1688 * Note that ClientRequestContext is created before the first call
1691 * If one of the callouts notices that ClientHttpRequest is no
1692 * longer valid, it should call cbdataReferenceDone() so that
1693 * ClientHttpRequest's reference count goes to zero and it will get
1694 * deleted. ClientHttpRequest will then delete ClientRequestContext.
1696 * Note that we set the _done flags here before actually starting
1697 * the callout. This is strictly for convenience.
1700 tos_t
aclMapTOS (acl_tos
* head
, ACLChecklist
* ch
);
1701 nfmark_t
aclMapNfmark (acl_nfmark
* head
, ACLChecklist
* ch
);
1704 ClientHttpRequest::doCallouts()
1706 assert(calloutContext
);
1708 auto &ale
= calloutContext
->http
->al
;
1709 /*Save the original request for logging purposes*/
1710 if (!ale
->request
) {
1711 ale
->request
= request
;
1712 HTTPMSGLOCK(ale
->request
);
1714 // Make the previously set client connection ID available as annotation.
1715 if (ConnStateData
*csd
= calloutContext
->http
->getConn()) {
1716 if (!csd
->notes()->empty())
1717 calloutContext
->http
->request
->notes()->appendNewOnly(csd
->notes().getRaw());
1719 ale
->syncNotes(calloutContext
->http
->request
);
1722 if (!calloutContext
->error
) {
1723 // CVE-2009-0801: verify the Host: header is consistent with other known details.
1724 if (!calloutContext
->host_header_verify_done
) {
1725 debugs(83, 3, HERE
<< "Doing calloutContext->hostHeaderVerify()");
1726 calloutContext
->host_header_verify_done
= true;
1727 calloutContext
->hostHeaderVerify();
1731 if (!calloutContext
->http_access_done
) {
1732 debugs(83, 3, HERE
<< "Doing calloutContext->clientAccessCheck()");
1733 calloutContext
->http_access_done
= true;
1734 calloutContext
->clientAccessCheck();
1739 if (!calloutContext
->adaptation_acl_check_done
) {
1740 calloutContext
->adaptation_acl_check_done
= true;
1741 if (Adaptation::AccessCheck::Start(
1742 Adaptation::methodReqmod
, Adaptation::pointPreCache
,
1743 request
, NULL
, calloutContext
->http
->al
, this))
1744 return; // will call callback
1748 if (!calloutContext
->redirect_done
) {
1749 calloutContext
->redirect_done
= true;
1751 if (Config
.Program
.redirect
) {
1752 debugs(83, 3, HERE
<< "Doing calloutContext->clientRedirectStart()");
1753 calloutContext
->redirect_state
= REDIRECT_PENDING
;
1754 calloutContext
->clientRedirectStart();
1759 if (!calloutContext
->adapted_http_access_done
) {
1760 debugs(83, 3, HERE
<< "Doing calloutContext->clientAccessCheck2()");
1761 calloutContext
->adapted_http_access_done
= true;
1762 calloutContext
->clientAccessCheck2();
1766 if (!calloutContext
->store_id_done
) {
1767 calloutContext
->store_id_done
= true;
1769 if (Config
.Program
.store_id
) {
1770 debugs(83, 3,"Doing calloutContext->clientStoreIdStart()");
1771 calloutContext
->store_id_state
= REDIRECT_PENDING
;
1772 calloutContext
->clientStoreIdStart();
1777 if (!calloutContext
->interpreted_req_hdrs
) {
1778 debugs(83, 3, HERE
<< "Doing clientInterpretRequestHeaders()");
1779 calloutContext
->interpreted_req_hdrs
= 1;
1780 clientInterpretRequestHeaders(this);
1783 if (!calloutContext
->no_cache_done
) {
1784 calloutContext
->no_cache_done
= true;
1786 if (Config
.accessList
.noCache
&& request
->flags
.cachable
) {
1787 debugs(83, 3, HERE
<< "Doing calloutContext->checkNoCache()");
1788 calloutContext
->checkNoCache();
1792 } // if !calloutContext->error
1794 if (!calloutContext
->tosToClientDone
) {
1795 calloutContext
->tosToClientDone
= true;
1796 if (getConn() != NULL
&& Comm::IsConnOpen(getConn()->clientConnection
)) {
1797 ACLFilledChecklist
ch(NULL
, request
, NULL
);
1798 ch
.src_addr
= request
->client_addr
;
1799 ch
.my_addr
= request
->my_addr
;
1800 tos_t tos
= aclMapTOS(Ip::Qos::TheConfig
.tosToClient
, &ch
);
1802 Ip::Qos::setSockTos(getConn()->clientConnection
, tos
);
1806 if (!calloutContext
->nfmarkToClientDone
) {
1807 calloutContext
->nfmarkToClientDone
= true;
1808 if (getConn() != NULL
&& Comm::IsConnOpen(getConn()->clientConnection
)) {
1809 ACLFilledChecklist
ch(NULL
, request
, NULL
);
1810 ch
.src_addr
= request
->client_addr
;
1811 ch
.my_addr
= request
->my_addr
;
1812 nfmark_t mark
= aclMapNfmark(Ip::Qos::TheConfig
.nfmarkToClient
, &ch
);
1814 Ip::Qos::setSockNfmark(getConn()->clientConnection
, mark
);
1819 // Even with calloutContext->error, we call sslBumpAccessCheck() to decide
1820 // whether SslBump applies to this transaction. If it applies, we will
1821 // attempt to bump the client to serve the error.
1822 if (!calloutContext
->sslBumpCheckDone
) {
1823 calloutContext
->sslBumpCheckDone
= true;
1824 if (calloutContext
->sslBumpAccessCheck())
1826 /* else no ssl bump required*/
1830 if (calloutContext
->error
) {
1831 // XXX: prformance regression. c_str() reallocates
1832 SBuf
storeUriBuf(request
->storeId());
1833 const char *storeUri
= storeUriBuf
.c_str();
1834 StoreEntry
*e
= storeCreateEntry(storeUri
, storeUri
, request
->flags
, request
->method
);
1836 if (sslBumpNeeded()) {
1837 // We have to serve an error, so bump the client first.
1838 sslBumpNeed(Ssl::bumpClientFirst
);
1839 // set final error but delay sending until we bump
1840 Ssl::ServerBump
*srvBump
= new Ssl::ServerBump(request
, e
, Ssl::bumpClientFirst
);
1841 errorAppendEntry(e
, calloutContext
->error
);
1842 calloutContext
->error
= NULL
;
1843 getConn()->setServerBump(srvBump
);
1844 e
->unlock("ClientHttpRequest::doCallouts+sslBumpNeeded");
1848 // send the error to the client now
1849 clientStreamNode
*node
= (clientStreamNode
*)client_stream
.tail
->prev
->data
;
1850 clientReplyContext
*repContext
= dynamic_cast<clientReplyContext
*>(node
->data
.getRaw());
1851 assert (repContext
);
1852 repContext
->setReplyToStoreEntry(e
, "immediate SslBump error");
1853 errorAppendEntry(e
, calloutContext
->error
);
1854 calloutContext
->error
= NULL
;
1855 if (calloutContext
->readNextRequest
&& getConn())
1856 getConn()->flags
.readMore
= true; // resume any pipeline reads.
1857 node
= (clientStreamNode
*)client_stream
.tail
->data
;
1858 clientStreamRead(node
, this, node
->readBuffer
);
1859 e
->unlock("ClientHttpRequest::doCallouts-sslBumpNeeded");
1864 cbdataReferenceDone(calloutContext
->http
);
1865 delete calloutContext
;
1866 calloutContext
= NULL
;
1869 headersLog(0, 1, request
->method
, request
);
1872 debugs(83, 3, HERE
<< "calling processRequest()");
1876 Adaptation::Icap::History::Pointer ih
= request
->icapHistory();
1878 ih
->logType
= logType
;
1883 /// Initiate an asynchronous adaptation transaction which will call us back.
1885 ClientHttpRequest::startAdaptation(const Adaptation::ServiceGroupPointer
&g
)
1887 debugs(85, 3, HERE
<< "adaptation needed for " << this);
1888 assert(!virginHeadSource
);
1889 assert(!adaptedBodySource
);
1890 virginHeadSource
= initiateAdaptation(
1891 new Adaptation::Iterator(request
, NULL
, al
, g
));
1893 // we could try to guess whether we can bypass this adaptation
1894 // initiation failure, but it should not really happen
1895 Must(initiated(virginHeadSource
));
1899 ClientHttpRequest::noteAdaptationAnswer(const Adaptation::Answer
&answer
)
1901 assert(cbdataReferenceValid(this)); // indicates bug
1902 clearAdaptation(virginHeadSource
);
1903 assert(!adaptedBodySource
);
1905 switch (answer
.kind
) {
1906 case Adaptation::Answer::akForward
:
1907 handleAdaptedHeader(const_cast<Http::Message
*>(answer
.message
.getRaw()));
1910 case Adaptation::Answer::akBlock
:
1911 handleAdaptationBlock(answer
);
1914 case Adaptation::Answer::akError
:
1915 handleAdaptationFailure(ERR_DETAIL_CLT_REQMOD_ABORT
, !answer
.final
);
1921 ClientHttpRequest::handleAdaptedHeader(Http::Message
*msg
)
1925 if (HttpRequest
*new_req
= dynamic_cast<HttpRequest
*>(msg
)) {
1927 * Replace the old request with the new request.
1929 HTTPMSGUNLOCK(request
);
1931 HTTPMSGLOCK(request
);
1933 // update the new message to flag whether URL re-writing was done on it
1934 if (request
->effectiveRequestUri().cmp(uri
) != 0)
1935 request
->flags
.redirected
= 1;
1938 * Store the new URI for logging
1941 uri
= SBufToCstring(request
->effectiveRequestUri());
1942 setLogUri(this, urlCanonicalClean(request
));
1943 assert(request
->method
.id());
1944 } else if (HttpReply
*new_rep
= dynamic_cast<HttpReply
*>(msg
)) {
1945 debugs(85,3,HERE
<< "REQMOD reply is HTTP reply");
1947 // subscribe to receive reply body
1948 if (new_rep
->body_pipe
!= NULL
) {
1949 adaptedBodySource
= new_rep
->body_pipe
;
1950 int consumer_ok
= adaptedBodySource
->setConsumerIfNotLate(this);
1951 assert(consumer_ok
);
1954 clientStreamNode
*node
= (clientStreamNode
*)client_stream
.tail
->prev
->data
;
1955 clientReplyContext
*repContext
= dynamic_cast<clientReplyContext
*>(node
->data
.getRaw());
1957 repContext
->createStoreEntry(request
->method
, request
->flags
);
1959 EBIT_CLR(storeEntry()->flags
, ENTRY_FWD_HDR_WAIT
);
1960 request_satisfaction_mode
= true;
1961 request_satisfaction_offset
= 0;
1962 storeEntry()->replaceHttpReply(new_rep
);
1963 storeEntry()->timestampsSet();
1965 if (!adaptedBodySource
) // no body
1966 storeEntry()->complete();
1967 clientGetMoreData(node
, this);
1970 // we are done with getting headers (but may be receiving body)
1971 clearAdaptation(virginHeadSource
);
1973 if (!request_satisfaction_mode
)
1978 ClientHttpRequest::handleAdaptationBlock(const Adaptation::Answer
&answer
)
1980 request
->detailError(ERR_ACCESS_DENIED
, ERR_DETAIL_REQMOD_BLOCK
);
1981 AclMatchedName
= answer
.ruleId
.termedBuf();
1982 assert(calloutContext
);
1983 calloutContext
->clientAccessCheckDone(ACCESS_DENIED
);
1984 AclMatchedName
= NULL
;
1988 ClientHttpRequest::resumeBodyStorage()
1990 if (!adaptedBodySource
)
1993 noteMoreBodyDataAvailable(adaptedBodySource
);
1997 ClientHttpRequest::noteMoreBodyDataAvailable(BodyPipe::Pointer
)
1999 assert(request_satisfaction_mode
);
2000 assert(adaptedBodySource
!= NULL
);
2002 if (size_t contentSize
= adaptedBodySource
->buf().contentSize()) {
2003 const size_t spaceAvailable
= storeEntry()->bytesWanted(Range
<size_t>(0,contentSize
));
2005 if (spaceAvailable
< contentSize
) {
2006 // No or partial body data consuming
2007 typedef NullaryMemFunT
<ClientHttpRequest
> Dialer
;
2008 AsyncCall::Pointer call
= asyncCall(93, 5, "ClientHttpRequest::resumeBodyStorage",
2009 Dialer(this, &ClientHttpRequest::resumeBodyStorage
));
2010 storeEntry()->deferProducer(call
);
2013 if (!spaceAvailable
)
2016 if (spaceAvailable
< contentSize
)
2017 contentSize
= spaceAvailable
;
2019 BodyPipeCheckout
bpc(*adaptedBodySource
);
2020 const StoreIOBuffer
ioBuf(&bpc
.buf
, request_satisfaction_offset
, contentSize
);
2021 storeEntry()->write(ioBuf
);
2022 // assume StoreEntry::write() writes the entire ioBuf
2023 request_satisfaction_offset
+= ioBuf
.length
;
2024 bpc
.buf
.consume(contentSize
);
2028 if (adaptedBodySource
->exhausted())
2029 endRequestSatisfaction();
2030 // else wait for more body data
2034 ClientHttpRequest::noteBodyProductionEnded(BodyPipe::Pointer
)
2036 assert(!virginHeadSource
);
2037 // should we end request satisfaction now?
2038 if (adaptedBodySource
!= NULL
&& adaptedBodySource
->exhausted())
2039 endRequestSatisfaction();
2043 ClientHttpRequest::endRequestSatisfaction()
2045 debugs(85,4, HERE
<< this << " ends request satisfaction");
2046 assert(request_satisfaction_mode
);
2047 stopConsumingFrom(adaptedBodySource
);
2049 // TODO: anything else needed to end store entry formation correctly?
2050 storeEntry()->complete();
2054 ClientHttpRequest::noteBodyProducerAborted(BodyPipe::Pointer
)
2056 assert(!virginHeadSource
);
2057 stopConsumingFrom(adaptedBodySource
);
2059 debugs(85,3, HERE
<< "REQMOD body production failed");
2060 if (request_satisfaction_mode
) { // too late to recover or serve an error
2061 request
->detailError(ERR_ICAP_FAILURE
, ERR_DETAIL_CLT_REQMOD_RESP_BODY
);
2062 const Comm::ConnectionPointer c
= getConn()->clientConnection
;
2063 Must(Comm::IsConnOpen(c
));
2064 c
->close(); // drastic, but we may be writing a response already
2066 handleAdaptationFailure(ERR_DETAIL_CLT_REQMOD_REQ_BODY
);
2071 ClientHttpRequest::handleAdaptationFailure(int errDetail
, bool bypassable
)
2073 debugs(85,3, HERE
<< "handleAdaptationFailure(" << bypassable
<< ")");
2075 const bool usedStore
= storeEntry() && !storeEntry()->isEmpty();
2076 const bool usedPipe
= request
->body_pipe
!= NULL
&&
2077 request
->body_pipe
->consumedSize() > 0;
2079 if (bypassable
&& !usedStore
&& !usedPipe
) {
2080 debugs(85,3, HERE
<< "ICAP REQMOD callout failed, bypassing: " << calloutContext
);
2086 debugs(85,3, HERE
<< "ICAP REQMOD callout failed, responding with error");
2088 clientStreamNode
*node
= (clientStreamNode
*)client_stream
.tail
->prev
->data
;
2089 clientReplyContext
*repContext
= dynamic_cast<clientReplyContext
*>(node
->data
.getRaw());
2092 calloutsError(ERR_ICAP_FAILURE
, errDetail
);
2099 ClientHttpRequest::callException(const std::exception
&ex
)
2101 if (const auto clientConn
= getConn() ? getConn()->clientConnection
: nullptr) {
2102 if (Comm::IsConnOpen(clientConn
)) {
2103 debugs(85, 3, "closing after exception: " << ex
.what());
2104 clientConn
->close(); // initiate orderly top-to-bottom cleanup
2108 debugs(85, DBG_IMPORTANT
, "ClientHttpRequest exception without connection. Ignoring " << ex
.what());
2109 // XXX: Normally, we mustStop() but we cannot do that here because it is
2110 // likely to leave Http::Stream and ConnStateData with a dangling http
2111 // pointer. See r13480 or XXX in Http::Stream class description.
2115 // XXX: modify and use with ClientRequestContext::clientAccessCheckDone too.
2117 ClientHttpRequest::calloutsError(const err_type error
, const int errDetail
)
2119 // The original author of the code also wanted to pass an errno to
2120 // setReplyToError, but it seems unlikely that the errno reflects the
2121 // true cause of the error at this point, so I did not pass it.
2122 if (calloutContext
) {
2125 ConnStateData
* c
= getConn();
2126 calloutContext
->error
= clientBuildError(error
, Http::scInternalServerError
,
2128 c
!= NULL
? c
->clientConnection
->remote
: noAddr
,
2132 calloutContext
->error
->auth_user_request
=
2133 c
!= NULL
&& c
->getAuth() != NULL
? c
->getAuth() : request
->auth_user_request
;
2135 calloutContext
->error
->detailError(errDetail
);
2136 calloutContext
->readNextRequest
= true;
2138 c
->expectNoForwarding();
2140 //else if(calloutContext == NULL) is it possible?