2 * Copyright (C) 1996-2026 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 "debug/Messages.h"
32 #include "error/Detail.h"
33 #include "errorpage.h"
36 #include "format/Token.h"
39 #include "helper/Reply.h"
41 #include "http/Stream.h"
42 #include "HttpHdrCc.h"
43 #include "HttpReply.h"
44 #include "HttpRequest.h"
46 #include "ip/NfMarkConfig.h"
47 #include "ip/QosConfig.h"
49 #include "log/access_log.h"
50 #include "MemObject.h"
52 #include "proxyp/Header.h"
55 #include "sbuf/StringConvert.h"
56 #include "SquidConfig.h"
62 #include "auth/UserRequest.h"
65 #include "adaptation/AccessCheck.h"
66 #include "adaptation/Answer.h"
67 #include "adaptation/Iterator.h"
68 #include "adaptation/Service.h"
70 #include "adaptation/icap/History.h"
74 #include "ssl/ServerBump.h"
75 #include "ssl/support.h"
78 #if FOLLOW_X_FORWARDED_FOR
80 #if !defined(SQUID_X_FORWARDED_FOR_HOP_MAX)
81 #define SQUID_X_FORWARDED_FOR_HOP_MAX 64
84 static void clientFollowXForwardedForCheck(Acl::Answer answer
, void *data
);
85 #endif /* FOLLOW_X_FORWARDED_FOR */
87 ErrorState
*clientBuildError(err_type
, Http::StatusCode
, char const *url
, const ConnStateData
*, HttpRequest
*, const AccessLogEntry::Pointer
&);
89 CBDATA_CLASS_INIT(ClientRequestContext
);
93 static void clientAccessCheckDoneWrapper(Acl::Answer
, void *);
95 static void sslBumpAccessCheckDoneWrapper(Acl::Answer
, void *);
97 static int clientHierarchical(ClientHttpRequest
* http
);
98 static void clientInterpretRequestHeaders(ClientHttpRequest
* http
);
99 static HLPCB clientRedirectDoneWrapper
;
100 static HLPCB clientStoreIdDoneWrapper
;
101 static void checkNoCacheDoneWrapper(Acl::Answer
, void *);
102 CSR clientGetMoreData
;
103 CSS clientReplyStatus
;
104 CSD clientReplyDetach
;
105 static void checkFailureRatio(err_type
, hier_code
);
107 ClientRequestContext::~ClientRequestContext()
109 cbdataReferenceDone(http
);
112 debugs(85,3, "ClientRequestContext destructed, this=" << this);
115 ClientRequestContext::ClientRequestContext(ClientHttpRequest
*anHttp
) :
116 http(cbdataReference(anHttp
))
118 debugs(85, 3, "ClientRequestContext constructed, this=" << this);
121 CBDATA_CLASS_INIT(ClientHttpRequest
);
123 ClientHttpRequest::ClientHttpRequest(ConnStateData
* aConn
) :
125 AsyncJob("ClientHttpRequest"),
127 al(new AccessLogEntry()),
128 conn_(cbdataReference(aConn
))
130 CodeContext::Reset(al
);
131 al
->cache
.start_time
= current_time
;
133 al
->tcpClient
= aConn
->clientConnection
;
134 al
->cache
.port
= aConn
->port
;
135 al
->cache
.caddr
= aConn
->log_addr
;
136 al
->proxyProtocolHeader
= aConn
->proxyProtocolHeader();
137 al
->updateError(aConn
->bareError
);
140 if (aConn
->clientConnection
!= nullptr && aConn
->clientConnection
->isOpen()) {
141 if (auto ssl
= fd_table
[aConn
->clientConnection
->fd
].ssl
.get())
142 al
->cache
.sslClientCert
.resetWithoutLocking(SSL_get_peer_certificate(ssl
));
146 dlinkAdd(this, &active
, &ClientActiveRequests
);
150 * returns true if client specified that the object must come from the cache
151 * without contacting origin server
154 ClientHttpRequest::onlyIfCached()const
157 return request
->cache_control
&&
158 request
->cache_control
->hasOnlyIfCached();
162 * This function is designed to serve a fairly specific purpose.
163 * Occasionally our vBNS-connected caches can talk to each other, but not
164 * the rest of the world. Here we try to detect frequent failures which
165 * make the cache unusable (e.g. DNS lookup and connect() failures). If
166 * the failure:success ratio goes above 1.0 then we go into "hit only"
167 * mode where we only return UDP_HIT or UDP_MISS_NOFETCH. Neighbors
168 * will only fetch HITs from us if they are using the ICP protocol. We
169 * stay in this mode for 5 minutes.
171 * Duane W., Sept 16, 1996
174 checkFailureRatio(err_type etype
, hier_code hcode
)
176 // Can be set at compile time with -D compiler flag
177 #ifndef FAILURE_MODE_TIME
178 #define FAILURE_MODE_TIME 300
181 if (hcode
== HIER_NONE
)
184 // don't bother when ICP is disabled.
185 if (Config
.Port
.icp
<= 0)
188 static double magic_factor
= 100.0;
192 n_good
= magic_factor
/ (1.0 + request_failure_ratio
);
194 n_bad
= magic_factor
- n_good
;
200 case ERR_CONNECT_FAIL
:
201 case ERR_SECURE_CONNECT_FAIL
:
211 request_failure_ratio
= n_bad
/ n_good
;
213 if (hit_only_mode_until
> squid_curtime
)
216 if (request_failure_ratio
< 1.0)
219 debugs(33, DBG_CRITICAL
, "WARNING: Failure Ratio at "<< std::setw(4)<<
220 std::setprecision(3) << request_failure_ratio
);
222 debugs(33, DBG_CRITICAL
, "WARNING: ICP going into HIT-only mode for " <<
223 FAILURE_MODE_TIME
/ 60 << " minutes...");
225 hit_only_mode_until
= squid_curtime
+ FAILURE_MODE_TIME
;
227 request_failure_ratio
= 0.8; /* reset to something less than 1.0 */
230 ClientHttpRequest::~ClientHttpRequest()
232 debugs(33, 3, "httpRequestFree: " << uri
);
234 // Even though freeResources() below may destroy the request,
235 // we no longer set request->body_pipe to NULL here
236 // because we did not initiate that pipe (ConnStateData did)
238 /* the ICP check here was erroneous
239 * - StoreEntry::releaseRequest was always called if entry was valid
244 loggingEntry(nullptr);
247 checkFailureRatio(request
->error
.category
, al
->hier
.code
);
252 announceInitiatorAbort(virginHeadSource
);
254 if (adaptedBodySource
!= nullptr)
255 stopConsumingFrom(adaptedBodySource
);
258 delete calloutContext
;
260 cbdataReferenceDone(conn_
);
262 /* moving to the next connection is handled by the context free */
263 dlinkDelete(&active
, &ClientActiveRequests
);
266 #if FOLLOW_X_FORWARDED_FOR
268 * clientFollowXForwardedForCheck() checks the content of X-Forwarded-For:
269 * against the followXFF ACL, or cleans up and passes control to
270 * clientAccessCheck().
272 * The trust model here is a little ambiguous. So to clarify the logic:
273 * - we may always use the direct client address as the client IP.
274 * - these trust tests merey tell whether we trust given IP enough to believe the
275 * IP string which it appended to the X-Forwarded-For: header.
276 * - if at any point we don't trust what an IP adds we stop looking.
277 * - at that point the current contents of indirect_client_addr are the value set
278 * by the last previously trusted IP.
279 * ++ indirect_client_addr contains the remote direct client from the trusted peers viewpoint.
282 clientFollowXForwardedForCheck(Acl::Answer answer
, void *data
)
284 ClientRequestContext
*calloutContext
= (ClientRequestContext
*) data
;
285 ClientHttpRequest
*http
= calloutContext
->http
;
286 HttpRequest
*request
= http
->request
;
288 if (answer
.allowed() && request
->x_forwarded_for_iterator
.size() != 0) {
291 * Remove the last comma-delimited element from the
292 * x_forwarded_for_iterator and use it to repeat the cycle.
295 const char *asciiaddr
;
298 p
= request
->x_forwarded_for_iterator
.termedBuf();
299 l
= request
->x_forwarded_for_iterator
.size();
302 * XXX x_forwarded_for_iterator should really be a list of
303 * IP addresses, but it's a String instead. We have to
304 * walk backwards through the String, biting off the last
305 * comma-delimited part each time. As long as the data is in
306 * a String, we should probably implement and use a variant of
307 * strListGetItem() that walks backwards instead of forwards
308 * through a comma-separated list. But we don't even do that;
309 * we just do the work in-line here.
311 /* skip trailing space and commas */
312 while (l
> 0 && (p
[l
-1] == ',' || xisspace(p
[l
-1])))
314 request
->x_forwarded_for_iterator
.cut(l
);
315 /* look for start of last item in list */
316 while (l
> 0 && ! (p
[l
-1] == ',' || xisspace(p
[l
-1])))
319 if ((addr
= asciiaddr
)) {
320 request
->indirect_client_addr
= addr
;
321 request
->x_forwarded_for_iterator
.cut(l
);
322 auto ch
= clientAclChecklistCreate(Config
.accessList
.followXFF
, http
);
323 if (!Config
.onoff
.acl_uses_indirect_client
) {
324 /* override the default src_addr tested if we have to go deeper than one level into XFF */
325 ch
->src_addr
= request
->indirect_client_addr
;
327 if (++calloutContext
->currentXffHopNumber
< SQUID_X_FORWARDED_FOR_HOP_MAX
) {
328 ACLFilledChecklist::NonBlockingCheck(std::move(ch
), clientFollowXForwardedForCheck
, data
);
331 const auto headerName
= Http::HeaderLookupTable
.lookup(Http::HdrType::X_FORWARDED_FOR
).name
;
332 debugs(28, DBG_CRITICAL
, "ERROR: Ignoring trailing " << headerName
<< " addresses" <<
333 Debug::Extra
<< "addresses allowed by follow_x_forwarded_for: " << calloutContext
->currentXffHopNumber
<<
334 Debug::Extra
<< "last/accepted address: " << request
->indirect_client_addr
<<
335 Debug::Extra
<< "ignored trailing addresses: " << request
->x_forwarded_for_iterator
);
336 // fall through to resume clientAccessCheck() processing
340 /* clean up, and pass control to clientAccessCheck */
341 if (Config
.onoff
.log_uses_indirect_client
) {
343 * Ensure that the access log shows the indirect client
344 * instead of the direct client.
346 http
->al
->cache
.caddr
= request
->indirect_client_addr
;
347 if (ConnStateData
*conn
= http
->getConn())
348 conn
->log_addr
= request
->indirect_client_addr
;
350 request
->x_forwarded_for_iterator
.clean();
351 request
->flags
.done_follow_x_forwarded_for
= true;
353 if (answer
.conflicted()) {
354 debugs(28, DBG_CRITICAL
, "ERROR: Processing X-Forwarded-For. Stopping at IP address: " << request
->indirect_client_addr
);
357 /* process actual access ACL as normal. */
358 calloutContext
->clientAccessCheck();
360 #endif /* FOLLOW_X_FORWARDED_FOR */
363 hostHeaderIpVerifyWrapper(const ipcache_addrs
* ia
, const Dns::LookupDetails
&dns
, void *data
)
365 ClientRequestContext
*c
= static_cast<ClientRequestContext
*>(data
);
366 c
->hostHeaderIpVerify(ia
, dns
);
370 ClientRequestContext::hostHeaderIpVerify(const ipcache_addrs
* ia
, const Dns::LookupDetails
&dns
)
372 Comm::ConnectionPointer clientConn
= http
->getConn()->clientConnection
;
374 // note the DNS details for the transaction stats.
375 http
->request
->recordLookup(dns
);
377 // Is the NAT destination IP in DNS?
378 if (ia
&& ia
->have(clientConn
->local
)) {
379 debugs(85, 3, "validate IP " << clientConn
->local
<< " possible from Host:");
380 http
->request
->flags
.hostVerified
= true;
384 debugs(85, 3, "FAIL: validate IP " << clientConn
->local
<< " possible from Host:");
385 hostHeaderVerifyFailed("local IP", "any domain IP");
389 ClientRequestContext::hostHeaderVerifyFailed(const char *A
, const char *B
)
391 // IP address validation for Host: failed. Admin wants to ignore them.
392 // NP: we do not yet handle CONNECT tunnels well, so ignore for them
393 if (!Config
.onoff
.hostStrictVerify
&& http
->request
->method
!= Http::METHOD_CONNECT
) {
394 debugs(85, 3, "SECURITY ALERT: Host header forgery detected on " << http
->getConn()->clientConnection
<<
395 " (" << A
<< " does not match " << B
<< ") on URL: " << http
->request
->effectiveRequestUri());
397 // MUST NOT cache (for now). It is tempting to set flags.noCache, but
398 // that flag is about satisfying _this_ request. We are actually OK with
399 // satisfying this request from the cache, but want to prevent _other_
400 // requests from being satisfied using this response.
401 http
->request
->flags
.cachable
.veto();
403 // XXX: when we have updated the cache key to base on raw-IP + URI this cacheable limit can go.
404 http
->request
->flags
.hierarchical
= false; // MUST NOT pass to peers (for now)
405 // XXX: when we have sorted out the best way to relay requests properly to peers this hierarchical limit can go.
410 debugs(85, DBG_IMPORTANT
, "SECURITY ALERT: Host header forgery detected on " <<
411 http
->getConn()->clientConnection
<< " (" << A
<< " does not match " << B
<< ")");
412 if (const char *ua
= http
->request
->header
.getStr(Http::HdrType::USER_AGENT
))
413 debugs(85, DBG_IMPORTANT
, "SECURITY ALERT: By user agent: " << ua
);
414 debugs(85, DBG_IMPORTANT
, "SECURITY ALERT: on URL: " << http
->request
->effectiveRequestUri());
416 // IP address validation for Host: failed. reject the connection.
417 clientStreamNode
*node
= (clientStreamNode
*)http
->client_stream
.tail
->prev
->data
;
418 clientReplyContext
*repContext
= dynamic_cast<clientReplyContext
*>(node
->data
.getRaw());
420 repContext
->setReplyToError(ERR_CONFLICT_HOST
, Http::scConflict
,
426 http
->getConn() != nullptr && http
->getConn()->getAuth() != nullptr ?
427 http
->getConn()->getAuth() : http
->request
->auth_user_request
);
431 node
= (clientStreamNode
*)http
->client_stream
.tail
->data
;
432 clientStreamRead(node
, http
, node
->readBuffer
);
436 ClientRequestContext::hostHeaderVerify()
438 // Require a Host: header.
439 const char *host
= http
->request
->header
.getStr(Http::HdrType::HOST
);
442 // TODO: dump out the HTTP/1.1 error about missing host header.
443 // otherwise this is fine, can't forge a header value when its not even set.
444 debugs(85, 3, "validate skipped with no Host: header present.");
449 if (http
->request
->flags
.internal
) {
450 // TODO: kill this when URL handling allows partial URLs out of accel mode
451 // and we no longer screw with the URL just to add our internal host there
452 debugs(85, 6, "validate skipped due to internal composite URL.");
457 // TODO: Unify Host value parsing below with AnyP::Uri authority parsing
458 // Locate if there is a port attached, strip ready for IP lookup
459 char *portStr
= nullptr;
460 char *hostB
= xstrdup(host
);
462 if (host
[0] == '[') {
464 portStr
= strchr(hostB
, ']');
465 if (portStr
&& *(++portStr
) != ':') {
469 // Domain or IPv4 literal with port
470 portStr
= strrchr(hostB
, ':');
475 *portStr
= '\0'; // strip the ':'
476 if (*(++portStr
) != '\0') {
478 int64_t ret
= strtoll(portStr
, &end
, 10);
479 if (end
== portStr
|| *end
!= '\0' || ret
< 1 || ret
> 0xFFFF) {
480 // invalid port details. Replace the ':'
484 port
= (ret
& 0xFFFF);
488 debugs(85, 3, "validate host=" << host
<< ", port=" << port
<< ", portStr=" << (portStr
?portStr
:"NULL"));
489 if (http
->request
->flags
.intercepted
|| http
->request
->flags
.interceptTproxy
) {
490 // verify the Host: port (if any) matches the apparent destination
491 if (portStr
&& port
!= http
->getConn()->clientConnection
->local
.port()) {
492 debugs(85, 3, "FAIL on validate port " << http
->getConn()->clientConnection
->local
.port() <<
493 " matches Host: port " << port
<< " (" << portStr
<< ")");
494 hostHeaderVerifyFailed("intercepted port", portStr
);
496 // XXX: match the scheme default port against the apparent destination
498 // verify the destination DNS is one of the Host: headers IPs
499 ipcache_nbgethostbyname(host
, hostHeaderIpVerifyWrapper
, this);
501 } else if (!Config
.onoff
.hostStrictVerify
) {
502 debugs(85, 3, "validate skipped.");
504 } else if (strlen(host
) != strlen(http
->request
->url
.host())) {
505 // Verify forward-proxy requested URL domain matches the Host: header
506 debugs(85, 3, "FAIL on validate URL domain length " << http
->request
->url
.host() << " matches Host: " << host
);
507 hostHeaderVerifyFailed(host
, http
->request
->url
.host());
508 } else if (matchDomainName(host
, http
->request
->url
.host()) != 0) {
509 // Verify forward-proxy requested URL domain matches the Host: header
510 debugs(85, 3, "FAIL on validate URL domain " << http
->request
->url
.host() << " matches Host: " << host
);
511 hostHeaderVerifyFailed(host
, http
->request
->url
.host());
512 } else if (portStr
&& !http
->request
->url
.port()) {
513 debugs(85, 3, "FAIL on validate portless URI matches Host: " << portStr
);
514 hostHeaderVerifyFailed("portless URI", portStr
);
515 } else if (portStr
&& port
!= *http
->request
->url
.port()) {
516 // Verify forward-proxy requested URL domain matches the Host: header
517 debugs(85, 3, "FAIL on validate URL port " << *http
->request
->url
.port() << " matches Host: port " << portStr
);
518 hostHeaderVerifyFailed("URL port", portStr
);
519 } else if (!portStr
&& http
->request
->method
!= Http::METHOD_CONNECT
&& http
->request
->url
.port() != http
->request
->url
.getScheme().defaultPort()) {
520 // Verify forward-proxy requested URL domain matches the Host: header
521 // Special case: we don't have a default-port to check for CONNECT. Assume URL is correct.
522 debugs(85, 3, "FAIL on validate URL port " << http
->request
->url
.port().value_or(0) << " matches Host: default port " << http
->request
->url
.getScheme().defaultPort().value_or(0));
523 hostHeaderVerifyFailed("URL port", "default port");
526 debugs(85, 3, "validate passed.");
527 http
->request
->flags
.hostVerified
= true;
533 /* This is the entry point for external users of the client_side routines */
535 ClientRequestContext::clientAccessCheck()
537 #if FOLLOW_X_FORWARDED_FOR
538 if (!http
->request
->flags
.doneFollowXff() &&
539 Config
.accessList
.followXFF
&&
540 http
->request
->header
.has(Http::HdrType::X_FORWARDED_FOR
)) {
542 /* we always trust the direct client address for actual use */
543 http
->request
->indirect_client_addr
= http
->request
->client_addr
;
544 http
->request
->indirect_client_addr
.port(0);
546 /* setup the XFF iterator for processing */
547 http
->request
->x_forwarded_for_iterator
= http
->request
->header
.getList(Http::HdrType::X_FORWARDED_FOR
);
549 /* begin by checking to see if we trust direct client enough to walk XFF */
550 auto acl_checklist
= clientAclChecklistCreate(Config
.accessList
.followXFF
, http
);
551 ACLFilledChecklist::NonBlockingCheck(std::move(acl_checklist
), clientFollowXForwardedForCheck
, this);
556 if (Config
.accessList
.http
) {
557 auto acl_checklist
= clientAclChecklistCreate(Config
.accessList
.http
, http
);
558 ACLFilledChecklist::NonBlockingCheck(std::move(acl_checklist
), clientAccessCheckDoneWrapper
, this);
560 debugs(0, DBG_CRITICAL
, "No http_access configuration found. This will block ALL traffic");
561 clientAccessCheckDone(ACCESS_DENIED
);
566 * Identical in operation to clientAccessCheck() but performed later using different configured ACL list.
567 * The default here is to allow all. Since the earlier http_access should do a default deny all.
568 * This check is just for a last-minute denial based on adapted request headers.
571 ClientRequestContext::clientAccessCheck2()
573 if (Config
.accessList
.adapted_http
) {
574 auto acl_checklist
= clientAclChecklistCreate(Config
.accessList
.adapted_http
, http
);
575 ACLFilledChecklist::NonBlockingCheck(std::move(acl_checklist
), clientAccessCheckDoneWrapper
, this);
577 debugs(85, 2, "No adapted_http_access configuration. default: ALLOW");
578 clientAccessCheckDone(ACCESS_ALLOWED
);
583 clientAccessCheckDoneWrapper(Acl::Answer answer
, void *data
)
585 ClientRequestContext
*calloutContext
= (ClientRequestContext
*) data
;
586 calloutContext
->clientAccessCheckDone(answer
);
590 ClientRequestContext::clientAccessCheckDone(const Acl::Answer
&answer
)
592 Http::StatusCode status
;
593 debugs(85, 2, "The request " << http
->request
->method
<< ' ' <<
594 http
->uri
<< " is " << answer
<<
595 "; last ACL checked: " << answer
.lastCheckDescription());
598 char const *proxy_auth_msg
= "<null>";
599 if (http
->getConn() != nullptr && http
->getConn()->getAuth() != nullptr)
600 proxy_auth_msg
= http
->getConn()->getAuth()->denyMessage("<null>");
601 else if (http
->request
->auth_user_request
!= nullptr)
602 proxy_auth_msg
= http
->request
->auth_user_request
->denyMessage("<null>");
605 if (!answer
.allowed()) {
606 // auth has a grace period where credentials can be expired but okay not to challenge.
608 /* Send an auth challenge or error */
609 // XXX: do we still need aclIsProxyAuth() ?
610 const auto auth_challenge
= (answer
== ACCESS_AUTH_REQUIRED
|| aclIsProxyAuth(answer
.lastCheckedName
));
611 debugs(85, 5, "Access Denied: " << http
->uri
);
614 debugs(33, 5, "Proxy Auth Message = " << (proxy_auth_msg
? proxy_auth_msg
: "<null>"));
617 auto page_id
= FindDenyInfoPage(answer
, answer
!= ACCESS_AUTH_REQUIRED
);
619 http
->updateLoggingTags(LOG_TCP_DENIED
);
621 if (auth_challenge
) {
623 if (http
->request
->flags
.sslBumped
) {
624 /*SSL Bumped request, authentication is not possible*/
625 status
= Http::scForbidden
;
626 } else if (!http
->flags
.accel
) {
627 /* Proxy authorisation needed */
628 status
= Http::scProxyAuthenticationRequired
;
630 /* WWW authorisation needed */
631 status
= Http::scUnauthorized
;
634 // need auth, but not possible to do.
635 status
= Http::scForbidden
;
637 if (page_id
== ERR_NONE
)
638 page_id
= (status
== Http::scForbidden
) ? ERR_ACCESS_DENIED
: ERR_CACHE_ACCESS_DENIED
;
640 status
= Http::scForbidden
;
642 if (page_id
== ERR_NONE
)
643 page_id
= ERR_ACCESS_DENIED
;
646 error
= clientBuildError(page_id
, status
, nullptr, http
->getConn(), http
->request
, http
->al
);
649 error
->auth_user_request
=
650 http
->getConn() != nullptr && http
->getConn()->getAuth() != nullptr ?
651 http
->getConn()->getAuth() : http
->request
->auth_user_request
;
654 readNextRequest
= true;
657 /* ACCESS_ALLOWED continues here ... */
659 http
->uri
= SBufToCstring(http
->request
->effectiveRequestUri());
665 ClientHttpRequest::noteAdaptationAclCheckDone(Adaptation::ServiceGroupPointer g
)
667 debugs(93,3, this << " adaptationAclCheckDone called");
670 Adaptation::Icap::History::Pointer ih
= request
->icapHistory();
672 if (getConn() != nullptr && getConn()->clientConnection
!= nullptr) {
674 if (getConn()->clientConnection
->isOpen()) {
675 ih
->ssluser
= sslGetUserEmail(fd_table
[getConn()->clientConnection
->fd
].ssl
.get());
679 ih
->log_uri
= log_uri
;
685 debugs(85,3, "no adaptation needed");
696 clientRedirectAccessCheckDone(Acl::Answer answer
, void *data
)
698 ClientRequestContext
*context
= (ClientRequestContext
*)data
;
699 ClientHttpRequest
*http
= context
->http
;
701 if (answer
.allowed())
702 redirectStart(http
, clientRedirectDoneWrapper
, context
);
704 Helper::Reply
const nilReply(Helper::Error
);
705 context
->clientRedirectDone(nilReply
);
710 ClientRequestContext::clientRedirectStart()
712 debugs(33, 5, "'" << http
->uri
<< "'");
713 http
->al
->syncNotes(http
->request
);
714 if (Config
.accessList
.redirector
) {
715 auto acl_checklist
= clientAclChecklistCreate(Config
.accessList
.redirector
, http
);
716 ACLFilledChecklist::NonBlockingCheck(std::move(acl_checklist
), clientRedirectAccessCheckDone
, this);
718 redirectStart(http
, clientRedirectDoneWrapper
, this);
722 * This methods handles Access checks result of StoreId access list.
723 * Will handle as "ERR" (no change) in a case Access is not allowed.
726 clientStoreIdAccessCheckDone(Acl::Answer answer
, void *data
)
728 ClientRequestContext
*context
= static_cast<ClientRequestContext
*>(data
);
729 ClientHttpRequest
*http
= context
->http
;
731 if (answer
.allowed())
732 storeIdStart(http
, clientStoreIdDoneWrapper
, context
);
734 debugs(85, 3, "access denied expected ERR reply handling: " << answer
);
735 Helper::Reply
const nilReply(Helper::Error
);
736 context
->clientStoreIdDone(nilReply
);
741 * Start locating an alternative storage ID string (if any) from admin
742 * configured helper program. This is an asynchronous operation terminating in
743 * ClientRequestContext::clientStoreIdDone() when completed.
746 ClientRequestContext::clientStoreIdStart()
748 debugs(33, 5,"'" << http
->uri
<< "'");
750 if (Config
.accessList
.store_id
) {
751 auto acl_checklist
= clientAclChecklistCreate(Config
.accessList
.store_id
, http
);
752 ACLFilledChecklist::NonBlockingCheck(std::move(acl_checklist
), clientStoreIdAccessCheckDone
, this);
754 storeIdStart(http
, clientStoreIdDoneWrapper
, this);
758 clientHierarchical(ClientHttpRequest
* http
)
760 HttpRequest
*request
= http
->request
;
761 HttpRequestMethod method
= request
->method
;
763 // intercepted requests MUST NOT (yet) be sent to peers unless verified
764 if (!request
->flags
.hostVerified
&& (request
->flags
.intercepted
|| request
->flags
.interceptTproxy
))
768 * IMS needs a private key, so we can use the hierarchy for IMS only if our
769 * neighbors support private keys
772 if (request
->flags
.ims
&& !neighbors_do_private_keys
)
776 * This is incorrect: authenticating requests can be sent via a hierarchy
777 * (they can even be cached if the correct headers are set on the reply)
779 if (request
->flags
.auth
)
782 if (method
== Http::METHOD_TRACE
)
785 if (method
!= Http::METHOD_GET
)
788 if (request
->flags
.loopDetected
)
791 if (request
->url
.getScheme() == AnyP::PROTO_HTTP
)
792 return method
.respMaybeCacheable();
798 clientCheckPinning(ClientHttpRequest
* http
)
800 HttpRequest
*request
= http
->request
;
801 HttpHeader
*req_hdr
= &request
->header
;
802 ConnStateData
*http_conn
= http
->getConn();
804 // Internal requests may be without a client connection
808 request
->flags
.connectionAuthDisabled
= http_conn
->port
->connection_auth_disabled
;
809 if (!request
->flags
.connectionAuthDisabled
) {
810 if (Comm::IsConnOpen(http_conn
->pinning
.serverConnection
)) {
811 if (http_conn
->pinning
.auth
) {
812 request
->flags
.connectionAuth
= true;
813 request
->flags
.auth
= true;
815 request
->flags
.connectionProxyAuth
= true;
817 // These should already be linked correctly.
818 assert(request
->clientConnectionManager
== http_conn
);
822 /* check if connection auth is used, and flag as candidate for pinning
824 * Note: we may need to set flags.connectionAuth even if the connection
825 * is already pinned if it was pinned earlier due to proxy auth
827 if (!request
->flags
.connectionAuth
) {
828 if (req_hdr
->has(Http::HdrType::AUTHORIZATION
) || req_hdr
->has(Http::HdrType::PROXY_AUTHORIZATION
)) {
829 HttpHeaderPos pos
= HttpHeaderInitPos
;
832 while ((e
= req_hdr
->getEntry(&pos
))) {
833 if (e
->id
== Http::HdrType::AUTHORIZATION
|| e
->id
== Http::HdrType::PROXY_AUTHORIZATION
) {
834 const char *value
= e
->value
.rawBuf();
835 if (strncasecmp(value
, "NTLM ", 5) == 0
837 strncasecmp(value
, "Negotiate ", 10) == 0
839 strncasecmp(value
, "Kerberos ", 9) == 0) {
840 if (e
->id
== Http::HdrType::AUTHORIZATION
) {
841 request
->flags
.connectionAuth
= true;
844 request
->flags
.connectionProxyAuth
= true;
850 if (may_pin
&& !request
->pinnedConnection()) {
851 // These should already be linked correctly. Just need the ServerConnection to pinn.
852 assert(request
->clientConnectionManager
== http_conn
);
859 clientInterpretRequestHeaders(ClientHttpRequest
* http
)
861 HttpRequest
*request
= http
->request
;
862 HttpHeader
*req_hdr
= &request
->header
;
863 bool no_cache
= false;
865 request
->imslen
= -1;
866 request
->ims
= req_hdr
->getTime(Http::HdrType::IF_MODIFIED_SINCE
);
868 if (request
->ims
> 0)
869 request
->flags
.ims
= true;
871 if (!request
->flags
.ignoreCc
) {
872 if (request
->cache_control
) {
873 if (request
->cache_control
->hasNoCache())
876 // RFC 2616: treat Pragma:no-cache as if it was Cache-Control:no-cache when Cache-Control is missing
877 } else if (req_hdr
->has(Http::HdrType::PRAGMA
))
878 no_cache
= req_hdr
->hasListMember(Http::HdrType::PRAGMA
,"no-cache",',');
881 if (request
->method
== Http::METHOD_OTHER
) {
886 #if USE_HTTP_VIOLATIONS
888 if (Config
.onoff
.reload_into_ims
)
889 request
->flags
.nocacheHack
= true;
890 else if (refresh_nocache_hack
)
891 request
->flags
.nocacheHack
= true;
895 request
->flags
.noCache
= true;
898 /* ignore range header in non-GETs or non-HEADs */
899 if (request
->method
== Http::METHOD_GET
|| request
->method
== Http::METHOD_HEAD
) {
900 // XXX: initialize if we got here without HttpRequest::parseHeader()
902 request
->range
= req_hdr
->getRange();
904 if (request
->range
) {
905 request
->flags
.isRanged
= true;
906 clientStreamNode
*node
= (clientStreamNode
*)http
->client_stream
.tail
->data
;
907 /* XXX: This is suboptimal. We should give the stream the range set,
908 * and thereby let the top of the stream set the offset when the
909 * size becomes known. As it is, we will end up requesting from 0
910 * for every -X range specification.
911 * RBC - this may be somewhat wrong. We should probably set the range
912 * iter up at this point.
914 node
->readBuffer
.offset
= request
->range
->lowestOffset(0);
918 /* Only HEAD and GET requests permit a Range or Request-Range header.
919 * If these headers appear on any other type of request, delete them now.
922 req_hdr
->delById(Http::HdrType::RANGE
);
923 req_hdr
->delById(Http::HdrType::REQUEST_RANGE
);
924 request
->ignoreRange("neither HEAD nor GET");
927 if (req_hdr
->has(Http::HdrType::AUTHORIZATION
))
928 request
->flags
.auth
= true;
930 clientCheckPinning(http
);
932 if (!request
->url
.userInfo().isEmpty())
933 request
->flags
.auth
= true;
935 if (req_hdr
->has(Http::HdrType::VIA
)) {
936 String s
= req_hdr
->getList(Http::HdrType::VIA
);
938 * ThisCache cannot be a member of Via header, "1.1 ThisCache" can.
939 * Note ThisCache2 has a space prepended to the hostname so we don't
940 * accidentally match super-domains.
943 if (strListIsSubstr(&s
, ThisCache2
, ',')) {
944 request
->flags
.loopDetected
= true;
948 fvdbCountVia(StringToSBuf(s
));
955 // headers only relevant to reverse-proxy
956 if (request
->flags
.accelerated
) {
957 // check for a cdn-info member with a cdn-id matching surrogate_id
958 // XXX: HttpHeader::hasListMember() does not handle OWS around ";" yet
959 if (req_hdr
->hasListMember(Http::HdrType::CDN_LOOP
, Config
.Accel
.surrogate_id
, ','))
960 request
->flags
.loopDetected
= true;
963 if (request
->flags
.loopDetected
) {
964 debugObj(33, DBG_IMPORTANT
, "WARNING: Forwarding loop detected for:\n",
965 request
, (ObjPackMethod
) & httpRequestPack
);
970 if (req_hdr
->has(Http::HdrType::X_FORWARDED_FOR
)) {
971 String s
= req_hdr
->getList(Http::HdrType::X_FORWARDED_FOR
);
972 fvdbCountForwarded(StringToSBuf(s
));
978 if (http
->request
->maybeCacheable())
979 request
->flags
.cachable
.support();
981 request
->flags
.cachable
.veto();
983 if (clientHierarchical(http
))
984 request
->flags
.hierarchical
= true;
986 debugs(85, 5, "clientInterpretRequestHeaders: REQ_NOCACHE = " <<
987 (request
->flags
.noCache
? "SET" : "NOT SET"));
988 debugs(85, 5, "clientInterpretRequestHeaders: REQ_CACHABLE = " <<
989 (request
->flags
.cachable
? "SET" : "NOT SET"));
990 debugs(85, 5, "clientInterpretRequestHeaders: REQ_HIERARCHICAL = " <<
991 (request
->flags
.hierarchical
? "SET" : "NOT SET"));
996 clientRedirectDoneWrapper(void *data
, const Helper::Reply
&result
)
998 ClientRequestContext
*calloutContext
= (ClientRequestContext
*)data
;
999 calloutContext
->clientRedirectDone(result
);
1003 clientStoreIdDoneWrapper(void *data
, const Helper::Reply
&result
)
1005 ClientRequestContext
*calloutContext
= (ClientRequestContext
*)data
;
1006 calloutContext
->clientStoreIdDone(result
);
1010 ClientRequestContext::clientRedirectDone(const Helper::Reply
&reply
)
1012 HttpRequest
*old_request
= http
->request
;
1013 debugs(85, 5, "'" << http
->uri
<< "' result=" << reply
);
1014 assert(redirect_state
== REDIRECT_PENDING
);
1015 redirect_state
= REDIRECT_DONE
;
1017 // Put helper response Notes into the transaction state record (ALE) eventually
1018 // do it early to ensure that no matter what the outcome the notes are present.
1020 http
->al
->syncNotes(old_request
);
1022 UpdateRequestNotes(http
->getConn(), *old_request
, reply
.notes
);
1024 switch (reply
.result
) {
1025 case Helper::TimedOut
:
1026 if (Config
.onUrlRewriteTimeout
.action
!= toutActBypass
) {
1027 static const auto d
= MakeNamedErrorDetail("REDIRECTOR_TIMEDOUT");
1028 http
->calloutsError(ERR_GATEWAY_FAILURE
, d
);
1029 debugs(85, DBG_IMPORTANT
, "ERROR: URL rewrite helper: Timedout");
1033 case Helper::Unknown
:
1035 // Handler in redirect.cc should have already mapped Unknown
1036 // IF it contained valid entry for the old URL-rewrite helper protocol
1037 debugs(85, DBG_IMPORTANT
, "ERROR: URL rewrite helper returned invalid result code. Wrong helper? " << reply
);
1040 case Helper::BrokenHelper
:
1041 debugs(85, DBG_IMPORTANT
, "ERROR: URL rewrite helper: " << reply
);
1045 // no change to be done.
1048 case Helper::Okay
: {
1049 // #1: redirect with a specific status code OK status=NNN url="..."
1050 // #2: redirect with a default status code OK url="..."
1051 // #3: re-write the URL OK rewrite-url="..."
1053 const char *statusNote
= reply
.notes
.findFirst("status");
1054 const char *urlNote
= reply
.notes
.findFirst("url");
1056 if (urlNote
!= nullptr) {
1057 // HTTP protocol redirect to be done.
1059 // TODO: change default redirect status for appropriate requests
1060 // Squid defaults to 302 status for now for better compatibility with old clients.
1061 // HTTP/1.0 client should get 302 (Http::scFound)
1062 // HTTP/1.1 client contacting reverse-proxy should get 307 (Http::scTemporaryRedirect)
1063 // HTTP/1.1 client being diverted by forward-proxy should get 303 (Http::scSeeOther)
1064 Http::StatusCode status
= Http::scFound
;
1065 if (statusNote
!= nullptr) {
1066 const char * result
= statusNote
;
1067 status
= static_cast<Http::StatusCode
>(atoi(result
));
1070 if (status
== Http::scMovedPermanently
1071 || status
== Http::scFound
1072 || status
== Http::scSeeOther
1073 || status
== Http::scPermanentRedirect
1074 || status
== Http::scTemporaryRedirect
) {
1075 http
->redirect
.status
= status
;
1076 http
->redirect
.location
= xstrdup(urlNote
);
1077 // TODO: validate the URL produced here is RFC 2616 compliant absolute URI
1079 debugs(85, DBG_CRITICAL
, "ERROR: URL-rewrite produces invalid " << status
<< " redirect Location: " << urlNote
);
1082 // URL-rewrite wanted. Ew.
1083 urlNote
= reply
.notes
.findFirst("rewrite-url");
1085 // prevent broken helpers causing too much damage. If old URL == new URL skip the re-write.
1086 if (urlNote
!= nullptr && strcmp(urlNote
, http
->uri
)) {
1088 if (tmpUrl
.parse(old_request
->method
, SBuf(urlNote
))) {
1089 HttpRequest
*new_request
= old_request
->clone();
1090 new_request
->url
= tmpUrl
;
1091 debugs(61, 2, "URL-rewriter diverts URL from " << old_request
->effectiveRequestUri() << " to " << new_request
->effectiveRequestUri());
1093 // unlink bodypipe from the old request. Not needed there any longer.
1094 if (old_request
->body_pipe
!= nullptr) {
1095 old_request
->body_pipe
= nullptr;
1096 debugs(61,2, "URL-rewriter diverts body_pipe " << new_request
->body_pipe
<<
1097 " from request " << old_request
<< " to " << new_request
);
1100 http
->resetRequestXXX(new_request
, true);
1101 old_request
= nullptr;
1103 debugs(85, DBG_CRITICAL
, "ERROR: URL-rewrite produces invalid request: " <<
1104 old_request
->method
<< " " << urlNote
<< " " << old_request
->http_ver
);
1112 /* XXX PIPELINE: This is inaccurate during pipelining */
1114 if (http
->getConn() != nullptr && Comm::IsConnOpen(http
->getConn()->clientConnection
))
1115 fd_note(http
->getConn()->clientConnection
->fd
, http
->uri
);
1123 * This method handles the different replies from StoreID helper.
1126 ClientRequestContext::clientStoreIdDone(const Helper::Reply
&reply
)
1128 HttpRequest
*old_request
= http
->request
;
1129 debugs(85, 5, "'" << http
->uri
<< "' result=" << reply
);
1130 assert(store_id_state
== REDIRECT_PENDING
);
1131 store_id_state
= REDIRECT_DONE
;
1133 // Put helper response Notes into the transaction state record (ALE) eventually
1134 // do it early to ensure that no matter what the outcome the notes are present.
1136 http
->al
->syncNotes(old_request
);
1138 UpdateRequestNotes(http
->getConn(), *old_request
, reply
.notes
);
1140 switch (reply
.result
) {
1141 case Helper::Unknown
:
1143 // Handler in redirect.cc should have already mapped Unknown
1144 // IF it contained valid entry for the old helper protocol
1145 debugs(85, DBG_IMPORTANT
, "ERROR: storeID helper returned invalid result code. Wrong helper? " << reply
);
1148 case Helper::TimedOut
:
1149 // Timeouts for storeID are not implemented
1150 case Helper::BrokenHelper
:
1151 debugs(85, DBG_IMPORTANT
, "ERROR: storeID helper: " << reply
);
1155 // no change to be done.
1158 case Helper::Okay
: {
1159 const char *urlNote
= reply
.notes
.findFirst("store-id");
1161 // prevent broken helpers causing too much damage. If old URL == new URL skip the re-write.
1162 if (urlNote
!= nullptr && strcmp(urlNote
, http
->uri
) ) {
1163 // Debug section required for some very specific cases.
1164 debugs(85, 9, "Setting storeID with: " << urlNote
);
1165 http
->request
->store_id
= urlNote
;
1166 http
->store_id
= urlNote
;
1175 /// applies "cache allow/deny" rules, asynchronously if needed
1177 ClientRequestContext::checkNoCache()
1179 if (Config
.accessList
.noCache
) {
1180 auto acl_checklist
= clientAclChecklistCreate(Config
.accessList
.noCache
, http
);
1181 ACLFilledChecklist::NonBlockingCheck(std::move(acl_checklist
), checkNoCacheDoneWrapper
, this);
1183 /* unless otherwise specified, we try to cache. */
1184 checkNoCacheDone(ACCESS_ALLOWED
);
1189 checkNoCacheDoneWrapper(Acl::Answer answer
, void *data
)
1191 ClientRequestContext
*calloutContext
= (ClientRequestContext
*) data
;
1192 calloutContext
->checkNoCacheDone(answer
);
1196 ClientRequestContext::checkNoCacheDone(const Acl::Answer
&answer
)
1198 if (answer
.denied()) {
1199 http
->request
->flags
.disableCacheUse("a cache deny rule matched");
1206 ClientRequestContext::sslBumpAccessCheck()
1208 if (!http
->getConn()) {
1209 http
->al
->ssl
.bumpMode
= Ssl::bumpEnd
; // SslBump does not apply; log -
1213 const Ssl::BumpMode bumpMode
= http
->getConn()->sslBumpMode
;
1214 if (http
->request
->flags
.forceTunnel
) {
1215 debugs(85, 5, "not needed; already decided to tunnel " << http
->getConn());
1216 if (bumpMode
!= Ssl::bumpEnd
)
1217 http
->al
->ssl
.bumpMode
= bumpMode
; // inherited from bumped connection
1221 // If SSL connection tunneling or bumping decision has been made, obey it.
1222 if (bumpMode
!= Ssl::bumpEnd
) {
1223 debugs(85, 5, "SslBump already decided (" << bumpMode
<<
1224 "), " << "ignoring ssl_bump for " << http
->getConn());
1226 // We need the following "if" for transparently bumped TLS connection,
1227 // because in this case we are running ssl_bump access list before
1228 // the doCallouts runs. It can be removed after the bug #4340 fixed.
1229 // We do not want to proceed to bumping steps:
1230 // - if the TLS connection with the client is already established
1231 // because we are accepting normal HTTP requests on TLS port,
1232 // or because of the client-first bumping mode
1233 // - When the bumping is already started
1234 if (!http
->getConn()->switchedToHttps() &&
1235 !http
->getConn()->serverBump())
1236 http
->sslBumpNeed(bumpMode
); // for processRequest() to bump if needed and not already bumped
1237 http
->al
->ssl
.bumpMode
= bumpMode
; // inherited from bumped connection
1241 // If we have not decided yet, decide whether to bump now.
1243 // Bumping here can only start with a CONNECT request on a bumping port
1244 // (bumping of intercepted SSL conns is decided before we get 1st request).
1245 // We also do not bump redirected CONNECT requests.
1246 if (http
->request
->method
!= Http::METHOD_CONNECT
|| http
->redirect
.status
||
1247 !Config
.accessList
.ssl_bump
||
1248 !http
->getConn()->port
->flags
.tunnelSslBumping
) {
1249 http
->al
->ssl
.bumpMode
= Ssl::bumpEnd
; // SslBump does not apply; log -
1250 debugs(85, 5, "cannot SslBump this request");
1254 // Do not bump during authentication: clients would not proxy-authenticate
1255 // if we delay a 407 response and respond with 200 OK to CONNECT.
1256 if (error
&& error
->httpStatus
== Http::scProxyAuthenticationRequired
) {
1257 http
->al
->ssl
.bumpMode
= Ssl::bumpEnd
; // SslBump does not apply; log -
1258 debugs(85, 5, "no SslBump during proxy authentication");
1263 debugs(85, 5, "SslBump applies. Force bump action on error " << errorTypeName(error
->type
));
1264 http
->sslBumpNeed(Ssl::bumpBump
);
1265 http
->al
->ssl
.bumpMode
= Ssl::bumpBump
;
1269 debugs(85, 5, "SslBump possible, checking ACL");
1271 auto aclChecklist
= clientAclChecklistCreate(Config
.accessList
.ssl_bump
, http
);
1272 ACLFilledChecklist::NonBlockingCheck(std::move(aclChecklist
), sslBumpAccessCheckDoneWrapper
, this);
1277 * A wrapper function to use the ClientRequestContext::sslBumpAccessCheckDone method
1278 * as ACLFilledChecklist callback
1281 sslBumpAccessCheckDoneWrapper(Acl::Answer answer
, void *data
)
1283 ClientRequestContext
*calloutContext
= static_cast<ClientRequestContext
*>(data
);
1284 calloutContext
->sslBumpAccessCheckDone(answer
);
1288 ClientRequestContext::sslBumpAccessCheckDone(const Acl::Answer
&answer
)
1290 const Ssl::BumpMode bumpMode
= answer
.allowed() ?
1291 static_cast<Ssl::BumpMode
>(answer
.kind
) : Ssl::bumpSplice
;
1292 http
->sslBumpNeed(bumpMode
); // for processRequest() to bump if needed
1293 http
->al
->ssl
.bumpMode
= bumpMode
; // for logging
1295 if (bumpMode
== Ssl::bumpTerminate
) {
1296 const Comm::ConnectionPointer clientConn
= http
->getConn() ? http
->getConn()->clientConnection
: nullptr;
1297 if (Comm::IsConnOpen(clientConn
)) {
1298 debugs(85, 3, "closing after Ssl::bumpTerminate ");
1299 clientConn
->close();
1309 * Identify requests that do not go through the store and client side stream
1310 * and forward them to the appropriate location. All other requests, request
1314 ClientHttpRequest::processRequest()
1316 debugs(85, 4, request
->method
<< ' ' << uri
);
1318 const bool untouchedConnect
= request
->method
== Http::METHOD_CONNECT
&& !redirect
.status
;
1321 if (untouchedConnect
&& sslBumpNeeded()) {
1322 assert(!request
->flags
.forceTunnel
);
1328 if (untouchedConnect
|| request
->flags
.forceTunnel
) {
1329 getConn()->stopReading(); // tunnels read for themselves
1338 ClientHttpRequest::httpStart()
1340 // XXX: Re-initializes rather than updates. Should not be needed at all.
1341 updateLoggingTags(LOG_TAG_NONE
);
1342 debugs(85, 4, loggingTags().c_str() << " for '" << uri
<< "'");
1344 /* no one should have touched this */
1345 assert(out
.offset
== 0);
1346 /* Use the Stream Luke */
1347 clientStreamNode
*node
= (clientStreamNode
*)client_stream
.tail
->data
;
1348 clientStreamRead(node
, this, node
->readBuffer
);
1354 ClientHttpRequest::sslBumpNeed(Ssl::BumpMode mode
)
1356 debugs(83, 3, "sslBump required: "<< Ssl::bumpMode(mode
));
1357 sslBumpNeed_
= mode
;
1360 // called when comm_write has completed
1362 SslBumpEstablish(const Comm::ConnectionPointer
&, char *, size_t, Comm::Flag errflag
, int, void *data
)
1364 ClientHttpRequest
*r
= static_cast<ClientHttpRequest
*>(data
);
1365 debugs(85, 5, "responded to CONNECT: " << r
<< " ? " << errflag
);
1366 r
->sslBumpEstablish(errflag
);
1370 ClientHttpRequest::sslBumpEstablish(Comm::Flag errflag
)
1372 // Bail out quickly on Comm::ERR_CLOSING - close handlers will tidy up
1373 if (errflag
== Comm::ERR_CLOSING
)
1377 debugs(85, 3, "CONNECT response failure in SslBump: " << errflag
);
1378 getConn()->clientConnection
->close();
1383 // Preserve authentication info for the ssl-bumped request
1384 if (request
->auth_user_request
!= nullptr)
1385 getConn()->setAuth(request
->auth_user_request
, "SSL-bumped CONNECT");
1388 assert(sslBumpNeeded());
1389 getConn()->switchToHttps(this, sslBumpNeed_
);
1393 ClientHttpRequest::sslBumpStart()
1395 debugs(85, 5, "Confirming " << Ssl::bumpMode(sslBumpNeed_
) <<
1396 "-bumped CONNECT tunnel on FD " << getConn()->clientConnection
);
1397 getConn()->sslBumpMode
= sslBumpNeed_
;
1399 AsyncCall::Pointer bumpCall
= commCbCall(85, 5, "ClientSocketContext::sslBumpEstablish",
1400 CommIoCbPtrFun(&SslBumpEstablish
, this));
1402 if (request
->flags
.interceptTproxy
|| request
->flags
.intercepted
) {
1403 CommIoCbParams
¶ms
= GetCommParams
<CommIoCbParams
>(bumpCall
);
1404 params
.flag
= Comm::OK
;
1405 params
.conn
= getConn()->clientConnection
;
1406 ScheduleCallHere(bumpCall
);
1410 al
->reply
= HttpReply::MakeConnectionEstablished();
1412 const auto mb
= al
->reply
->pack();
1413 // send an HTTP 200 response to kick client SSL negotiation
1414 // TODO: Unify with tunnel.cc and add a Server(?) header
1415 Comm::Write(getConn()->clientConnection
, mb
, bumpCall
);
1422 ClientHttpRequest::updateError(const Error
&error
)
1425 request
->error
.update(error
);
1427 al
->updateError(error
);
1431 ClientHttpRequest::gotEnough() const
1433 // TODO: See also (and unify with) clientReplyContext::storeNotOKTransferDone()
1434 int64_t contentLength
=
1435 memObject()->baseReply().bodySize(request
->method
);
1436 assert(contentLength
>= 0);
1438 if (out
.offset
< contentLength
)
1445 ClientHttpRequest::storeEntry(StoreEntry
*newEntry
)
1451 ClientHttpRequest::loggingEntry(StoreEntry
*newEntry
)
1454 loggingEntry_
->unlock("ClientHttpRequest::loggingEntry");
1456 loggingEntry_
= newEntry
;
1459 loggingEntry_
->lock("ClientHttpRequest::loggingEntry");
1463 ClientHttpRequest::initRequest(HttpRequest
*aRequest
)
1465 assignRequest(aRequest
);
1466 if (const auto csd
= getConn()) {
1467 if (!csd
->notes()->empty())
1468 request
->notes()->appendNewOnly(csd
->notes().getRaw());
1470 // al is created in the constructor
1473 al
->request
= request
;
1474 HTTPMSGLOCK(al
->request
);
1475 al
->syncNotes(request
);
1480 ClientHttpRequest::resetRequest(HttpRequest
*newRequest
)
1482 const auto uriChanged
= request
->effectiveRequestUri() != newRequest
->effectiveRequestUri();
1483 resetRequestXXX(newRequest
, uriChanged
);
1487 ClientHttpRequest::resetRequestXXX(HttpRequest
*newRequest
, const bool uriChanged
)
1489 assert(request
!= newRequest
);
1491 assignRequest(newRequest
);
1493 uri
= SBufToCstring(request
->effectiveRequestUri());
1496 request
->flags
.redirected
= true;
1497 checkForInternalAccess();
1502 ClientHttpRequest::checkForInternalAccess()
1504 if (!internalCheck(request
->url
.path()))
1507 if (request
->url
.port() == getMyPort() && internalHostnameIs(SBuf(request
->url
.host()))) {
1508 debugs(33, 3, "internal URL found: " << request
->url
.getScheme() << "://" << request
->url
.authority(true));
1509 request
->flags
.internal
= true;
1510 } else if (Config
.onoff
.global_internal_static
&& internalStaticCheck(request
->url
.path())) {
1511 debugs(33, 3, "internal URL found: " << request
->url
.getScheme() << "://" << request
->url
.authority(true) << " (global_internal_static on)");
1512 request
->url
.setScheme(AnyP::PROTO_HTTP
, "http");
1513 request
->url
.host(internalHostname());
1514 request
->url
.port(getMyPort());
1515 request
->flags
.internal
= true;
1516 setLogUriToRequestUri();
1518 debugs(33, 3, "internal URL found: " << request
->url
.getScheme() << "://" << request
->url
.authority(true) << " (not this proxy)");
1521 if (ForSomeCacheManager(request
->url
.path()))
1522 request
->flags
.disableCacheUse("cache manager URL");
1526 ClientHttpRequest::assignRequest(HttpRequest
*newRequest
)
1530 const_cast<HttpRequest
*&>(request
) = newRequest
;
1531 HTTPMSGLOCK(request
);
1532 setLogUriToRequestUri();
1536 ClientHttpRequest::clearRequest()
1538 HttpRequest
*oldRequest
= request
;
1539 HTTPMSGUNLOCK(oldRequest
);
1540 const_cast<HttpRequest
*&>(request
) = nullptr;
1541 absorbLogUri(nullptr);
1545 * doCallouts() - This function controls the order of "callout"
1546 * executions, including non-blocking access control checks, the
1547 * redirector, and ICAP. Previously, these callouts were chained
1548 * together such that "clientAccessCheckDone()" would call
1549 * "clientRedirectStart()" and so on.
1551 * The ClientRequestContext (aka calloutContext) class holds certain
1552 * state data for the callout/callback operations. Previously
1553 * ClientHttpRequest would sort of hand off control to ClientRequestContext
1554 * for a short time. ClientRequestContext would then delete itself
1555 * and pass control back to ClientHttpRequest when all callouts
1558 * This caused some problems for ICAP because we want to make the
1559 * ICAP callout after checking ACLs, but before checking the no_cache
1560 * list. We can't stuff the ICAP state into the ClientRequestContext
1561 * class because we still need the ICAP state after ClientRequestContext
1564 * Note that ClientRequestContext is created before the first call
1567 * Note that we set the _done flags here before actually starting
1568 * the callout. This is strictly for convenience.
1572 ClientHttpRequest::doCallouts()
1574 assert(calloutContext
);
1576 if (!calloutContext
->error
) {
1577 // CVE-2009-0801: verify the Host: header is consistent with other known details.
1578 if (!calloutContext
->host_header_verify_done
) {
1579 debugs(83, 3, "Doing calloutContext->hostHeaderVerify()");
1580 calloutContext
->host_header_verify_done
= true;
1581 calloutContext
->hostHeaderVerify();
1585 if (!calloutContext
->http_access_done
) {
1586 debugs(83, 3, "Doing calloutContext->clientAccessCheck()");
1587 calloutContext
->http_access_done
= true;
1588 calloutContext
->clientAccessCheck();
1593 if (!calloutContext
->adaptation_acl_check_done
) {
1594 calloutContext
->adaptation_acl_check_done
= true;
1595 if (Adaptation::AccessCheck::Start(
1596 Adaptation::methodReqmod
, Adaptation::pointPreCache
,
1597 request
, nullptr, calloutContext
->http
->al
, this))
1598 return; // will call callback
1602 if (!calloutContext
->redirect_done
) {
1603 calloutContext
->redirect_done
= true;
1605 if (Config
.Program
.redirect
) {
1606 debugs(83, 3, "Doing calloutContext->clientRedirectStart()");
1607 calloutContext
->redirect_state
= REDIRECT_PENDING
;
1608 calloutContext
->clientRedirectStart();
1613 if (!calloutContext
->adapted_http_access_done
) {
1614 debugs(83, 3, "Doing calloutContext->clientAccessCheck2()");
1615 calloutContext
->adapted_http_access_done
= true;
1616 calloutContext
->clientAccessCheck2();
1620 if (!calloutContext
->store_id_done
) {
1621 calloutContext
->store_id_done
= true;
1623 if (Config
.Program
.store_id
) {
1624 debugs(83, 3,"Doing calloutContext->clientStoreIdStart()");
1625 calloutContext
->store_id_state
= REDIRECT_PENDING
;
1626 calloutContext
->clientStoreIdStart();
1631 if (!calloutContext
->interpreted_req_hdrs
) {
1632 debugs(83, 3, "Doing clientInterpretRequestHeaders()");
1633 calloutContext
->interpreted_req_hdrs
= 1;
1634 clientInterpretRequestHeaders(this);
1637 if (!calloutContext
->no_cache_done
) {
1638 calloutContext
->no_cache_done
= true;
1640 if (Config
.accessList
.noCache
&& request
->flags
.cachable
) {
1641 debugs(83, 3, "Doing calloutContext->checkNoCache()");
1642 calloutContext
->checkNoCache();
1646 } // if !calloutContext->error
1648 // Set appropriate MARKs and CONNMARKs if needed.
1649 if (getConn() && Comm::IsConnOpen(getConn()->clientConnection
)) {
1650 ACLFilledChecklist
ch(nullptr, request
);
1651 ch
.al
= calloutContext
->http
->al
;
1652 ch
.src_addr
= request
->client_addr
;
1653 ch
.my_addr
= request
->my_addr
;
1654 ch
.syncAle(request
, log_uri
);
1656 if (!calloutContext
->toClientMarkingDone
) {
1657 calloutContext
->toClientMarkingDone
= true;
1658 tos_t tos
= aclMapTOS(Ip::Qos::TheConfig
.tosToClient
, &ch
);
1660 Ip::Qos::setSockTos(getConn()->clientConnection
, tos
);
1662 const auto packetMark
= aclFindNfMarkConfig(Ip::Qos::TheConfig
.nfmarkToClient
, &ch
);
1663 if (!packetMark
.isEmpty())
1664 Ip::Qos::setSockNfmark(getConn()->clientConnection
, packetMark
.mark
);
1666 const auto connmark
= aclFindNfMarkConfig(Ip::Qos::TheConfig
.nfConnmarkToClient
, &ch
);
1667 if (!connmark
.isEmpty())
1668 Ip::Qos::setNfConnmark(getConn()->clientConnection
, Ip::Qos::dirAccepted
, connmark
);
1673 // Even with calloutContext->error, we call sslBumpAccessCheck() to decide
1674 // whether SslBump applies to this transaction. If it applies, we will
1675 // attempt to bump the client to serve the error.
1676 if (!calloutContext
->sslBumpCheckDone
) {
1677 calloutContext
->sslBumpCheckDone
= true;
1678 if (calloutContext
->sslBumpAccessCheck())
1680 /* else no ssl bump required*/
1684 if (calloutContext
->error
) {
1685 // XXX: prformance regression. c_str() reallocates
1686 SBuf
storeUriBuf(request
->storeId());
1687 const char *storeUri
= storeUriBuf
.c_str();
1688 StoreEntry
*e
= storeCreateEntry(storeUri
, storeUri
, request
->flags
, request
->method
);
1690 if (sslBumpNeeded()) {
1691 // We have to serve an error, so bump the client first.
1692 sslBumpNeed(Ssl::bumpClientFirst
);
1693 // set final error but delay sending until we bump
1694 Ssl::ServerBump
*srvBump
= new Ssl::ServerBump(this, e
, Ssl::bumpClientFirst
);
1695 errorAppendEntry(e
, calloutContext
->error
);
1696 calloutContext
->error
= nullptr;
1697 getConn()->setServerBump(srvBump
);
1698 e
->unlock("ClientHttpRequest::doCallouts+sslBumpNeeded");
1702 // send the error to the client now
1703 clientStreamNode
*node
= (clientStreamNode
*)client_stream
.tail
->prev
->data
;
1704 clientReplyContext
*repContext
= dynamic_cast<clientReplyContext
*>(node
->data
.getRaw());
1705 assert (repContext
);
1706 repContext
->setReplyToStoreEntry(e
, "immediate SslBump error");
1707 errorAppendEntry(e
, calloutContext
->error
);
1708 calloutContext
->error
= nullptr;
1709 if (calloutContext
->readNextRequest
&& getConn())
1710 getConn()->flags
.readMore
= true; // resume any pipeline reads.
1711 node
= (clientStreamNode
*)client_stream
.tail
->data
;
1712 clientStreamRead(node
, this, node
->readBuffer
);
1713 e
->unlock("ClientHttpRequest::doCallouts-sslBumpNeeded");
1718 delete calloutContext
;
1719 calloutContext
= nullptr;
1721 debugs(83, 3, "calling processRequest()");
1725 Adaptation::Icap::History::Pointer ih
= request
->icapHistory();
1727 ih
->logType
= loggingTags();
1732 ClientHttpRequest::setLogUriToRequestUri()
1735 const auto canonicalUri
= request
->canonicalCleanUrl();
1736 absorbLogUri(xstrndup(canonicalUri
, MAX_URL
));
1740 ClientHttpRequest::setLogUriToRawUri(const char *rawUri
, const HttpRequestMethod
&method
)
1743 // Should(!request);
1745 // TODO: SBuf() performance regression, fix by converting rawUri to SBuf
1746 char *canonicalUri
= urlCanonicalCleanWithoutRequest(SBuf(rawUri
), method
, AnyP::UriScheme());
1748 absorbLogUri(AnyP::Uri::cleanup(canonicalUri
));
1750 char *cleanedRawUri
= AnyP::Uri::cleanup(rawUri
);
1751 al
->setVirginUrlForMissingRequest(SBuf(cleanedRawUri
));
1752 xfree(cleanedRawUri
);
1756 ClientHttpRequest::absorbLogUri(char *aUri
)
1759 const_cast<char *&>(log_uri
) = aUri
;
1763 ClientHttpRequest::setErrorUri(const char *aUri
)
1767 // Should(!request);
1769 uri
= xstrdup(aUri
);
1770 // TODO: SBuf() performance regression, fix by converting setErrorUri() parameter to SBuf
1771 const SBuf
errorUri(aUri
);
1772 const auto canonicalUri
= urlCanonicalCleanWithoutRequest(errorUri
, HttpRequestMethod(), AnyP::UriScheme());
1773 absorbLogUri(xstrndup(canonicalUri
, MAX_URL
));
1775 al
->setVirginUrlForMissingRequest(errorUri
);
1778 // XXX: This should not be a _request_ method. Move range_iter elsewhere.
1780 ClientHttpRequest::prepPartialResponseGeneration()
1783 assert(request
->range
);
1785 range_iter
.pos
= request
->range
->begin();
1786 range_iter
.end
= request
->range
->end();
1787 range_iter
.debt_size
= 0;
1788 const auto multipart
= request
->range
->specs
.size() > 1;
1790 range_iter
.boundary
= rangeBoundaryStr();
1791 range_iter
.valid
= true; // TODO: Remove.
1792 range_iter
.updateSpec(); // TODO: Refactor to initialize rather than update.
1794 assert(range_iter
.pos
!= range_iter
.end
);
1795 const auto &firstRange
= *range_iter
.pos
;
1797 out
.offset
= firstRange
->offset
;
1799 return multipart
? mRangeCLen() : firstRange
->length
;
1803 /// Initiate an asynchronous adaptation transaction which will call us back.
1805 ClientHttpRequest::startAdaptation(const Adaptation::ServiceGroupPointer
&g
)
1807 debugs(85, 3, "adaptation needed for " << this);
1808 assert(!virginHeadSource
);
1809 assert(!adaptedBodySource
);
1810 virginHeadSource
= initiateAdaptation(
1811 new Adaptation::Iterator(request
, nullptr, al
, g
));
1813 // we could try to guess whether we can bypass this adaptation
1814 // initiation failure, but it should not really happen
1815 Must(initiated(virginHeadSource
));
1819 ClientHttpRequest::noteAdaptationAnswer(const Adaptation::Answer
&answer
)
1821 clearAdaptation(virginHeadSource
);
1822 assert(!adaptedBodySource
);
1824 switch (answer
.kind
) {
1825 case Adaptation::Answer::akForward
:
1826 handleAdaptedHeader(const_cast<Http::Message
*>(answer
.message
.getRaw()));
1829 case Adaptation::Answer::akBlock
:
1830 handleAdaptationBlock(answer
);
1833 case Adaptation::Answer::akError
: {
1834 static const auto d
= MakeNamedErrorDetail("CLT_REQMOD_ABORT");
1835 handleAdaptationFailure(d
, !answer
.final
);
1842 ClientHttpRequest::handleAdaptedHeader(Http::Message
*msg
)
1846 if (HttpRequest
*new_req
= dynamic_cast<HttpRequest
*>(msg
)) {
1847 resetRequest(new_req
);
1848 assert(request
->method
.id());
1849 } else if (HttpReply
*new_rep
= dynamic_cast<HttpReply
*>(msg
)) {
1850 debugs(85,3, "REQMOD reply is HTTP reply");
1852 // subscribe to receive reply body
1853 if (new_rep
->body_pipe
!= nullptr) {
1854 adaptedBodySource
= new_rep
->body_pipe
;
1855 int consumer_ok
= adaptedBodySource
->setConsumerIfNotLate(this);
1856 assert(consumer_ok
);
1859 clientStreamNode
*node
= (clientStreamNode
*)client_stream
.tail
->prev
->data
;
1860 clientReplyContext
*repContext
= dynamic_cast<clientReplyContext
*>(node
->data
.getRaw());
1862 repContext
->createStoreEntry(request
->method
, request
->flags
);
1864 request_satisfaction_mode
= true;
1865 request_satisfaction_offset
= 0;
1866 storeEntry()->replaceHttpReply(new_rep
);
1867 storeEntry()->timestampsSet();
1869 al
->reply
= new_rep
;
1871 if (request
->method
== Http::METHOD_CONNECT
) {
1872 // Squid has not established a tunnel. We forward the response
1873 // generated by the adaptation service to the HTTP client, but the
1874 // service becomes responsible for the client's reaction to this
1875 // response. A typical use case is a service that responds with a
1876 // "block page" implemented as an HTTP error response.
1878 // Since we are not going to tunnel, remove clientProcessRequest()'s
1879 // ban on reading post-CONNECT HTTP requests.
1880 if (const auto c
= getConn())
1881 c
->flags
.readMore
= true;
1884 if (!adaptedBodySource
) // no body
1885 storeEntry()->complete();
1886 clientGetMoreData(node
, this);
1889 // we are done with getting headers (but may be receiving body)
1890 clearAdaptation(virginHeadSource
);
1892 if (!request_satisfaction_mode
)
1897 ClientHttpRequest::handleAdaptationBlock(const Adaptation::Answer
&answer
)
1899 static const auto d
= MakeNamedErrorDetail("REQMOD_BLOCK");
1900 request
->detailError(ERR_ACCESS_DENIED
, d
);
1901 assert(calloutContext
);
1902 calloutContext
->clientAccessCheckDone(answer
.blockedToChecklistAnswer());
1906 ClientHttpRequest::resumeBodyStorage()
1908 if (!adaptedBodySource
)
1911 noteMoreBodyDataAvailable(adaptedBodySource
);
1915 ClientHttpRequest::noteMoreBodyDataAvailable(BodyPipe::Pointer
)
1917 assert(request_satisfaction_mode
);
1918 assert(adaptedBodySource
!= nullptr);
1920 if (size_t contentSize
= adaptedBodySource
->buf().contentSize()) {
1921 const size_t spaceAvailable
= storeEntry()->bytesWanted(Range
<size_t>(0,contentSize
));
1923 if (spaceAvailable
< contentSize
) {
1924 // No or partial body data consuming
1925 typedef NullaryMemFunT
<ClientHttpRequest
> Dialer
;
1926 AsyncCall::Pointer call
= asyncCall(93, 5, "ClientHttpRequest::resumeBodyStorage",
1927 Dialer(this, &ClientHttpRequest::resumeBodyStorage
));
1928 storeEntry()->deferProducer(call
);
1931 if (!spaceAvailable
)
1934 if (spaceAvailable
< contentSize
)
1935 contentSize
= spaceAvailable
;
1937 BodyPipeCheckout
bpc(*adaptedBodySource
);
1938 const StoreIOBuffer
ioBuf(&bpc
.buf
, request_satisfaction_offset
, contentSize
);
1939 storeEntry()->write(ioBuf
);
1940 // assume StoreEntry::write() writes the entire ioBuf
1941 request_satisfaction_offset
+= ioBuf
.length
;
1942 bpc
.buf
.consume(contentSize
);
1946 if (adaptedBodySource
->exhausted()) {
1947 // XXX: Setting receivedWholeAdaptedReply here is a workaround for a
1948 // regression, as described in https://bugs.squid-cache.org/show_bug.cgi?id=5187#c6
1949 receivedWholeAdaptedReply
= true;
1950 debugs(85, Important(72), "WARNING: Squid bug 5187 workaround triggered");
1951 endRequestSatisfaction();
1953 // else wait for more body data
1957 ClientHttpRequest::noteBodyProductionEnded(BodyPipe::Pointer
)
1959 assert(!virginHeadSource
);
1961 // distinguish this code path from future noteBodyProducerAborted() that
1962 // would continue storing/delivering (truncated) reply if necessary (TODO)
1963 receivedWholeAdaptedReply
= true;
1965 // should we end request satisfaction now?
1966 if (adaptedBodySource
!= nullptr && adaptedBodySource
->exhausted())
1967 endRequestSatisfaction();
1971 ClientHttpRequest::endRequestSatisfaction()
1973 debugs(85,4, this << " ends request satisfaction");
1974 assert(request_satisfaction_mode
);
1975 stopConsumingFrom(adaptedBodySource
);
1977 // TODO: anything else needed to end store entry formation correctly?
1978 if (receivedWholeAdaptedReply
) {
1979 // We received the entire reply per receivedWholeAdaptedReply.
1980 // We are called when we consumed everything received (per our callers).
1981 // We consume only what we store per noteMoreBodyDataAvailable().
1982 storeEntry()->completeSuccessfully("received, consumed, and, hence, stored the entire REQMOD reply");
1984 storeEntry()->completeTruncated("REQMOD request satisfaction default");
1989 ClientHttpRequest::noteBodyProducerAborted(BodyPipe::Pointer
)
1991 assert(!virginHeadSource
);
1992 stopConsumingFrom(adaptedBodySource
);
1994 debugs(85,3, "REQMOD body production failed");
1995 if (request_satisfaction_mode
) { // too late to recover or serve an error
1996 static const auto d
= MakeNamedErrorDetail("CLT_REQMOD_RESP_BODY");
1997 request
->detailError(ERR_ICAP_FAILURE
, d
);
1998 const Comm::ConnectionPointer c
= getConn()->clientConnection
;
1999 Must(Comm::IsConnOpen(c
));
2000 c
->close(); // drastic, but we may be writing a response already
2002 static const auto d
= MakeNamedErrorDetail("CLT_REQMOD_REQ_BODY");
2003 handleAdaptationFailure(d
);
2008 ClientHttpRequest::handleAdaptationFailure(const ErrorDetail::Pointer
&errDetail
, bool bypassable
)
2010 debugs(85,3, "handleAdaptationFailure(" << bypassable
<< ")");
2012 const bool usedStore
= storeEntry() && !storeEntry()->isEmpty();
2013 const bool usedPipe
= request
->body_pipe
!= nullptr &&
2014 request
->body_pipe
->consumedSize() > 0;
2016 if (bypassable
&& !usedStore
&& !usedPipe
) {
2017 debugs(85,3, "ICAP REQMOD callout failed, bypassing: " << calloutContext
);
2023 debugs(85,3, "ICAP REQMOD callout failed, responding with error");
2025 clientStreamNode
*node
= (clientStreamNode
*)client_stream
.tail
->prev
->data
;
2026 clientReplyContext
*repContext
= dynamic_cast<clientReplyContext
*>(node
->data
.getRaw());
2029 calloutsError(ERR_ICAP_FAILURE
, errDetail
);
2036 ClientHttpRequest::callException(const std::exception
&ex
)
2038 if (const auto clientConn
= getConn() ? getConn()->clientConnection
: nullptr) {
2039 if (Comm::IsConnOpen(clientConn
)) {
2040 debugs(85, 3, "closing after exception: " << ex
.what());
2041 clientConn
->close(); // initiate orderly top-to-bottom cleanup
2045 debugs(85, DBG_IMPORTANT
, "ClientHttpRequest exception without connection. Ignoring " << ex
.what());
2046 // XXX: Normally, we mustStop() but we cannot do that here because it is
2047 // likely to leave Http::Stream and ConnStateData with a dangling http
2048 // pointer. See r13480 or XXX in Http::Stream class description.
2052 // XXX: modify and use with ClientRequestContext::clientAccessCheckDone too.
2054 ClientHttpRequest::calloutsError(const err_type error
, const ErrorDetail::Pointer
&errDetail
)
2056 // The original author of the code also wanted to pass an errno to
2057 // setReplyToError, but it seems unlikely that the errno reflects the
2058 // true cause of the error at this point, so I did not pass it.
2059 if (calloutContext
) {
2060 ConnStateData
* c
= getConn();
2061 calloutContext
->error
= clientBuildError(error
, Http::scInternalServerError
,
2062 nullptr, c
, request
, al
);
2064 calloutContext
->error
->auth_user_request
=
2065 c
!= nullptr && c
->getAuth() != nullptr ? c
->getAuth() : request
->auth_user_request
;
2067 calloutContext
->error
->detailError(errDetail
);
2068 calloutContext
->readNextRequest
= true;
2070 c
->expectNoForwarding();
2072 //else if(calloutContext == NULL) is it possible?