client_side_request.cc
Go to the documentation of this file.
1/*
2 * Copyright (C) 1996-2023 The Squid Software Foundation and contributors
3 *
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.
7 */
8
9/* DEBUG: section 85 Client-side Request Routines */
10
11/*
12 * General logic of request processing:
13 *
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.
17 */
18
19#include "squid.h"
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"
28#include "clientStream.h"
29#include "comm/Connection.h"
30#include "comm/Write.h"
31#include "error/Detail.h"
32#include "errorpage.h"
33#include "fd.h"
34#include "fde.h"
35#include "format/Token.h"
36#include "FwdState.h"
37#include "helper.h"
38#include "helper/Reply.h"
39#include "http.h"
40#include "http/Stream.h"
41#include "HttpHdrCc.h"
42#include "HttpReply.h"
43#include "HttpRequest.h"
44#include "ip/NfMarkConfig.h"
45#include "ip/QosConfig.h"
46#include "ipcache.h"
47#include "log/access_log.h"
48#include "MemObject.h"
49#include "Parsing.h"
50#include "proxyp/Header.h"
51#include "redirect.h"
52#include "rfc1738.h"
53#include "sbuf/StringConvert.h"
54#include "SquidConfig.h"
55#include "Store.h"
56#include "StrList.h"
57#include "tools.h"
58#include "wordlist.h"
59#if USE_AUTH
60#include "auth/UserRequest.h"
61#endif
62#if USE_ADAPTATION
64#include "adaptation/Answer.h"
65#include "adaptation/Iterator.h"
66#include "adaptation/Service.h"
67#if ICAP_CLIENT
69#endif
70#endif
71#if USE_OPENSSL
72#include "ssl/ServerBump.h"
73#include "ssl/support.h"
74#endif
75
76#if FOLLOW_X_FORWARDED_FOR
77static void clientFollowXForwardedForCheck(Acl::Answer answer, void *data);
78#endif /* FOLLOW_X_FORWARDED_FOR */
79
81
83
84/* Local functions */
85/* other */
86static void clientAccessCheckDoneWrapper(Acl::Answer, void *);
87#if USE_OPENSSL
89#endif
90static int clientHierarchical(ClientHttpRequest * http);
94static void checkNoCacheDoneWrapper(Acl::Answer, void *);
99
101{
102 /*
103 * Release our "lock" on our parent, ClientHttpRequest, if we
104 * still have one
105 */
106
107 if (http)
109
110 delete error;
111 debugs(85,3, "ClientRequestContext destructed, this=" << this);
112}
113
115 http(cbdataReference(anHttp))
116{
117 debugs(85, 3, "ClientRequestContext constructed, this=" << this);
118}
119
121
123#if USE_ADAPTATION
124 AsyncJob("ClientHttpRequest"),
125#endif
126 al(new AccessLogEntry()),
127 conn_(cbdataReference(aConn))
128{
131 if (aConn) {
132 al->tcpClient = aConn->clientConnection;
133 al->cache.port = aConn->port;
134 al->cache.caddr = aConn->log_addr;
136 al->updateError(aConn->bareError);
137
138#if USE_OPENSSL
139 if (aConn->clientConnection != nullptr && aConn->clientConnection->isOpen()) {
140 if (auto ssl = fd_table[aConn->clientConnection->fd].ssl.get())
141 al->cache.sslClientCert.resetWithoutLocking(SSL_get_peer_certificate(ssl));
142 }
143#endif
144 }
146}
147
148/*
149 * returns true if client specified that the object must come from the cache
150 * without contacting origin server
151 */
152bool
154{
156 return request->cache_control &&
158}
159
172static void
174{
175 // Can be set at compile time with -D compiler flag
176#ifndef FAILURE_MODE_TIME
177#define FAILURE_MODE_TIME 300
178#endif
179
180 if (hcode == HIER_NONE)
181 return;
182
183 // don't bother when ICP is disabled.
184 if (Config.Port.icp <= 0)
185 return;
186
187 static double magic_factor = 100.0;
188 double n_good;
189 double n_bad;
190
191 n_good = magic_factor / (1.0 + request_failure_ratio);
192
193 n_bad = magic_factor - n_good;
194
195 switch (etype) {
196
197 case ERR_DNS_FAIL:
198
199 case ERR_CONNECT_FAIL:
201
202 case ERR_READ_ERROR:
203 ++n_bad;
204 break;
205
206 default:
207 ++n_good;
208 }
209
210 request_failure_ratio = n_bad / n_good;
211
213 return;
214
215 if (request_failure_ratio < 1.0)
216 return;
217
218 debugs(33, DBG_CRITICAL, "WARNING: Failure Ratio at "<< std::setw(4)<<
219 std::setprecision(3) << request_failure_ratio);
220
221 debugs(33, DBG_CRITICAL, "WARNING: ICP going into HIT-only mode for " <<
222 FAILURE_MODE_TIME / 60 << " minutes...");
223
225
226 request_failure_ratio = 0.8; /* reset to something less than 1.0 */
227}
228
230{
231 debugs(33, 3, "httpRequestFree: " << uri);
232
233 // Even though freeResources() below may destroy the request,
234 // we no longer set request->body_pipe to NULL here
235 // because we did not initiate that pipe (ConnStateData did)
236
237 /* the ICP check here was erroneous
238 * - StoreEntry::releaseRequest was always called if entry was valid
239 */
240
241 logRequest();
242
243 loggingEntry(nullptr);
244
245 if (request)
247
249
250#if USE_ADAPTATION
252
253 if (adaptedBodySource != nullptr)
255#endif
256
257 delete calloutContext;
258
259 if (conn_)
261
262 /* moving to the next connection is handled by the context free */
264}
265
275int
276clientBeginRequest(const HttpRequestMethod& method, char const *url, CSCB * streamcallback,
277 CSD * streamdetach, ClientStreamData streamdata, HttpHeader const *header,
278 char *tailbuf, size_t taillen, const MasterXaction::Pointer &mx)
279{
280 size_t url_sz;
281 ClientHttpRequest *http = new ClientHttpRequest(nullptr);
282 HttpRequest *request;
283 StoreIOBuffer tempBuffer;
284 if (http->al != nullptr)
286 /* this is only used to adjust the connection offset in client_side.c */
287 http->req_sz = 0;
288 tempBuffer.length = taillen;
289 tempBuffer.data = tailbuf;
290 /* client stream setup */
292 clientReplyStatus, new clientReplyContext(http), streamcallback,
293 streamdetach, streamdata, tempBuffer);
294 /* make it visible in the 'current acctive requests list' */
295 /* Set flags */
296 /* internal requests only makes sense in an
297 * accelerator today. TODO: accept flags ? */
298 http->flags.accel = true;
299 /* allow size for url rewriting */
300 url_sz = strlen(url) + Config.appendDomainLen + 5;
301 http->uri = (char *)xcalloc(url_sz, 1);
302 strcpy(http->uri, url); // XXX: polluting http->uri before parser validation
303
304 request = HttpRequest::FromUrlXXX(http->uri, mx, method);
305 if (!request) {
306 debugs(85, 5, "Invalid URL: " << http->uri);
307 return -1;
308 }
309
310 /*
311 * now update the headers in request with our supplied headers.
312 * HttpRequest::FromUrl() should return a blank header set, but
313 * we use Update to be sure of correctness.
314 */
315 if (header)
316 request->header.update(header);
317
318 /* http struct now ready */
319
320 /*
321 * build new header list *? TODO
322 */
323 request->flags.accelerated = http->flags.accel;
324
325 /* this is an internally created
326 * request, not subject to acceleration
327 * target overrides */
328 // TODO: detect and handle internal requests of internal objects?
329
330 /* Internally created requests cannot have bodies today */
331 request->content_length = 0;
332
333 request->client_addr.setNoAddr();
334
335#if FOLLOW_X_FORWARDED_FOR
337#endif /* FOLLOW_X_FORWARDED_FOR */
338
339 request->my_addr.setNoAddr(); /* undefined for internal requests */
340
341 request->my_addr.port(0);
342
343 request->http_ver = Http::ProtocolVersion();
344
345 http->initRequest(request);
346
347 /* optional - skip the access check ? */
348 http->calloutContext = new ClientRequestContext(http);
349
350 http->calloutContext->http_access_done = false;
351
352 http->calloutContext->redirect_done = true;
353
354 http->calloutContext->no_cache_done = true;
355
356 http->doCallouts();
357
358 return 0;
359}
360
361bool
363{
364 ClientHttpRequest *http_ = http;
365
366 if (cbdataReferenceValid(http_))
367 return true;
368
369 http = nullptr;
370
371 cbdataReferenceDone(http_);
372
373 return false;
374}
375
376#if FOLLOW_X_FORWARDED_FOR
391static void
393{
394 ClientRequestContext *calloutContext = (ClientRequestContext *) data;
395
396 if (!calloutContext->httpStateIsValid())
397 return;
398
399 ClientHttpRequest *http = calloutContext->http;
400 HttpRequest *request = http->request;
401
402 if (answer.allowed() && request->x_forwarded_for_iterator.size() != 0) {
403
404 /*
405 * Remove the last comma-delimited element from the
406 * x_forwarded_for_iterator and use it to repeat the cycle.
407 */
408 const char *p;
409 const char *asciiaddr;
410 int l;
411 Ip::Address addr;
412 p = request->x_forwarded_for_iterator.termedBuf();
413 l = request->x_forwarded_for_iterator.size();
414
415 /*
416 * XXX x_forwarded_for_iterator should really be a list of
417 * IP addresses, but it's a String instead. We have to
418 * walk backwards through the String, biting off the last
419 * comma-delimited part each time. As long as the data is in
420 * a String, we should probably implement and use a variant of
421 * strListGetItem() that walks backwards instead of forwards
422 * through a comma-separated list. But we don't even do that;
423 * we just do the work in-line here.
424 */
425 /* skip trailing space and commas */
426 while (l > 0 && (p[l-1] == ',' || xisspace(p[l-1])))
427 --l;
428 request->x_forwarded_for_iterator.cut(l);
429 /* look for start of last item in list */
430 while (l > 0 && ! (p[l-1] == ',' || xisspace(p[l-1])))
431 --l;
432 asciiaddr = p+l;
433 if ((addr = asciiaddr)) {
434 request->indirect_client_addr = addr;
435 request->x_forwarded_for_iterator.cut(l);
438 /* override the default src_addr tested if we have to go deeper than one level into XFF */
439 Filled(calloutContext->acl_checklist)->src_addr = request->indirect_client_addr;
440 }
442 return;
443 }
444 }
445
446 /* clean up, and pass control to clientAccessCheck */
448 /*
449 * Ensure that the access log shows the indirect client
450 * instead of the direct client.
451 */
452 http->al->cache.caddr = request->indirect_client_addr;
453 if (ConnStateData *conn = http->getConn())
454 conn->log_addr = request->indirect_client_addr;
455 }
457 request->flags.done_follow_x_forwarded_for = true;
458
459 if (answer.conflicted()) {
460 debugs(28, DBG_CRITICAL, "ERROR: Processing X-Forwarded-For. Stopping at IP address: " << request->indirect_client_addr );
461 }
462
463 /* process actual access ACL as normal. */
464 calloutContext->clientAccessCheck();
465}
466#endif /* FOLLOW_X_FORWARDED_FOR */
467
468static void
470{
471 ClientRequestContext *c = static_cast<ClientRequestContext*>(data);
472 c->hostHeaderIpVerify(ia, dns);
473}
474
475void
477{
479
480 // note the DNS details for the transaction stats.
482
483 // Is the NAT destination IP in DNS?
484 if (ia && ia->have(clientConn->local)) {
485 debugs(85, 3, "validate IP " << clientConn->local << " possible from Host:");
487 http->doCallouts();
488 return;
489 }
490 debugs(85, 3, "FAIL: validate IP " << clientConn->local << " possible from Host:");
491 hostHeaderVerifyFailed("local IP", "any domain IP");
492}
493
494void
496{
497 // IP address validation for Host: failed. Admin wants to ignore them.
498 // NP: we do not yet handle CONNECT tunnels well, so ignore for them
500 debugs(85, 3, "SECURITY ALERT: Host header forgery detected on " << http->getConn()->clientConnection <<
501 " (" << A << " does not match " << B << ") on URL: " << http->request->effectiveRequestUri());
502
503 // MUST NOT cache (for now). It is tempting to set flags.noCache, but
504 // that flag is about satisfying _this_ request. We are actually OK with
505 // satisfying this request from the cache, but want to prevent _other_
506 // requests from being satisfied using this response.
508
509 // XXX: when we have updated the cache key to base on raw-IP + URI this cacheable limit can go.
510 http->request->flags.hierarchical = false; // MUST NOT pass to peers (for now)
511 // XXX: when we have sorted out the best way to relay requests properly to peers this hierarchical limit can go.
512 http->doCallouts();
513 return;
514 }
515
516 debugs(85, DBG_IMPORTANT, "SECURITY ALERT: Host header forgery detected on " <<
517 http->getConn()->clientConnection << " (" << A << " does not match " << B << ")");
518 if (const char *ua = http->request->header.getStr(Http::HdrType::USER_AGENT))
519 debugs(85, DBG_IMPORTANT, "SECURITY ALERT: By user agent: " << ua);
520 debugs(85, DBG_IMPORTANT, "SECURITY ALERT: on URL: " << http->request->effectiveRequestUri());
521
522 // IP address validation for Host: failed. reject the connection.
524 clientReplyContext *repContext = dynamic_cast<clientReplyContext *>(node->data.getRaw());
525 assert (repContext);
526 repContext->setReplyToError(ERR_CONFLICT_HOST, Http::scConflict,
527 nullptr,
528 http->getConn(),
529 http->request,
530 nullptr,
531#if USE_AUTH
532 http->getConn() != nullptr && http->getConn()->getAuth() != nullptr ?
534#else
535 NULL);
536#endif
538 clientStreamRead(node, http, node->readBuffer);
539}
540
541void
543{
544 // Require a Host: header.
545 const char *host = http->request->header.getStr(Http::HdrType::HOST);
546
547 if (!host) {
548 // TODO: dump out the HTTP/1.1 error about missing host header.
549 // otherwise this is fine, can't forge a header value when its not even set.
550 debugs(85, 3, "validate skipped with no Host: header present.");
551 http->doCallouts();
552 return;
553 }
554
555 if (http->request->flags.internal) {
556 // TODO: kill this when URL handling allows partial URLs out of accel mode
557 // and we no longer screw with the URL just to add our internal host there
558 debugs(85, 6, "validate skipped due to internal composite URL.");
559 http->doCallouts();
560 return;
561 }
562
563 // TODO: Unify Host value parsing below with AnyP::Uri authority parsing
564 // Locate if there is a port attached, strip ready for IP lookup
565 char *portStr = nullptr;
566 char *hostB = xstrdup(host);
567 host = hostB;
568 if (host[0] == '[') {
569 // IPv6 literal.
570 portStr = strchr(hostB, ']');
571 if (portStr && *(++portStr) != ':') {
572 portStr = nullptr;
573 }
574 } else {
575 // Domain or IPv4 literal with port
576 portStr = strrchr(hostB, ':');
577 }
578
579 uint16_t port = 0;
580 if (portStr) {
581 *portStr = '\0'; // strip the ':'
582 if (*(++portStr) != '\0') {
583 char *end = nullptr;
584 int64_t ret = strtoll(portStr, &end, 10);
585 if (end == portStr || *end != '\0' || ret < 1 || ret > 0xFFFF) {
586 // invalid port details. Replace the ':'
587 *(--portStr) = ':';
588 portStr = nullptr;
589 } else
590 port = (ret & 0xFFFF);
591 }
592 }
593
594 debugs(85, 3, "validate host=" << host << ", port=" << port << ", portStr=" << (portStr?portStr:"NULL"));
596 // verify the Host: port (if any) matches the apparent destination
597 if (portStr && port != http->getConn()->clientConnection->local.port()) {
598 debugs(85, 3, "FAIL on validate port " << http->getConn()->clientConnection->local.port() <<
599 " matches Host: port " << port << " (" << portStr << ")");
600 hostHeaderVerifyFailed("intercepted port", portStr);
601 } else {
602 // XXX: match the scheme default port against the apparent destination
603
604 // verify the destination DNS is one of the Host: headers IPs
606 }
607 } else if (!Config.onoff.hostStrictVerify) {
608 debugs(85, 3, "validate skipped.");
609 http->doCallouts();
610 } else if (strlen(host) != strlen(http->request->url.host())) {
611 // Verify forward-proxy requested URL domain matches the Host: header
612 debugs(85, 3, "FAIL on validate URL domain length " << http->request->url.host() << " matches Host: " << host);
614 } else if (matchDomainName(host, http->request->url.host()) != 0) {
615 // Verify forward-proxy requested URL domain matches the Host: header
616 debugs(85, 3, "FAIL on validate URL domain " << http->request->url.host() << " matches Host: " << host);
618 } else if (portStr && !http->request->url.port()) {
619 debugs(85, 3, "FAIL on validate portless URI matches Host: " << portStr);
620 hostHeaderVerifyFailed("portless URI", portStr);
621 } else if (portStr && port != *http->request->url.port()) {
622 // Verify forward-proxy requested URL domain matches the Host: header
623 debugs(85, 3, "FAIL on validate URL port " << *http->request->url.port() << " matches Host: port " << portStr);
624 hostHeaderVerifyFailed("URL port", portStr);
625 } else if (!portStr && http->request->method != Http::METHOD_CONNECT && http->request->url.port() != http->request->url.getScheme().defaultPort()) {
626 // Verify forward-proxy requested URL domain matches the Host: header
627 // Special case: we don't have a default-port to check for CONNECT. Assume URL is correct.
628 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));
629 hostHeaderVerifyFailed("URL port", "default port");
630 } else {
631 // Okay no problem.
632 debugs(85, 3, "validate passed.");
634 http->doCallouts();
635 }
636 safe_free(hostB);
637}
638
639/* This is the entry point for external users of the client_side routines */
640void
642{
643#if FOLLOW_X_FORWARDED_FOR
644 if (!http->request->flags.doneFollowXff() &&
647
648 /* we always trust the direct client address for actual use */
651
652 /* setup the XFF iterator for processing */
654
655 /* begin by checking to see if we trust direct client enough to walk XFF */
658 return;
659 }
660#endif
661
662 if (Config.accessList.http) {
665 } else {
666 debugs(0, DBG_CRITICAL, "No http_access configuration found. This will block ALL traffic");
668 }
669}
670
676void
678{
682 } else {
683 debugs(85, 2, "No adapted_http_access configuration. default: ALLOW");
685 }
686}
687
688void
690{
691 ClientRequestContext *calloutContext = (ClientRequestContext *) data;
692
693 if (!calloutContext->httpStateIsValid())
694 return;
695
696 calloutContext->clientAccessCheckDone(answer);
697}
698
699void
701{
702 acl_checklist = nullptr;
703 err_type page_id;
704 Http::StatusCode status;
705 debugs(85, 2, "The request " << http->request->method << ' ' <<
706 http->uri << " is " << answer <<
707 "; last ACL checked: " << (AclMatchedName ? AclMatchedName : "[none]"));
708
709#if USE_AUTH
710 char const *proxy_auth_msg = "<null>";
711 if (http->getConn() != nullptr && http->getConn()->getAuth() != nullptr)
712 proxy_auth_msg = http->getConn()->getAuth()->denyMessage("<null>");
713 else if (http->request->auth_user_request != nullptr)
714 proxy_auth_msg = http->request->auth_user_request->denyMessage("<null>");
715#endif
716
717 if (!answer.allowed()) {
718 // auth has a grace period where credentials can be expired but okay not to challenge.
719
720 /* Send an auth challenge or error */
721 // XXX: do we still need aclIsProxyAuth() ?
722 bool auth_challenge = (answer == ACCESS_AUTH_REQUIRED || aclIsProxyAuth(AclMatchedName));
723 debugs(85, 5, "Access Denied: " << http->uri);
724 debugs(85, 5, "AclMatchedName = " << (AclMatchedName ? AclMatchedName : "<null>"));
725#if USE_AUTH
726 if (auth_challenge)
727 debugs(33, 5, "Proxy Auth Message = " << (proxy_auth_msg ? proxy_auth_msg : "<null>"));
728#endif
729
730 /*
731 * NOTE: get page_id here, based on AclMatchedName because if
732 * USE_DELAY_POOLS is enabled, then AclMatchedName gets clobbered in
733 * the clientCreateStoreEntry() call just below. Pedro Ribeiro
734 * <pribeiro@isel.pt>
735 */
737
739
740 if (auth_challenge) {
741#if USE_AUTH
742 if (http->request->flags.sslBumped) {
743 /*SSL Bumped request, authentication is not possible*/
744 status = Http::scForbidden;
745 } else if (!http->flags.accel) {
746 /* Proxy authorisation needed */
748 } else {
749 /* WWW authorisation needed */
750 status = Http::scUnauthorized;
751 }
752#else
753 // need auth, but not possible to do.
754 status = Http::scForbidden;
755#endif
756 if (page_id == ERR_NONE)
757 page_id = ERR_CACHE_ACCESS_DENIED;
758 } else {
759 status = Http::scForbidden;
760
761 if (page_id == ERR_NONE)
762 page_id = ERR_ACCESS_DENIED;
763 }
764
765 error = clientBuildError(page_id, status, nullptr, http->getConn(), http->request, http->al);
766
767#if USE_AUTH
769 http->getConn() != nullptr && http->getConn()->getAuth() != nullptr ?
771#endif
772
773 readNextRequest = true;
774 }
775
776 /* ACCESS_ALLOWED continues here ... */
777 xfree(http->uri);
779 http->doCallouts();
780}
781
782#if USE_ADAPTATION
783void
785{
786 debugs(93,3, this << " adaptationAclCheckDone called");
787
788#if ICAP_CLIENT
790 if (ih != nullptr) {
791 if (getConn() != nullptr && getConn()->clientConnection != nullptr) {
792 ih->rfc931 = getConn()->clientConnection->rfc931;
793#if USE_OPENSSL
794 if (getConn()->clientConnection->isOpen()) {
795 ih->ssluser = sslGetUserEmail(fd_table[getConn()->clientConnection->fd].ssl.get());
796 }
797#endif
798 }
799 ih->log_uri = log_uri;
800 ih->req_sz = req_sz;
801 }
802#endif
803
804 if (!g) {
805 debugs(85,3, "no adaptation needed");
806 doCallouts();
807 return;
808 }
809
811}
812
813#endif
814
815static void
817{
819 ClientHttpRequest *http = context->http;
820 context->acl_checklist = nullptr;
821
822 if (answer.allowed())
824 else {
825 Helper::Reply const nilReply(Helper::Error);
826 context->clientRedirectDone(nilReply);
827 }
828}
829
830void
832{
833 debugs(33, 5, "'" << http->uri << "'");
838 } else
840}
841
846static void
848{
849 ClientRequestContext *context = static_cast<ClientRequestContext *>(data);
850 ClientHttpRequest *http = context->http;
851 context->acl_checklist = nullptr;
852
853 if (answer.allowed())
855 else {
856 debugs(85, 3, "access denied expected ERR reply handling: " << answer);
857 Helper::Reply const nilReply(Helper::Error);
858 context->clientStoreIdDone(nilReply);
859 }
860}
861
867void
869{
870 debugs(33, 5,"'" << http->uri << "'");
871
875 } else
877}
878
879static int
881{
882 HttpRequest *request = http->request;
883 HttpRequestMethod method = request->method;
884
885 // intercepted requests MUST NOT (yet) be sent to peers unless verified
886 if (!request->flags.hostVerified && (request->flags.intercepted || request->flags.interceptTproxy))
887 return 0;
888
889 /*
890 * IMS needs a private key, so we can use the hierarchy for IMS only if our
891 * neighbors support private keys
892 */
893
894 if (request->flags.ims && !neighbors_do_private_keys)
895 return 0;
896
897 /*
898 * This is incorrect: authenticating requests can be sent via a hierarchy
899 * (they can even be cached if the correct headers are set on the reply)
900 */
901 if (request->flags.auth)
902 return 0;
903
904 if (method == Http::METHOD_TRACE)
905 return 1;
906
907 if (method != Http::METHOD_GET)
908 return 0;
909
910 if (request->flags.loopDetected)
911 return 0;
912
913 if (request->url.getScheme() == AnyP::PROTO_HTTP)
914 return method.respMaybeCacheable();
915
916 if (request->url.getScheme() == AnyP::PROTO_CACHE_OBJECT)
917 return 0;
918
919 return 1;
920}
921
922static void
924{
925 HttpRequest *request = http->request;
926 HttpHeader *req_hdr = &request->header;
927 ConnStateData *http_conn = http->getConn();
928
929 /* Internal requests such as those from ESI includes may be without
930 * a client connection
931 */
932 if (!http_conn)
933 return;
934
935 request->flags.connectionAuthDisabled = http_conn->port->connection_auth_disabled;
936 if (!request->flags.connectionAuthDisabled) {
937 if (Comm::IsConnOpen(http_conn->pinning.serverConnection)) {
938 if (http_conn->pinning.auth) {
939 request->flags.connectionAuth = true;
940 request->flags.auth = true;
941 } else {
942 request->flags.connectionProxyAuth = true;
943 }
944 // These should already be linked correctly.
945 assert(request->clientConnectionManager == http_conn);
946 }
947 }
948
949 /* check if connection auth is used, and flag as candidate for pinning
950 * in such case.
951 * Note: we may need to set flags.connectionAuth even if the connection
952 * is already pinned if it was pinned earlier due to proxy auth
953 */
954 if (!request->flags.connectionAuth) {
958 int may_pin = 0;
959 while ((e = req_hdr->getEntry(&pos))) {
961 const char *value = e->value.rawBuf();
962 if (strncasecmp(value, "NTLM ", 5) == 0
963 ||
964 strncasecmp(value, "Negotiate ", 10) == 0
965 ||
966 strncasecmp(value, "Kerberos ", 9) == 0) {
968 request->flags.connectionAuth = true;
969 may_pin = 1;
970 } else {
971 request->flags.connectionProxyAuth = true;
972 may_pin = 1;
973 }
974 }
975 }
976 }
977 if (may_pin && !request->pinnedConnection()) {
978 // These should already be linked correctly. Just need the ServerConnection to pinn.
979 assert(request->clientConnectionManager == http_conn);
980 }
981 }
982 }
983}
984
985static void
987{
988 HttpRequest *request = http->request;
989 HttpHeader *req_hdr = &request->header;
990 bool no_cache = false;
991
992 request->imslen = -1;
993 request->ims = req_hdr->getTime(Http::HdrType::IF_MODIFIED_SINCE);
994
995 if (request->ims > 0)
996 request->flags.ims = true;
997
998 if (!request->flags.ignoreCc) {
999 if (request->cache_control) {
1000 if (request->cache_control->hasNoCache())
1001 no_cache=true;
1002
1003 // RFC 2616: treat Pragma:no-cache as if it was Cache-Control:no-cache when Cache-Control is missing
1004 } else if (req_hdr->has(Http::HdrType::PRAGMA))
1005 no_cache = req_hdr->hasListMember(Http::HdrType::PRAGMA,"no-cache",',');
1006 }
1007
1008 if (request->method == Http::METHOD_OTHER) {
1009 no_cache=true;
1010 }
1011
1012 if (no_cache) {
1013#if USE_HTTP_VIOLATIONS
1014
1016 request->flags.nocacheHack = true;
1017 else if (refresh_nocache_hack)
1018 request->flags.nocacheHack = true;
1019 else
1020#endif
1021
1022 request->flags.noCache = true;
1023 }
1024
1025 /* ignore range header in non-GETs or non-HEADs */
1026 if (request->method == Http::METHOD_GET || request->method == Http::METHOD_HEAD) {
1027 // XXX: initialize if we got here without HttpRequest::parseHeader()
1028 if (!request->range)
1029 request->range = req_hdr->getRange();
1030
1031 if (request->range) {
1032 request->flags.isRanged = true;
1034 /* XXX: This is suboptimal. We should give the stream the range set,
1035 * and thereby let the top of the stream set the offset when the
1036 * size becomes known. As it is, we will end up requesting from 0
1037 * for evey -X range specification.
1038 * RBC - this may be somewhat wrong. We should probably set the range
1039 * iter up at this point.
1040 */
1041 node->readBuffer.offset = request->range->lowestOffset(0);
1042 }
1043 }
1044
1045 /* Only HEAD and GET requests permit a Range or Request-Range header.
1046 * If these headers appear on any other type of request, delete them now.
1047 */
1048 else {
1049 req_hdr->delById(Http::HdrType::RANGE);
1051 request->ignoreRange("neither HEAD nor GET");
1052 }
1053
1054 if (req_hdr->has(Http::HdrType::AUTHORIZATION))
1055 request->flags.auth = true;
1056
1057 clientCheckPinning(http);
1058
1059 if (!request->url.userInfo().isEmpty())
1060 request->flags.auth = true;
1061
1062 if (req_hdr->has(Http::HdrType::VIA)) {
1063 String s = req_hdr->getList(Http::HdrType::VIA);
1064 /*
1065 * ThisCache cannot be a member of Via header, "1.1 ThisCache" can.
1066 * Note ThisCache2 has a space prepended to the hostname so we don't
1067 * accidentally match super-domains.
1068 */
1069
1070 if (strListIsSubstr(&s, ThisCache2, ',')) {
1071 request->flags.loopDetected = true;
1072 }
1073
1074#if USE_FORW_VIA_DB
1076
1077#endif
1078
1079 s.clean();
1080 }
1081
1082 // headers only relevant to reverse-proxy
1083 if (request->flags.accelerated) {
1084 // check for a cdn-info member with a cdn-id matching surrogate_id
1085 // XXX: HttpHeader::hasListMember() does not handle OWS around ";" yet
1087 request->flags.loopDetected = true;
1088 }
1089
1090 if (request->flags.loopDetected) {
1091 debugObj(33, DBG_IMPORTANT, "WARNING: Forwarding loop detected for:\n",
1092 request, (ObjPackMethod) & httpRequestPack);
1093 }
1094
1095#if USE_FORW_VIA_DB
1096
1097 if (req_hdr->has(Http::HdrType::X_FORWARDED_FOR)) {
1100 s.clean();
1101 }
1102
1103#endif
1104
1105 if (http->request->maybeCacheable())
1106 request->flags.cachable.support();
1107 else
1108 request->flags.cachable.veto();
1109
1110 if (clientHierarchical(http))
1111 request->flags.hierarchical = true;
1112
1113 debugs(85, 5, "clientInterpretRequestHeaders: REQ_NOCACHE = " <<
1114 (request->flags.noCache ? "SET" : "NOT SET"));
1115 debugs(85, 5, "clientInterpretRequestHeaders: REQ_CACHABLE = " <<
1116 (request->flags.cachable ? "SET" : "NOT SET"));
1117 debugs(85, 5, "clientInterpretRequestHeaders: REQ_HIERARCHICAL = " <<
1118 (request->flags.hierarchical ? "SET" : "NOT SET"));
1119
1120}
1121
1122void
1124{
1125 ClientRequestContext *calloutContext = (ClientRequestContext *)data;
1126
1127 if (!calloutContext->httpStateIsValid())
1128 return;
1129
1130 calloutContext->clientRedirectDone(result);
1131}
1132
1133void
1134clientStoreIdDoneWrapper(void *data, const Helper::Reply &result)
1135{
1136 ClientRequestContext *calloutContext = (ClientRequestContext *)data;
1137
1138 if (!calloutContext->httpStateIsValid())
1139 return;
1140
1141 calloutContext->clientStoreIdDone(result);
1142}
1143
1144void
1146{
1147 HttpRequest *old_request = http->request;
1148 debugs(85, 5, "'" << http->uri << "' result=" << reply);
1151
1152 // Put helper response Notes into the transaction state record (ALE) eventually
1153 // do it early to ensure that no matter what the outcome the notes are present.
1154 if (http->al)
1155 http->al->syncNotes(old_request);
1156
1157 UpdateRequestNotes(http->getConn(), *old_request, reply.notes);
1158
1159 switch (reply.result) {
1160 case Helper::TimedOut:
1162 static const auto d = MakeNamedErrorDetail("REDIRECTOR_TIMEDOUT");
1164 debugs(85, DBG_IMPORTANT, "ERROR: URL rewrite helper: Timedout");
1165 }
1166 break;
1167
1168 case Helper::Unknown:
1169 case Helper::TT:
1170 // Handler in redirect.cc should have already mapped Unknown
1171 // IF it contained valid entry for the old URL-rewrite helper protocol
1172 debugs(85, DBG_IMPORTANT, "ERROR: URL rewrite helper returned invalid result code. Wrong helper? " << reply);
1173 break;
1174
1176 debugs(85, DBG_IMPORTANT, "ERROR: URL rewrite helper: " << reply);
1177 break;
1178
1179 case Helper::Error:
1180 // no change to be done.
1181 break;
1182
1183 case Helper::Okay: {
1184 // #1: redirect with a specific status code OK status=NNN url="..."
1185 // #2: redirect with a default status code OK url="..."
1186 // #3: re-write the URL OK rewrite-url="..."
1187
1188 const char *statusNote = reply.notes.findFirst("status");
1189 const char *urlNote = reply.notes.findFirst("url");
1190
1191 if (urlNote != nullptr) {
1192 // HTTP protocol redirect to be done.
1193
1194 // TODO: change default redirect status for appropriate requests
1195 // Squid defaults to 302 status for now for better compatibility with old clients.
1196 // HTTP/1.0 client should get 302 (Http::scFound)
1197 // HTTP/1.1 client contacting reverse-proxy should get 307 (Http::scTemporaryRedirect)
1198 // HTTP/1.1 client being diverted by forward-proxy should get 303 (Http::scSeeOther)
1200 if (statusNote != nullptr) {
1201 const char * result = statusNote;
1202 status = static_cast<Http::StatusCode>(atoi(result));
1203 }
1204
1205 if (status == Http::scMovedPermanently
1206 || status == Http::scFound
1207 || status == Http::scSeeOther
1208 || status == Http::scPermanentRedirect
1209 || status == Http::scTemporaryRedirect) {
1210 http->redirect.status = status;
1211 http->redirect.location = xstrdup(urlNote);
1212 // TODO: validate the URL produced here is RFC 2616 compliant absolute URI
1213 } else {
1214 debugs(85, DBG_CRITICAL, "ERROR: URL-rewrite produces invalid " << status << " redirect Location: " << urlNote);
1215 }
1216 } else {
1217 // URL-rewrite wanted. Ew.
1218 urlNote = reply.notes.findFirst("rewrite-url");
1219
1220 // prevent broken helpers causing too much damage. If old URL == new URL skip the re-write.
1221 if (urlNote != nullptr && strcmp(urlNote, http->uri)) {
1222 AnyP::Uri tmpUrl;
1223 if (tmpUrl.parse(old_request->method, SBuf(urlNote))) {
1224 HttpRequest *new_request = old_request->clone();
1225 new_request->url = tmpUrl;
1226 debugs(61, 2, "URL-rewriter diverts URL from " << old_request->effectiveRequestUri() << " to " << new_request->effectiveRequestUri());
1227
1228 // update the new request to flag the re-writing was done on it
1229 new_request->flags.redirected = true;
1230
1231 // unlink bodypipe from the old request. Not needed there any longer.
1232 if (old_request->body_pipe != nullptr) {
1233 old_request->body_pipe = nullptr;
1234 debugs(61,2, "URL-rewriter diverts body_pipe " << new_request->body_pipe <<
1235 " from request " << old_request << " to " << new_request);
1236 }
1237
1238 http->resetRequest(new_request);
1239 old_request = nullptr;
1240 } else {
1241 debugs(85, DBG_CRITICAL, "ERROR: URL-rewrite produces invalid request: " <<
1242 old_request->method << " " << urlNote << " " << old_request->http_ver);
1243 }
1244 }
1245 }
1246 }
1247 break;
1248 }
1249
1250 /* XXX PIPELINE: This is inaccurate during pipelining */
1251
1252 if (http->getConn() != nullptr && Comm::IsConnOpen(http->getConn()->clientConnection))
1254
1255 assert(http->uri);
1256
1257 http->doCallouts();
1258}
1259
1263void
1265{
1266 HttpRequest *old_request = http->request;
1267 debugs(85, 5, "'" << http->uri << "' result=" << reply);
1270
1271 // Put helper response Notes into the transaction state record (ALE) eventually
1272 // do it early to ensure that no matter what the outcome the notes are present.
1273 if (http->al)
1274 http->al->syncNotes(old_request);
1275
1276 UpdateRequestNotes(http->getConn(), *old_request, reply.notes);
1277
1278 switch (reply.result) {
1279 case Helper::Unknown:
1280 case Helper::TT:
1281 // Handler in redirect.cc should have already mapped Unknown
1282 // IF it contained valid entry for the old helper protocol
1283 debugs(85, DBG_IMPORTANT, "ERROR: storeID helper returned invalid result code. Wrong helper? " << reply);
1284 break;
1285
1286 case Helper::TimedOut:
1287 // Timeouts for storeID are not implemented
1289 debugs(85, DBG_IMPORTANT, "ERROR: storeID helper: " << reply);
1290 break;
1291
1292 case Helper::Error:
1293 // no change to be done.
1294 break;
1295
1296 case Helper::Okay: {
1297 const char *urlNote = reply.notes.findFirst("store-id");
1298
1299 // prevent broken helpers causing too much damage. If old URL == new URL skip the re-write.
1300 if (urlNote != nullptr && strcmp(urlNote, http->uri) ) {
1301 // Debug section required for some very specific cases.
1302 debugs(85, 9, "Setting storeID with: " << urlNote );
1303 http->request->store_id = urlNote;
1304 http->store_id = urlNote;
1305 }
1306 }
1307 break;
1308 }
1309
1310 http->doCallouts();
1311}
1312
1314void
1316{
1320 } else {
1321 /* unless otherwise specified, we try to cache. */
1323 }
1324}
1325
1326static void
1328{
1329 ClientRequestContext *calloutContext = (ClientRequestContext *) data;
1330
1331 if (!calloutContext->httpStateIsValid())
1332 return;
1333
1334 calloutContext->checkNoCacheDone(answer);
1335}
1336
1337void
1339{
1340 acl_checklist = nullptr;
1341 if (answer.denied()) {
1342 http->request->flags.disableCacheUse("a cache deny rule matched");
1343 }
1344 http->doCallouts();
1345}
1346
1347#if USE_OPENSSL
1348bool
1350{
1351 if (!http->getConn()) {
1352 http->al->ssl.bumpMode = Ssl::bumpEnd; // SslBump does not apply; log -
1353 return false;
1354 }
1355
1357 if (http->request->flags.forceTunnel) {
1358 debugs(85, 5, "not needed; already decided to tunnel " << http->getConn());
1359 if (bumpMode != Ssl::bumpEnd)
1360 http->al->ssl.bumpMode = bumpMode; // inherited from bumped connection
1361 return false;
1362 }
1363
1364 // If SSL connection tunneling or bumping decision has been made, obey it.
1365 if (bumpMode != Ssl::bumpEnd) {
1366 debugs(85, 5, "SslBump already decided (" << bumpMode <<
1367 "), " << "ignoring ssl_bump for " << http->getConn());
1368
1369 // We need the following "if" for transparently bumped TLS connection,
1370 // because in this case we are running ssl_bump access list before
1371 // the doCallouts runs. It can be removed after the bug #4340 fixed.
1372 // We do not want to proceed to bumping steps:
1373 // - if the TLS connection with the client is already established
1374 // because we are accepting normal HTTP requests on TLS port,
1375 // or because of the client-first bumping mode
1376 // - When the bumping is already started
1377 if (!http->getConn()->switchedToHttps() &&
1378 !http->getConn()->serverBump())
1379 http->sslBumpNeed(bumpMode); // for processRequest() to bump if needed and not already bumped
1380 http->al->ssl.bumpMode = bumpMode; // inherited from bumped connection
1381 return false;
1382 }
1383
1384 // If we have not decided yet, decide whether to bump now.
1385
1386 // Bumping here can only start with a CONNECT request on a bumping port
1387 // (bumping of intercepted SSL conns is decided before we get 1st request).
1388 // We also do not bump redirected CONNECT requests.
1391 !http->getConn()->port->flags.tunnelSslBumping) {
1392 http->al->ssl.bumpMode = Ssl::bumpEnd; // SslBump does not apply; log -
1393 debugs(85, 5, "cannot SslBump this request");
1394 return false;
1395 }
1396
1397 // Do not bump during authentication: clients would not proxy-authenticate
1398 // if we delay a 407 response and respond with 200 OK to CONNECT.
1400 http->al->ssl.bumpMode = Ssl::bumpEnd; // SslBump does not apply; log -
1401 debugs(85, 5, "no SslBump during proxy authentication");
1402 return false;
1403 }
1404
1405 if (error) {
1406 debugs(85, 5, "SslBump applies. Force bump action on error " << errorTypeName(error->type));
1409 return false;
1410 }
1411
1412 debugs(85, 5, "SslBump possible, checking ACL");
1413
1416 return true;
1417}
1418
1423static void
1425{
1426 ClientRequestContext *calloutContext = static_cast<ClientRequestContext *>(data);
1427
1428 if (!calloutContext->httpStateIsValid())
1429 return;
1430 calloutContext->sslBumpAccessCheckDone(answer);
1431}
1432
1433void
1435{
1436 if (!httpStateIsValid())
1437 return;
1438
1439 const Ssl::BumpMode bumpMode = answer.allowed() ?
1440 static_cast<Ssl::BumpMode>(answer.kind) : Ssl::bumpSplice;
1441 http->sslBumpNeed(bumpMode); // for processRequest() to bump if needed
1442 http->al->ssl.bumpMode = bumpMode; // for logging
1443
1445 const Comm::ConnectionPointer clientConn = http->getConn() ? http->getConn()->clientConnection : nullptr;
1446 if (Comm::IsConnOpen(clientConn)) {
1447 debugs(85, 3, "closing after Ssl::bumpTerminate ");
1448 clientConn->close();
1449 }
1450 return;
1451 }
1452
1453 http->doCallouts();
1454}
1455#endif
1456
1457/*
1458 * Identify requests that do not go through the store and client side stream
1459 * and forward them to the appropriate location. All other requests, request
1460 * them.
1461 */
1462void
1464{
1465 debugs(85, 4, request->method << ' ' << uri);
1466
1467 const bool untouchedConnect = request->method == Http::METHOD_CONNECT && !redirect.status;
1468
1469#if USE_OPENSSL
1470 if (untouchedConnect && sslBumpNeeded()) {
1472 sslBumpStart();
1473 return;
1474 }
1475#endif
1476
1477 if (untouchedConnect || request->flags.forceTunnel) {
1478 getConn()->stopReading(); // tunnels read for themselves
1479 tunnelStart(this);
1480 return;
1481 }
1482
1483 httpStart();
1484}
1485
1486void
1488{
1489 // XXX: Re-initializes rather than updates. Should not be needed at all.
1491 debugs(85, 4, loggingTags().c_str() << " for '" << uri << "'");
1492
1493 /* no one should have touched this */
1494 assert(out.offset == 0);
1495 /* Use the Stream Luke */
1497 clientStreamRead(node, this, node->readBuffer);
1498}
1499
1500#if USE_OPENSSL
1501
1502void
1504{
1505 debugs(83, 3, "sslBump required: "<< Ssl::bumpMode(mode));
1506 sslBumpNeed_ = mode;
1507}
1508
1509// called when comm_write has completed
1510static void
1511SslBumpEstablish(const Comm::ConnectionPointer &, char *, size_t, Comm::Flag errflag, int, void *data)
1512{
1513 ClientHttpRequest *r = static_cast<ClientHttpRequest*>(data);
1514 debugs(85, 5, "responded to CONNECT: " << r << " ? " << errflag);
1515
1517 r->sslBumpEstablish(errflag);
1518}
1519
1520void
1522{
1523 // Bail out quickly on Comm::ERR_CLOSING - close handlers will tidy up
1524 if (errflag == Comm::ERR_CLOSING)
1525 return;
1526
1527 if (errflag) {
1528 debugs(85, 3, "CONNECT response failure in SslBump: " << errflag);
1530 return;
1531 }
1532
1533#if USE_AUTH
1534 // Preserve authentication info for the ssl-bumped request
1535 if (request->auth_user_request != nullptr)
1536 getConn()->setAuth(request->auth_user_request, "SSL-bumped CONNECT");
1537#endif
1538
1541}
1542
1543void
1545{
1546 debugs(85, 5, "Confirming " << Ssl::bumpMode(sslBumpNeed_) <<
1547 "-bumped CONNECT tunnel on FD " << getConn()->clientConnection);
1549
1550 AsyncCall::Pointer bumpCall = commCbCall(85, 5, "ClientSocketContext::sslBumpEstablish",
1552
1554 CommIoCbParams &params = GetCommParams<CommIoCbParams>(bumpCall);
1555 params.flag = Comm::OK;
1556 params.conn = getConn()->clientConnection;
1557 ScheduleCallHere(bumpCall);
1558 return;
1559 }
1560
1562
1563 const auto mb = al->reply->pack();
1564 // send an HTTP 200 response to kick client SSL negotiation
1565 // TODO: Unify with tunnel.cc and add a Server(?) header
1566 Comm::Write(getConn()->clientConnection, mb, bumpCall);
1567 delete mb;
1568}
1569
1570#endif
1571
1572void
1574{
1575 if (request)
1577 else
1579}
1580
1581bool
1583{
1584 // TODO: See also (and unify with) clientReplyContext::storeNotOKTransferDone()
1585 int64_t contentLength =
1587 assert(contentLength >= 0);
1588
1589 if (out.offset < contentLength)
1590 return false;
1591
1592 return true;
1593}
1594
1595void
1597{
1598 entry_ = newEntry;
1599}
1600
1601void
1603{
1604 if (loggingEntry_)
1605 loggingEntry_->unlock("ClientHttpRequest::loggingEntry");
1606
1607 loggingEntry_ = newEntry;
1608
1609 if (loggingEntry_)
1610 loggingEntry_->lock("ClientHttpRequest::loggingEntry");
1611}
1612
1613void
1615{
1616 assignRequest(aRequest);
1617 if (const auto csd = getConn()) {
1618 if (!csd->notes()->empty())
1619 request->notes()->appendNewOnly(csd->notes().getRaw());
1620 }
1621 // al is created in the constructor
1622 assert(al);
1623 if (!al->request) {
1624 al->request = request;
1627 }
1628}
1629
1630void
1632{
1633 assert(request != newRequest);
1634 clearRequest();
1635 assignRequest(newRequest);
1636 xfree(uri);
1638}
1639
1640void
1642{
1643 assert(newRequest);
1644 assert(!request);
1645 const_cast<HttpRequest *&>(request) = newRequest;
1648}
1649
1650void
1652{
1653 HttpRequest *oldRequest = request;
1654 HTTPMSGUNLOCK(oldRequest);
1655 const_cast<HttpRequest *&>(request) = nullptr;
1656 absorbLogUri(nullptr);
1657}
1658
1659/*
1660 * doCallouts() - This function controls the order of "callout"
1661 * executions, including non-blocking access control checks, the
1662 * redirector, and ICAP. Previously, these callouts were chained
1663 * together such that "clientAccessCheckDone()" would call
1664 * "clientRedirectStart()" and so on.
1665 *
1666 * The ClientRequestContext (aka calloutContext) class holds certain
1667 * state data for the callout/callback operations. Previously
1668 * ClientHttpRequest would sort of hand off control to ClientRequestContext
1669 * for a short time. ClientRequestContext would then delete itself
1670 * and pass control back to ClientHttpRequest when all callouts
1671 * were finished.
1672 *
1673 * This caused some problems for ICAP because we want to make the
1674 * ICAP callout after checking ACLs, but before checking the no_cache
1675 * list. We can't stuff the ICAP state into the ClientRequestContext
1676 * class because we still need the ICAP state after ClientRequestContext
1677 * goes away.
1678 *
1679 * Note that ClientRequestContext is created before the first call
1680 * to doCallouts().
1681 *
1682 * If one of the callouts notices that ClientHttpRequest is no
1683 * longer valid, it should call cbdataReferenceDone() so that
1684 * ClientHttpRequest's reference count goes to zero and it will get
1685 * deleted. ClientHttpRequest will then delete ClientRequestContext.
1686 *
1687 * Note that we set the _done flags here before actually starting
1688 * the callout. This is strictly for convenience.
1689 */
1690
1691void
1693{
1695
1696 if (!calloutContext->error) {
1697 // CVE-2009-0801: verify the Host: header is consistent with other known details.
1699 debugs(83, 3, "Doing calloutContext->hostHeaderVerify()");
1702 return;
1703 }
1704
1706 debugs(83, 3, "Doing calloutContext->clientAccessCheck()");
1709 return;
1710 }
1711
1712#if USE_ADAPTATION
1717 request, nullptr, calloutContext->http->al, this))
1718 return; // will call callback
1719 }
1720#endif
1721
1724
1725 if (Config.Program.redirect) {
1726 debugs(83, 3, "Doing calloutContext->clientRedirectStart()");
1729 return;
1730 }
1731 }
1732
1734 debugs(83, 3, "Doing calloutContext->clientAccessCheck2()");
1737 return;
1738 }
1739
1742
1743 if (Config.Program.store_id) {
1744 debugs(83, 3,"Doing calloutContext->clientStoreIdStart()");
1747 return;
1748 }
1749 }
1750
1752 debugs(83, 3, "Doing clientInterpretRequestHeaders()");
1755 }
1756
1759
1761 debugs(83, 3, "Doing calloutContext->checkNoCache()");
1763 return;
1764 }
1765 }
1766 } // if !calloutContext->error
1767
1768 // Set appropriate MARKs and CONNMARKs if needed.
1769 if (getConn() && Comm::IsConnOpen(getConn()->clientConnection)) {
1770 ACLFilledChecklist ch(nullptr, request, nullptr);
1771 ch.al = calloutContext->http->al;
1773 ch.my_addr = request->my_addr;
1774 ch.syncAle(request, log_uri);
1775
1778 tos_t tos = aclMapTOS(Ip::Qos::TheConfig.tosToClient, &ch);
1779 if (tos)
1780 Ip::Qos::setSockTos(getConn()->clientConnection, tos);
1781
1782 const auto packetMark = aclFindNfMarkConfig(Ip::Qos::TheConfig.nfmarkToClient, &ch);
1783 if (!packetMark.isEmpty())
1784 Ip::Qos::setSockNfmark(getConn()->clientConnection, packetMark.mark);
1785
1786 const auto connmark = aclFindNfMarkConfig(Ip::Qos::TheConfig.nfConnmarkToClient, &ch);
1787 if (!connmark.isEmpty())
1788 Ip::Qos::setNfConnmark(getConn()->clientConnection, Ip::Qos::dirAccepted, connmark);
1789 }
1790 }
1791
1792#if USE_OPENSSL
1793 // Even with calloutContext->error, we call sslBumpAccessCheck() to decide
1794 // whether SslBump applies to this transaction. If it applies, we will
1795 // attempt to bump the client to serve the error.
1799 return;
1800 /* else no ssl bump required*/
1801 }
1802#endif
1803
1804 if (calloutContext->error) {
1805 // XXX: prformance regression. c_str() reallocates
1806 SBuf storeUriBuf(request->storeId());
1807 const char *storeUri = storeUriBuf.c_str();
1808 StoreEntry *e = storeCreateEntry(storeUri, storeUri, request->flags, request->method);
1809#if USE_OPENSSL
1810 if (sslBumpNeeded()) {
1811 // We have to serve an error, so bump the client first.
1813 // set final error but delay sending until we bump
1814 Ssl::ServerBump *srvBump = new Ssl::ServerBump(this, e, Ssl::bumpClientFirst);
1816 calloutContext->error = nullptr;
1817 getConn()->setServerBump(srvBump);
1818 e->unlock("ClientHttpRequest::doCallouts+sslBumpNeeded");
1819 } else
1820#endif
1821 {
1822 // send the error to the client now
1824 clientReplyContext *repContext = dynamic_cast<clientReplyContext *>(node->data.getRaw());
1825 assert (repContext);
1826 repContext->setReplyToStoreEntry(e, "immediate SslBump error");
1828 calloutContext->error = nullptr;
1830 getConn()->flags.readMore = true; // resume any pipeline reads.
1832 clientStreamRead(node, this, node->readBuffer);
1833 e->unlock("ClientHttpRequest::doCallouts-sslBumpNeeded");
1834 return;
1835 }
1836 }
1837
1839 delete calloutContext;
1840 calloutContext = nullptr;
1841#if HEADERS_LOG
1842
1843 headersLog(0, 1, request->method, request);
1844#endif
1845
1846 debugs(83, 3, "calling processRequest()");
1848
1849#if ICAP_CLIENT
1851 if (ih != nullptr)
1852 ih->logType = loggingTags();
1853#endif
1854}
1855
1856void
1858{
1859 assert(request);
1860 const auto canonicalUri = request->canonicalCleanUrl();
1861 absorbLogUri(xstrndup(canonicalUri, MAX_URL));
1862}
1863
1864void
1866{
1867 assert(rawUri);
1868 // Should(!request);
1869
1870 // TODO: SBuf() performance regression, fix by converting rawUri to SBuf
1871 char *canonicalUri = urlCanonicalCleanWithoutRequest(SBuf(rawUri), method, AnyP::UriScheme());
1872
1873 absorbLogUri(AnyP::Uri::cleanup(canonicalUri));
1874
1875 char *cleanedRawUri = AnyP::Uri::cleanup(rawUri);
1876 al->setVirginUrlForMissingRequest(SBuf(cleanedRawUri));
1877 xfree(cleanedRawUri);
1878}
1879
1880void
1882{
1883 xfree(log_uri);
1884 const_cast<char *&>(log_uri) = aUri;
1885}
1886
1887void
1889{
1890 assert(!uri);
1891 assert(aUri);
1892 // Should(!request);
1893
1894 uri = xstrdup(aUri);
1895 // TODO: SBuf() performance regression, fix by converting setErrorUri() parameter to SBuf
1896 const SBuf errorUri(aUri);
1897 const auto canonicalUri = urlCanonicalCleanWithoutRequest(errorUri, HttpRequestMethod(), AnyP::UriScheme());
1898 absorbLogUri(xstrndup(canonicalUri, MAX_URL));
1899
1901}
1902
1903// XXX: This should not be a _request_ method. Move range_iter elsewhere.
1904int64_t
1906{
1907 assert(request);
1909
1913 const auto multipart = request->range->specs.size() > 1;
1914 if (multipart)
1916 range_iter.valid = true; // TODO: Remove.
1917 range_iter.updateSpec(); // TODO: Refactor to initialize rather than update.
1918
1920 const auto &firstRange = *range_iter.pos;
1921 assert(firstRange);
1922 out.offset = firstRange->offset;
1923
1924 return multipart ? mRangeCLen() : firstRange->length;
1925}
1926
1927#if USE_ADAPTATION
1929void
1931{
1932 debugs(85, 3, "adaptation needed for " << this);
1936 new Adaptation::Iterator(request, nullptr, al, g));
1937
1938 // we could try to guess whether we can bypass this adaptation
1939 // initiation failure, but it should not really happen
1941}
1942
1943void
1945{
1946 assert(cbdataReferenceValid(this)); // indicates bug
1949
1950 switch (answer.kind) {
1952 handleAdaptedHeader(const_cast<Http::Message*>(answer.message.getRaw()));
1953 break;
1954
1956 handleAdaptationBlock(answer);
1957 break;
1958
1960 static const auto d = MakeNamedErrorDetail("CLT_REQMOD_ABORT");
1961 handleAdaptationFailure(d, !answer.final);
1962 break;
1963 }
1964 }
1965}
1966
1967void
1969{
1970 assert(msg);
1971
1972 if (HttpRequest *new_req = dynamic_cast<HttpRequest*>(msg)) {
1973 // update the new message to flag whether URL re-writing was done on it
1974 if (request->effectiveRequestUri() != new_req->effectiveRequestUri())
1975 new_req->flags.redirected = true;
1976 resetRequest(new_req);
1977 assert(request->method.id());
1978 } else if (HttpReply *new_rep = dynamic_cast<HttpReply*>(msg)) {
1979 debugs(85,3, "REQMOD reply is HTTP reply");
1980
1981 // subscribe to receive reply body
1982 if (new_rep->body_pipe != nullptr) {
1983 adaptedBodySource = new_rep->body_pipe;
1984 int consumer_ok = adaptedBodySource->setConsumerIfNotLate(this);
1985 assert(consumer_ok);
1986 }
1987
1989 clientReplyContext *repContext = dynamic_cast<clientReplyContext *>(node->data.getRaw());
1990 assert(repContext);
1991 repContext->createStoreEntry(request->method, request->flags);
1992
1995 storeEntry()->replaceHttpReply(new_rep);
1997
1998 al->reply = new_rep;
1999
2000 if (!adaptedBodySource) // no body
2001 storeEntry()->complete();
2002 clientGetMoreData(node, this);
2003 }
2004
2005 // we are done with getting headers (but may be receiving body)
2007
2009 doCallouts();
2010}
2011
2012void
2014{
2015 static const auto d = MakeNamedErrorDetail("REQMOD_BLOCK");
2017 AclMatchedName = answer.ruleId.termedBuf();
2020 AclMatchedName = nullptr;
2021}
2022
2023void
2025{
2026 if (!adaptedBodySource)
2027 return;
2028
2030}
2031
2032void
2034{
2036 assert(adaptedBodySource != nullptr);
2037
2038 if (size_t contentSize = adaptedBodySource->buf().contentSize()) {
2039 const size_t spaceAvailable = storeEntry()->bytesWanted(Range<size_t>(0,contentSize));
2040
2041 if (spaceAvailable < contentSize ) {
2042 // No or partial body data consuming
2043 typedef NullaryMemFunT<ClientHttpRequest> Dialer;
2044 AsyncCall::Pointer call = asyncCall(93, 5, "ClientHttpRequest::resumeBodyStorage",
2046 storeEntry()->deferProducer(call);
2047 }
2048
2049 if (!spaceAvailable)
2050 return;
2051
2052 if (spaceAvailable < contentSize )
2053 contentSize = spaceAvailable;
2054
2056 const StoreIOBuffer ioBuf(&bpc.buf, request_satisfaction_offset, contentSize);
2057 storeEntry()->write(ioBuf);
2058 // assume StoreEntry::write() writes the entire ioBuf
2060 bpc.buf.consume(contentSize);
2061 bpc.checkIn();
2062 }
2063
2066 // else wait for more body data
2067}
2068
2069void
2071{
2073
2074 // distinguish this code path from future noteBodyProducerAborted() that
2075 // would continue storing/delivering (truncated) reply if necessary (TODO)
2077
2078 // should we end request satisfaction now?
2079 if (adaptedBodySource != nullptr && adaptedBodySource->exhausted())
2081}
2082
2083void
2085{
2086 debugs(85,4, this << " ends request satisfaction");
2089
2090 // TODO: anything else needed to end store entry formation correctly?
2092 // We received the entire reply per receivedWholeAdaptedReply.
2093 // We are called when we consumed everything received (per our callers).
2094 // We consume only what we store per noteMoreBodyDataAvailable().
2095 storeEntry()->completeSuccessfully("received, consumed, and, hence, stored the entire REQMOD reply");
2096 } else {
2097 storeEntry()->completeTruncated("REQMOD request satisfaction default");
2098 }
2099}
2100
2101void
2103{
2106
2107 debugs(85,3, "REQMOD body production failed");
2108 if (request_satisfaction_mode) { // too late to recover or serve an error
2109 static const auto d = MakeNamedErrorDetail("CLT_REQMOD_RESP_BODY");
2113 c->close(); // drastic, but we may be writing a response already
2114 } else {
2115 static const auto d = MakeNamedErrorDetail("CLT_REQMOD_REQ_BODY");
2117 }
2118}
2119
2120void
2122{
2123 debugs(85,3, "handleAdaptationFailure(" << bypassable << ")");
2124
2125 const bool usedStore = storeEntry() && !storeEntry()->isEmpty();
2126 const bool usedPipe = request->body_pipe != nullptr &&
2128
2129 if (bypassable && !usedStore && !usedPipe) {
2130 debugs(85,3, "ICAP REQMOD callout failed, bypassing: " << calloutContext);
2131 if (calloutContext)
2132 doCallouts();
2133 return;
2134 }
2135
2136 debugs(85,3, "ICAP REQMOD callout failed, responding with error");
2137
2139 clientReplyContext *repContext = dynamic_cast<clientReplyContext *>(node->data.getRaw());
2140 assert(repContext);
2141
2142 calloutsError(ERR_ICAP_FAILURE, errDetail);
2143
2144 if (calloutContext)
2145 doCallouts();
2146}
2147
2148void
2149ClientHttpRequest::callException(const std::exception &ex)
2150{
2151 if (const auto clientConn = getConn() ? getConn()->clientConnection : nullptr) {
2152 if (Comm::IsConnOpen(clientConn)) {
2153 debugs(85, 3, "closing after exception: " << ex.what());
2154 clientConn->close(); // initiate orderly top-to-bottom cleanup
2155 return;
2156 }
2157 }
2158 debugs(85, DBG_IMPORTANT, "ClientHttpRequest exception without connection. Ignoring " << ex.what());
2159 // XXX: Normally, we mustStop() but we cannot do that here because it is
2160 // likely to leave Http::Stream and ConnStateData with a dangling http
2161 // pointer. See r13480 or XXX in Http::Stream class description.
2162}
2163#endif
2164
2165// XXX: modify and use with ClientRequestContext::clientAccessCheckDone too.
2166void
2168{
2169 // The original author of the code also wanted to pass an errno to
2170 // setReplyToError, but it seems unlikely that the errno reflects the
2171 // true cause of the error at this point, so I did not pass it.
2172 if (calloutContext) {
2173 ConnStateData * c = getConn();
2175 nullptr, c, request, al);
2176#if USE_AUTH
2178 c != nullptr && c->getAuth() != nullptr ? c->getAuth() : request->auth_user_request;
2179#endif
2180 calloutContext->error->detailError(errDetail);
2182 if (c != nullptr)
2183 c->expectNoForwarding();
2184 }
2185 //else if(calloutContext == NULL) is it possible?
2186}
2187
#define ScheduleCallHere(call)
Definition: AsyncCall.h:165
RefCount< AsyncCallT< Dialer > > asyncCall(int aDebugSection, int aDebugLevel, const char *aName, const Dialer &aDialer)
Definition: AsyncCall.h:155
CommCbFunPtrCallT< Dialer > * commCbCall(int debugSection, int debugLevel, const char *callName, const Dialer &dialer)
Definition: CommCalls.h:312
ErrorDetail::Pointer MakeNamedErrorDetail(const char *name)
Definition: Detail.cc:54
const char * errorTypeName(err_type err)
Definition: Error.h:53
ACLFilledChecklist * Filled(ACLChecklist *checklist)
convenience and safety wrapper for dynamic_cast<ACLFilledChecklist*>
Ip::NfMarkConfig aclFindNfMarkConfig(acl_nfmark *head, ACLChecklist *ch)
Checks for a netfilter mark value to apply depending on the ACL.
Definition: FwdState.cc:1473
tos_t aclMapTOS(acl_tos *head, ACLChecklist *ch)
Checks for a TOS value to apply depending on the ACL.
Definition: FwdState.cc:1461
ssize_t HttpHeaderPos
Definition: HttpHeader.h:45
#define HttpHeaderInitPos
Definition: HttpHeader.h:48
void UpdateRequestNotes(ConnStateData *csd, HttpRequest &request, NotePairs const &helperNotes)
Definition: HttpRequest.cc:763
void httpRequestPack(void *obj, Packable *p)
Definition: HttpRequest.cc:361
@ LOG_TCP_DENIED
Definition: LogTags.h:52
@ LOG_TAG_NONE
Definition: LogTags.h:38
time_t squid_curtime
Definition: stub_libtime.cc:20
void SBufToCstring(char *d, const SBuf &s)
Definition: SBuf.h:752
class SquidConfig Config
Definition: SquidConfig.cc:12
int strListIsSubstr(const String *list, const char *s, char del)
Definition: StrList.cc:63
SBuf StringToSBuf(const String &s)
create a new SBuf from a String by copying contents
Definition: StringConvert.h:17
#define Must(condition)
Definition: TextException.h:71
int conn
the current server connection FD
Definition: Transport.cc:26
int matchDomainName(const char *h, const char *d, MatchDomainNameFlags flags)
Definition: Uri.cc:744
char * urlCanonicalCleanWithoutRequest(const SBuf &url, const HttpRequestMethod &method, const AnyP::UriScheme &scheme)
Definition: Uri.cc:628
void fvdbCountVia(const SBuf &)
void fvdbCountForwarded(const SBuf &)
count occurrences of the given X-Forwarded-For header value
void error(char *format,...)
#define assert(EX)
Definition: assert.h:17
int cbdataReferenceValid(const void *p)
Definition: cbdata.cc:265
#define cbdataReferenceDone(var)
Definition: cbdata.h:352
#define cbdataReference(var)
Definition: cbdata.h:343
#define CBDATA_CLASS_INIT(type)
Definition: cbdata.h:320
void nonBlockingCheck(ACLCB *callback, void *callback_data)
Definition: Checklist.cc:237
Ip::Address src_addr
AccessLogEntry::Pointer al
info for the future access.log, and external ACL
void syncAle(HttpRequest *adaptedRequest, const char *logUri) const override
assigns uninitialized adapted_request and url ALE components
AnyP::PortCfgPointer port
Security::CertPointer sslClientCert
cert received from the client
struct timeval start_time
The time the master transaction started.
int bumpMode
whether and how the request was SslBumped
HttpReplyPointer reply
class AccessLogEntry::CacheDetails cache
HierarchyLogEntry hier
void syncNotes(HttpRequest *request)
Comm::ConnectionPointer tcpClient
TCP/IP level details about the client connection.
HttpRequest * request
void setVirginUrlForMissingRequest(const SBuf &vu)
Remember Client URI (or equivalent) when there is no HttpRequest.
ProxyProtocol::HeaderPointer proxyProtocolHeader
see ConnStateData::proxyProtocolHeader_
class AccessLogEntry::SslDetails ssl
void updateError(const Error &)
sets (or updates the already stored) transaction error as needed
int kind
the matched custom access list verb (or zero)
Definition: Acl.h:170
bool denied() const
Definition: Acl.h:162
bool conflicted() const
whether Squid is uncertain about the allowed() or denied() answer
Definition: Acl.h:165
bool allowed() const
Definition: Acl.h:156
static bool Start(Method method, VectPoint vp, HttpRequest *req, HttpReply *, const AccessLogEntryPointer &, Adaptation::Initiator *)
Definition: AccessCheck.cc:30
summarizes adaptation service answer for the noteAdaptationAnswer() API
Definition: Answer.h:23
String ruleId
ACL (or similar rule) name that blocked forwarding.
Definition: Answer.h:40
Kind kind
the type of the answer
Definition: Answer.h:42
Http::MessagePointer message
HTTP request or response to forward.
Definition: Answer.h:39
bool final
whether the error, if any, cannot be bypassed
Definition: Answer.h:41
@ akForward
forward the supplied adapted HTTP message
Definition: Answer.h:27
@ akBlock
block or deny the master xaction; see authority
Definition: Answer.h:28
@ akError
no adapted message will come; see bypassable
Definition: Answer.h:29
CbcPointer< Initiate > initiateAdaptation(Initiate *x)
< starts freshly created initiate and returns a safe pointer to it
Definition: Initiator.cc:23
void clearAdaptation(CbcPointer< Initiate > &x)
clears the pointer (does not call announceInitiatorAbort)
Definition: Initiator.cc:32
void announceInitiatorAbort(CbcPointer< Initiate > &x)
inform the transaction about abnormal termination and clear the pointer
Definition: Initiator.cc:38
bool initiated(const CbcPointer< AsyncJob > &job) const
Must(initiated(initiate)) instead of Must(initiate.set()), for clarity.
Definition: Initiator.h:52
iterates services in ServiceGroup, starting adaptation launchers
Definition: Iterator.h:32
Port defaultPort() const
Definition: UriScheme.cc:71
Definition: Uri.h:31
AnyP::UriScheme const & getScheme() const
Definition: Uri.h:67
static char * cleanup(const char *uri)
Definition: Uri.cc:916
void port(const Port p)
reset authority port subcomponent
Definition: Uri.h:95
void host(const char *src)
Definition: Uri.cc:99
bool parse(const HttpRequestMethod &, const SBuf &url)
Definition: Uri.cc:254
void userInfo(const SBuf &s)
Definition: Uri.h:79
char const * denyMessage(char const *const default_message=nullptr) const
Definition: UserRequest.cc:127
void stopConsumingFrom(RefCount< BodyPipe > &)
Definition: BodyPipe.cc:118
MemBuf & buf
Definition: BodyPipe.h:74
const MemBuf & buf() const
Definition: BodyPipe.h:137
bool exhausted() const
Definition: BodyPipe.cc:174
uint64_t consumedSize() const
Definition: BodyPipe.h:111
bool setConsumerIfNotLate(const Consumer::Pointer &aConsumer)
Definition: BodyPipe.cc:228
int64_t prepPartialResponseGeneration()
ClientHttpRequest(ConnStateData *)
void noteAdaptationAclCheckDone(Adaptation::ServiceGroupPointer) override
void noteMoreBodyDataAvailable(BodyPipe::Pointer) override
struct ClientHttpRequest::Out out
void clearRequest()
resets the current request and log_uri to nil
HttpRequest *const request
void resumeBodyStorage()
called by StoreEntry when it has more buffer space available
bool receivedWholeAdaptedReply
noteBodyProductionEnded() was called
void noteBodyProductionEnded(BodyPipe::Pointer) override
StoreEntry * loggingEntry_
int64_t mRangeCLen() const
Definition: client_side.cc:764
void calloutsError(const err_type, const ErrorDetail::Pointer &)
Build an error reply. For use with the callouts.
void absorbLogUri(char *)
assigns log_uri with aUri without copying the entire C-string
ConnStateData * getConn() const
String rangeBoundaryStr() const
Definition: client_side.cc:804
void initRequest(HttpRequest *)
void setLogUriToRequestUri()
sets log_uri when we know the current request
void updateError(const Error &)
if necessary, stores new error information (if any)
CbcPointer< Adaptation::Initiate > virginHeadSource
void updateLoggingTags(const LogTags_ot code)
update the code in the transaction processing tags
MemObject * memObject() const
void setLogUriToRawUri(const char *, const HttpRequestMethod &)
size_t req_sz
raw request size on input, not current request size
ConnStateData * conn_
void setErrorUri(const char *)
BodyPipe::Pointer adaptedBodySource
Ssl::BumpMode sslBumpNeed_
whether (and how) the request needs to be bumped
HttpHdrRangeIter range_iter
void noteAdaptationAnswer(const Adaptation::Answer &) override
void handleAdaptedHeader(Http::Message *)
struct ClientHttpRequest::Flags flags
void resetRequest(HttpRequest *)
void callException(const std::exception &) override
called when the job throws during an async call
void assignRequest(HttpRequest *)
StoreEntry * storeEntry() const
void handleAdaptationBlock(const Adaptation::Answer &)
void noteBodyProducerAborted(BodyPipe::Pointer) override
void sslBumpEstablish(Comm::Flag)
bool sslBumpNeeded() const
returns true if and only if the request needs to be bumped
ClientRequestContext * calloutContext
Ssl::BumpMode sslBumpNeed() const
returns raw sslBump mode value
const LogTags & loggingTags() const
the processing tags associated with this request transaction.
void handleAdaptationFailure(const ErrorDetail::Pointer &, bool bypassable=false)
const AccessLogEntry::Pointer al
access.log entry
StoreEntry * loggingEntry() const
void startAdaptation(const Adaptation::ServiceGroupPointer &)
Initiate an asynchronous adaptation transaction which will call us back.
struct ClientHttpRequest::Redirect redirect
void clientAccessCheckDone(const Acl::Answer &)
void clientStoreIdDone(const Helper::Reply &)
void clientRedirectDone(const Helper::Reply &)
void sslBumpAccessCheckDone(const Acl::Answer &answer)
The callback function for ssl-bump access check list.
ClientRequestContext(ClientHttpRequest *)
bool readNextRequest
whether Squid should read after error handling
ClientHttpRequest * http
ACLChecklist * acl_checklist
need ptr back so we can unregister if needed
void checkNoCache()
applies "cache allow/deny" rules, asynchronously if needed
ErrorState * error
saved error page for centralized/delayed processing
void hostHeaderVerifyFailed(const char *A, const char *B)
void hostHeaderIpVerify(const ipcache_addrs *, const Dns::LookupDetails &)
void checkNoCacheDone(const Acl::Answer &)
static void Reset()
forgets the current context, setting it to nil/unknown
Definition: CodeContext.cc:77
Comm::Flag flag
comm layer result status.
Definition: CommCalls.h:82
Comm::ConnectionPointer conn
Definition: CommCalls.h:80
bool isOpen() const
Definition: Connection.h:101
char rfc931[USER_IDENT_SZ]
Definition: Connection.h:176
Ip::Address local
Definition: Connection.h:146
Ssl::ServerBump * serverBump()
Definition: client_side.h:286
bool auth
pinned for www authentication
Definition: client_side.h:148
bool switchedToHttps() const
Definition: client_side.h:285
const ProxyProtocol::HeaderPointer & proxyProtocolHeader() const
Definition: client_side.h:361
Comm::ConnectionPointer serverConnection
Definition: client_side.h:144
void switchToHttps(ClientHttpRequest *, Ssl::BumpMode bumpServerMode)
void setAuth(const Auth::UserRequest::Pointer &aur, const char *cause)
Definition: client_side.cc:518
const Auth::UserRequest::Pointer & getAuth() const
Definition: client_side.h:124
Error bareError
a problem that occurred without a request (e.g., while parsing headers)
Definition: client_side.h:382
void expectNoForwarding()
cleans up virgin request [body] forwarding state
struct ConnStateData::@37 flags
bool isOpen() const
Definition: client_side.cc:664
Ip::Address log_addr
Definition: client_side.h:137
Ssl::BumpMode sslBumpMode
ssl_bump decision (Ssl::bumpEnd if n/a).
Definition: client_side.h:305
bool readMore
needs comm_read (for this request or new requests)
Definition: client_side.h:140
AnyP::Port port
destination port of the request that caused serverConnection
Definition: client_side.h:146
void setServerBump(Ssl::ServerBump *srvBump)
Definition: client_side.h:287
struct ConnStateData::@38 pinning
bool have(const Ip::Address &ip, size_t *position=nullptr) const
Definition: ipcache.cc:973
encapsulates DNS lookup results
Definition: LookupDetails.h:23
err_type type
Definition: errorpage.h:170
void detailError(const ErrorDetail::Pointer &dCode)
set error type-specific detail code
Definition: errorpage.h:111
Auth::UserRequest::Pointer auth_user_request
Definition: errorpage.h:175
Http::StatusCode httpStatus
Definition: errorpage.h:173
a transaction problem
Definition: Error.h:18
err_type category
primary error classification (or ERR_NONE)
Definition: Error.h:35
void update(const Error &)
if necessary, stores the given error information (if any)
Definition: Error.cc:16
NotePairs notes
Definition: Reply.h:62
Helper::ResultCode result
The helper response 'result' field.
Definition: Reply.h:59
bool hasNoCache(const String **val=nullptr) const
Definition: HttpHdrCc.h:89
bool hasOnlyIfCached() const
Definition: HttpHdrCc.h:145
HttpHdrRange::iterator pos
HttpHdrRange::iterator end
iterator begin()
iterator end()
std::vector< HttpHdrRangeSpec * > specs
int64_t lowestOffset(int64_t) const
Http::HdrType id
Definition: HttpHeader.h:63
int delById(Http::HdrType id)
Definition: HttpHeader.cc:673
String getList(Http::HdrType id) const
Definition: HttpHeader.cc:820
void update(const HttpHeader *fresh)
Definition: HttpHeader.cc:274
HttpHeaderEntry * getEntry(HttpHeaderPos *pos) const
Definition: HttpHeader.cc:590
const char * getStr(Http::HdrType id) const
Definition: HttpHeader.cc:1196
time_t getTime(Http::HdrType id) const
Definition: HttpHeader.cc:1179
HttpHdrRange * getRange() const
Definition: HttpHeader.cc:1253
int has(Http::HdrType id) const
Definition: HttpHeader.cc:969
int hasListMember(Http::HdrType id, const char *member, const char separator) const
Definition: HttpHeader.cc:1695
MemBuf * pack() const
Definition: HttpReply.cc:110
int64_t bodySize(const HttpRequestMethod &) const
Definition: HttpReply.cc:374
static HttpReplyPointer MakeConnectionEstablished()
construct and return an HTTP/200 (Connection Established) response
Definition: HttpReply.cc:119
bool respMaybeCacheable() const
Http::MethodType id() const
Definition: RequestMethod.h:70
void recordLookup(const Dns::LookupDetails &detail)
Definition: HttpRequest.cc:583
HttpHdrRange * range
Definition: HttpRequest.h:143
CbcPointer< ConnStateData > clientConnectionManager
Definition: HttpRequest.h:232
HttpRequestMethod method
Definition: HttpRequest.h:114
HttpRequest * clone() const override
Definition: HttpRequest.cc:175
Ip::Address indirect_client_addr
Definition: HttpRequest.h:152
static HttpRequest * FromUrlXXX(const char *url, const MasterXaction::Pointer &, const HttpRequestMethod &method=Http::METHOD_GET)
Definition: HttpRequest.cc:528
time_t ims
Definition: HttpRequest.h:145
String store_id
Definition: HttpRequest.h:139
RequestFlags flags
Definition: HttpRequest.h:141
String x_forwarded_for_iterator
Definition: HttpRequest.h:187
void detailError(const err_type c, const ErrorDetail::Pointer &d)
sets error detail if no earlier detail was available
Definition: HttpRequest.h:101
NotePairs::Pointer notes()
Definition: HttpRequest.cc:755
ConnStateData * pinnedConnection()
Definition: HttpRequest.cc:728
void ignoreRange(const char *reason)
forgets about the cached Range header (for a reason)
Definition: HttpRequest.cc:624
const SBuf storeId()
Definition: HttpRequest.cc:736
bool maybeCacheable()
Definition: HttpRequest.cc:538
char * canonicalCleanUrl() const
Definition: HttpRequest.cc:817
Ip::Address my_addr
Definition: HttpRequest.h:155
Auth::UserRequest::Pointer auth_user_request
Definition: HttpRequest.h:127
Error error
the first transaction problem encountered (or falsy)
Definition: HttpRequest.h:161
Adaptation::Icap::History::Pointer icapHistory() const
Returns possibly nil history, creating it if icap logging is enabled.
Definition: HttpRequest.cc:389
AnyP::Uri url
the request URI
Definition: HttpRequest.h:115
Ip::Address client_addr
Definition: HttpRequest.h:149
const SBuf & effectiveRequestUri() const
RFC 7230 section 5.5 - Effective Request URI.
Definition: HttpRequest.cc:747
common parts of HttpRequest and HttpReply
Definition: Message.h:26
HttpHeader header
Definition: Message.h:74
int64_t content_length
Definition: Message.h:83
BodyPipe::Pointer body_pipe
optional pipeline to receive message body
Definition: Message.h:97
HttpHdrCc * cache_control
Definition: Message.h:76
AnyP::ProtocolVersion http_ver
Definition: Message.h:72
void setNoAddr()
Definition: Address.cc:292
unsigned short port() const
Definition: Address.cc:778
mb_size_t contentSize() const
available data size
Definition: MemBuf.h:47
void consume(mb_size_t sz)
removes sz bytes and "packs" by moving content left
Definition: MemBuf.cc:168
const HttpReply & baseReply() const
Definition: MemObject.h:59
void appendNewOnly(const NotePairs *src)
Definition: Notes.cc:381
const char * findFirst(const char *noteKey) const
Definition: Notes.cc:297
Definition: Range.h:19
C * getRaw() const
Definition: RefCount.h:80
bool doneFollowXff() const
Definition: RequestFlags.h:123
bool interceptTproxy
Set for requests handled by a "tproxy" port.
Definition: RequestFlags.h:70
bool accelerated
Definition: RequestFlags.h:62
bool connectionAuth
Definition: RequestFlags.h:80
bool forceTunnel
whether to forward via TunnelStateData (instead of FwdState)
Definition: RequestFlags.h:115
bool connectionProxyAuth
Definition: RequestFlags.h:85
bool hostVerified
Definition: RequestFlags.h:68
bool done_follow_x_forwarded_for
Definition: RequestFlags.h:103
void disableCacheUse(const char *reason)
Definition: RequestFlags.cc:30
bool intercepted
Definition: RequestFlags.h:66
bool nocacheHack
Definition: RequestFlags.h:60
bool loopDetected
Definition: RequestFlags.h:40
bool connectionAuthDisabled
Definition: RequestFlags.h:82
SupportOrVeto cachable
whether the response may be stored in the cache
Definition: RequestFlags.h:35
bool hierarchical
Definition: RequestFlags.h:38
Definition: SBuf.h:94
const char * c_str()
Definition: SBuf.cc:516
void resetWithoutLocking(T *t)
Reset raw pointer - unlock any previous one and save new one without locking.
Comm::ConnectionPointer clientConnection
Definition: Server.h:98
void stopReading()
cancels Comm::Read() if it is scheduled
Definition: Server.cc:60
struct SquidConfig::@94 Port
size_t appendDomainLen
Definition: SquidConfig.h:221
acl_access * adapted_http
Definition: SquidConfig.h:358
int log_uses_indirect_client
Definition: SquidConfig.h:326
int acl_uses_indirect_client
Definition: SquidConfig.h:324
wordlist * store_id
Definition: SquidConfig.h:200
acl_access * followXFF
Definition: SquidConfig.h:389
acl_access * redirector
Definition: SquidConfig.h:375
struct SquidConfig::@107 accessList
int hostStrictVerify
Definition: SquidConfig.h:335
int reload_into_ims
Definition: SquidConfig.h:291
struct SquidConfig::@106 onoff
acl_access * http
Definition: SquidConfig.h:357
wordlist * redirect
Definition: SquidConfig.h:199
struct SquidConfig::@99 Program
struct SquidConfig::@100 Accel
char * surrogate_id
Definition: SquidConfig.h:218
AclDenyInfoList * denyInfoList
Definition: SquidConfig.h:406
unsigned short icp
Definition: SquidConfig.h:139
struct SquidConfig::UrlHelperTimeout onUrlRewriteTimeout
acl_access * ssl_bump
Definition: SquidConfig.h:386
acl_access * noCache
Definition: SquidConfig.h:364
void completeSuccessfully(const char *whyWeAreSureWeStoredTheWholeReply)
Definition: store.cc:991
size_t bytesWanted(Range< size_t > const aRange, bool ignoreDelayPool=false) const
Definition: store.cc:211
void completeTruncated(const char *whyWeConsiderTheReplyTruncated)
Definition: store.cc:998
int unlock(const char *context)
Definition: store.cc:443
void complete()
Definition: store.cc:1005
void write(StoreIOBuffer)
Definition: store.cc:754
void lock(const char *context)
Definition: store.cc:419
bool timestampsSet()
Definition: store.cc:1361
void replaceHttpReply(const HttpReplyPointer &, const bool andStartWriting=true)
Definition: store.cc:1673
bool isEmpty() const
Definition: Store.h:66
void deferProducer(const AsyncCall::Pointer &producer)
call back producer when more buffer space is available
Definition: store.cc:340
void clean()
Definition: String.cc:118
char const * rawBuf() const
Definition: SquidString.h:86
void cut(size_type newLength)
Definition: String.cc:222
char const * termedBuf() const
Definition: SquidString.h:92
size_type size() const
Definition: SquidString.h:73
void veto()
makes decision() false regardless of past or future support() calls
Definition: SupportOrVeto.h:29
void CSD(clientStreamNode *, ClientHttpRequest *)
client stream detach
void CSR(clientStreamNode *, ClientHttpRequest *)
client stream read
void CSCB(clientStreamNode *, ClientHttpRequest *, HttpReply *, StoreIOBuffer)
client stream read callback
clientStream_status_t CSS(clientStreamNode *, ClientHttpRequest *)
ACLFilledChecklist * clientAclChecklistCreate(const acl_access *acl, ClientHttpRequest *http)
static void clientInterpretRequestHeaders(ClientHttpRequest *http)
static void clientRedirectAccessCheckDone(Acl::Answer answer, void *data)
static void clientFollowXForwardedForCheck(Acl::Answer answer, void *data)
#define FAILURE_MODE_TIME
static void checkNoCacheDoneWrapper(Acl::Answer, void *)
static void sslBumpAccessCheckDoneWrapper(Acl::Answer, void *)
ErrorState * clientBuildError(err_type, Http::StatusCode, char const *url, const ConnStateData *, HttpRequest *, const AccessLogEntry::Pointer &)
static void hostHeaderIpVerifyWrapper(const ipcache_addrs *ia, const Dns::LookupDetails &dns, void *data)
static void clientCheckPinning(ClientHttpRequest *http)
static int clientHierarchical(ClientHttpRequest *http)
static HLPCB clientStoreIdDoneWrapper
static void clientStoreIdAccessCheckDone(Acl::Answer answer, void *data)
int clientBeginRequest(const HttpRequestMethod &method, char const *url, CSCB *streamcallback, CSD *streamdetach, ClientStreamData streamdata, HttpHeader const *header, char *tailbuf, size_t taillen, const MasterXaction::Pointer &mx)
static void checkFailureRatio(err_type, hier_code)
static HLPCB clientRedirectDoneWrapper
SQUIDCEXTERN CSR clientGetMoreData
static void clientAccessCheckDoneWrapper(Acl::Answer, void *)
SQUIDCEXTERN CSS clientReplyStatus
SQUIDCEXTERN CSD clientReplyDetach
static void SslBumpEstablish(const Comm::ConnectionPointer &, char *, size_t, Comm::Flag errflag, int, void *data)
void tunnelStart(ClientHttpRequest *)
Definition: tunnel.cc:1140
#define DBG_IMPORTANT
Definition: Stream.h:38
#define debugs(SECTION, LEVEL, CONTENT)
Definition: Stream.h:193
#define DBG_CRITICAL
Definition: Stream.h:37
#define REDIRECT_DONE
Definition: defines.h:57
#define REDIRECT_PENDING
Definition: defines.h:56
#define MAX_URL
Definition: defines.h:78
static int port
Definition: ldap_backend.cc:70
err_type
Definition: forward.h:14
@ ERR_ACCESS_DENIED
Definition: forward.h:18
@ ERR_CONNECT_FAIL
Definition: forward.h:30
@ ERR_SECURE_CONNECT_FAIL
Definition: forward.h:31
@ ERR_DNS_FAIL
Definition: forward.h:35
@ ERR_GATEWAY_FAILURE
Definition: forward.h:67
@ ERR_NONE
Definition: forward.h:15
@ ERR_ICAP_FAILURE
Definition: forward.h:64
@ ERR_CONFLICT_HOST
Definition: forward.h:48
@ ERR_READ_ERROR
Definition: forward.h:28
@ ERR_CACHE_ACCESS_DENIED
Definition: forward.h:19
void fd_note(int fd, const char *s)
Definition: fd.cc:216
#define fd_table
Definition: fde.h:189
int refresh_nocache_hack
char ThisCache2[RFC2181_MAXHOSTNAMELEN<< 1]
int neighbors_do_private_keys
double request_failure_ratio
time_t hit_only_mode_until
err_type aclGetDenyInfoPage(AclDenyInfoList **head, const char *name, int redirect_allowed)
Definition: Gadgets.cc:42
int aclIsProxyAuth(const char *name)
Definition: Gadgets.cc:73
const char * AclMatchedName
Definition: Acl.cc:29
@ ACCESS_AUTH_REQUIRED
Definition: Acl.h:120
@ ACCESS_DENIED
Definition: Acl.h:115
@ ACCESS_ALLOWED
Definition: Acl.h:116
void clientStreamRead(clientStreamNode *thisObject, ClientHttpRequest *http, StoreIOBuffer readBuffer)
void clientStreamInit(dlink_list *list, CSR *func, CSD *rdetach, CSS *readstatus, ClientStreamData readdata, CSCB *callback, CSD *cdetach, ClientStreamData callbackdata, StoreIOBuffer tailBuffer)
void errorAppendEntry(StoreEntry *entry, ErrorState *err)
Definition: errorpage.cc:718
void ipcache_nbgethostbyname(const char *name, IPH *handler, void *handlerData)
Definition: ipcache.cc:599
const char * bumpMode(int bm)
Definition: support.h:138
const char * sslGetUserEmail(SSL *ssl)
Definition: support.cc:885
BumpMode
Definition: support.h:126
@ bumpTerminate
Definition: support.h:126
@ bumpEnd
Definition: support.h:126
@ bumpClientFirst
Definition: support.h:126
@ bumpSplice
Definition: support.h:126
@ bumpBump
Definition: support.h:126
void HLPCB(void *, const Helper::Reply &)
Definition: forward.h:27
hier_code
Definition: hier_code.h:12
@ HIER_NONE
Definition: hier_code.h:13
void HTTPMSGUNLOCK(M *&a)
Definition: Message.h:149
void HTTPMSGLOCK(Http::Message *a)
Definition: Message.h:160
unsigned char tos_t
Definition: forward.h:27
static uint32 A
Definition: md4.c:43
static uint32 B
Definition: md4.c:43
@ methodReqmod
Definition: Elements.h:17
@ pointPreCache
Definition: Elements.h:18
@ PROTO_HTTP
Definition: ProtocolType.h:25
@ PROTO_CACHE_OBJECT
Definition: ProtocolType.h:31
bool IsConnOpen(const Comm::ConnectionPointer &conn)
Definition: Connection.cc:27
void Write(const Comm::ConnectionPointer &conn, const char *buf, int size, AsyncCall::Pointer &callback, FREE *free_func)
Definition: Write.cc:33
Flag
Definition: Flag.h:15
@ OK
Definition: Flag.h:16
@ ERR_CLOSING
Definition: Flag.h:24
@ Unknown
Definition: ResultCode.h:17
@ BrokenHelper
Definition: ResultCode.h:20
@ Error
Definition: ResultCode.h:19
@ TimedOut
Definition: ResultCode.h:21
@ Okay
Definition: ResultCode.h:18
StatusCode
Definition: StatusCode.h:20
@ scForbidden
Definition: StatusCode.h:47
@ scUnauthorized
Definition: StatusCode.h:45
@ scFound
Definition: StatusCode.h:38
@ scInternalServerError
Definition: StatusCode.h:71
@ scConflict
Definition: StatusCode.h:53
@ scPermanentRedirect
Definition: StatusCode.h:43
@ scSeeOther
Definition: StatusCode.h:39
@ scProxyAuthenticationRequired
Definition: StatusCode.h:51
@ scTemporaryRedirect
Definition: StatusCode.h:42
@ scMovedPermanently
Definition: StatusCode.h:37
@ METHOD_TRACE
Definition: MethodType.h:30
@ METHOD_OTHER
Definition: MethodType.h:93
@ METHOD_CONNECT
Definition: MethodType.h:29
@ METHOD_GET
Definition: MethodType.h:25
@ METHOD_HEAD
Definition: MethodType.h:28
@ PROXY_AUTHORIZATION
@ IF_MODIFIED_SINCE
AnyP::ProtocolVersion ProtocolVersion(unsigned int aMajor, unsigned int aMinor)
HTTP version label information.
bool setNfConnmark(Comm::ConnectionPointer &conn, const ConnectionDirection connDir, const NfMarkConfig &cm)
Definition: QosConfig.cc:181
@ dirAccepted
accepted (from a client by Squid)
Definition: QosConfig.h:67
Config TheConfig
Globally available instance of Qos::Config.
Definition: QosConfig.cc:283
int setSockTos(const Comm::ConnectionPointer &conn, tos_t tos)
Definition: QosConfig.cc:570
int setSockNfmark(const Comm::ConnectionPointer &conn, nfmark_t mark)
Definition: QosConfig.cc:602
#define xfree
#define xstrdup
void storeIdStart(ClientHttpRequest *http, HLPCB *handler, void *data)
Definition: redirect.cc:311
void redirectStart(ClientHttpRequest *http, HLPCB *handler, void *data)
Definition: redirect.cc:285
@ toutActBypass
Definition: redirect.h:16
#define SQUIDCEXTERN
Definition: squid.h:21
StoreEntry * storeCreateEntry(const char *url, const char *logUrl, const RequestFlags &flags, const HttpRequestMethod &method)
Definition: store.cc:733
int64_t strtoll(const char *nptr, char **endptr, int base)
Definition: strtoll.c:61
Definition: parse.c:104
struct timeval current_time
the current UNIX time in timeval {seconds, microseconds} format
Definition: gadgets.cc:17
void debugObj(int section, int level, const char *label, void *obj, ObjPackMethod pm)
Definition: tools.cc:938
void(* ObjPackMethod)(void *obj, Packable *p)
Definition: tools.h:33
#define NULL
Definition: types.h:160
void * xcalloc(size_t n, size_t sz)
Definition: xalloc.cc:71
#define safe_free(x)
Definition: xalloc.h:73
#define xisspace(x)
Definition: xis.h:17
char * xstrndup(const char *s, size_t n)
Definition: xstring.cc:56

 

Introduction

Documentation

Support

Miscellaneous

Web Site Translations

Mirrors