client_side_request.cc
Go to the documentation of this file.
1 /*
2  * Copyright (C) 1996-2018 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"
27 #include "ClientRequestContext.h"
28 #include "clientStream.h"
29 #include "comm/Connection.h"
30 #include "comm/Write.h"
31 #include "err_detail_type.h"
32 #include "errorpage.h"
33 #include "fd.h"
34 #include "fde.h"
35 #include "format/Token.h"
36 #include "gopher.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 "profiler/Profiler.h"
51 #include "redirect.h"
52 #include "SquidConfig.h"
53 #include "SquidTime.h"
54 #include "Store.h"
55 #include "StrList.h"
56 #include "tools.h"
57 #include "wordlist.h"
58 #if USE_AUTH
59 #include "auth/UserRequest.h"
60 #endif
61 #if USE_ADAPTATION
62 #include "adaptation/AccessCheck.h"
63 #include "adaptation/Answer.h"
64 #include "adaptation/Iterator.h"
65 #include "adaptation/Service.h"
66 #if ICAP_CLIENT
68 #endif
69 #endif
70 #if USE_OPENSSL
71 #include "ssl/ServerBump.h"
72 #include "ssl/support.h"
73 #endif
74 
75 #if LINGERING_CLOSE
76 #define comm_close comm_lingering_close
77 #endif
78 
79 static const char *const crlf = "\r\n";
80 
81 #if FOLLOW_X_FORWARDED_FOR
82 static void clientFollowXForwardedForCheck(allow_t answer, void *data);
83 #endif /* FOLLOW_X_FORWARDED_FOR */
84 
86 
88 
89 /* Local functions */
90 /* other */
91 static void clientAccessCheckDoneWrapper(allow_t, void *);
92 #if USE_OPENSSL
93 static void sslBumpAccessCheckDoneWrapper(allow_t, void *);
94 #endif
95 static int clientHierarchical(ClientHttpRequest * http);
99 static void checkNoCacheDoneWrapper(allow_t, void *);
103 static void checkFailureRatio(err_type, hier_code);
104 
106 {
107  /*
108  * Release our "lock" on our parent, ClientHttpRequest, if we
109  * still have one
110  */
111 
112  if (http)
114 
115  delete error;
116  debugs(85,3, "ClientRequestContext destructed, this=" << this);
117 }
118 
120  http(cbdataReference(anHttp)),
121  acl_checklist(NULL),
122  redirect_state(REDIRECT_NONE),
123  store_id_state(REDIRECT_NONE),
124  host_header_verify_done(false),
125  http_access_done(false),
126  adapted_http_access_done(false),
127 #if USE_ADAPTATION
128  adaptation_acl_check_done(false),
129 #endif
130  redirect_done(false),
131  store_id_done(false),
132  no_cache_done(false),
133  interpreted_req_hdrs(false),
134  toClientMarkingDone(false),
135 #if USE_OPENSSL
136  sslBumpCheckDone(false),
137 #endif
138  error(NULL),
139  readNextRequest(false)
140 {
141  debugs(85, 3, "ClientRequestContext constructed, this=" << this);
142 }
143 
145 
147 #if USE_ADAPTATION
148  AsyncJob("ClientHttpRequest"),
149 #endif
150  request(NULL),
151  uri(NULL),
152  log_uri(NULL),
153  req_sz(0),
154  logType(LOG_TAG_NONE),
155  calloutContext(NULL),
156  maxReplyBodySize_(0),
157  entry_(NULL),
158  loggingEntry_(NULL),
159  conn_(NULL)
160 #if USE_OPENSSL
161  , sslBumpNeed_(Ssl::bumpEnd)
162 #endif
163 #if USE_ADAPTATION
164  , request_satisfaction_mode(false)
165  , request_satisfaction_offset(0)
166 #endif
167 {
168  setConn(aConn);
169  al = new AccessLogEntry;
171  if (aConn) {
173  al->cache.port = aConn->port;
174  al->cache.caddr = aConn->log_addr;
175 
176 #if USE_OPENSSL
177  if (aConn->clientConnection != NULL && aConn->clientConnection->isOpen()) {
178  if (auto ssl = fd_table[aConn->clientConnection->fd].ssl.get())
179  al->cache.sslClientCert.resetWithoutLocking(SSL_get_peer_certificate(ssl));
180  }
181 #endif
182  }
184 }
185 
186 /*
187  * returns true if client specified that the object must come from the cache
188  * without contacting origin server
189  */
190 bool
192 {
193  assert(request);
194  return request->cache_control &&
196 }
197 
210 static void
212 {
213  // Can be set at compile time with -D compiler flag
214 #ifndef FAILURE_MODE_TIME
215 #define FAILURE_MODE_TIME 300
216 #endif
217 
218  if (hcode == HIER_NONE)
219  return;
220 
221  // don't bother when ICP is disabled.
222  if (Config.Port.icp <= 0)
223  return;
224 
225  static double magic_factor = 100.0;
226  double n_good;
227  double n_bad;
228 
229  n_good = magic_factor / (1.0 + request_failure_ratio);
230 
231  n_bad = magic_factor - n_good;
232 
233  switch (etype) {
234 
235  case ERR_DNS_FAIL:
236 
237  case ERR_CONNECT_FAIL:
239 
240  case ERR_READ_ERROR:
241  ++n_bad;
242  break;
243 
244  default:
245  ++n_good;
246  }
247 
248  request_failure_ratio = n_bad / n_good;
249 
251  return;
252 
253  if (request_failure_ratio < 1.0)
254  return;
255 
256  debugs(33, DBG_CRITICAL, "WARNING: Failure Ratio at "<< std::setw(4)<<
257  std::setprecision(3) << request_failure_ratio);
258 
259  debugs(33, DBG_CRITICAL, "WARNING: ICP going into HIT-only mode for " <<
260  FAILURE_MODE_TIME / 60 << " minutes...");
261 
263 
264  request_failure_ratio = 0.8; /* reset to something less than 1.0 */
265 }
266 
268 {
269  debugs(33, 3, "httpRequestFree: " << uri);
271 
272  // Even though freeResources() below may destroy the request,
273  // we no longer set request->body_pipe to NULL here
274  // because we did not initiate that pipe (ConnStateData did)
275 
276  /* the ICP check here was erroneous
277  * - StoreEntry::releaseRequest was always called if entry was valid
278  */
279 
280  logRequest();
281 
283 
284  if (request)
286 
287  freeResources();
288 
289 #if USE_ADAPTATION
291 
292  if (adaptedBodySource != NULL)
294 #endif
295 
296  if (calloutContext)
297  delete calloutContext;
298 
300 
301  if (conn_)
303 
304  /* moving to the next connection is handled by the context free */
306 
308 }
309 
319 int
320 clientBeginRequest(const HttpRequestMethod& method, char const *url, CSCB * streamcallback,
321  CSD * streamdetach, ClientStreamData streamdata, HttpHeader const *header,
322  char *tailbuf, size_t taillen, const MasterXaction::Pointer &mx)
323 {
324  size_t url_sz;
327  StoreIOBuffer tempBuffer;
328  if (http->al != NULL)
329  http->al->cache.start_time = current_time;
330  /* this is only used to adjust the connection offset in client_side.c */
331  http->req_sz = 0;
332  tempBuffer.length = taillen;
333  tempBuffer.data = tailbuf;
334  /* client stream setup */
336  clientReplyStatus, new clientReplyContext(http), streamcallback,
337  streamdetach, streamdata, tempBuffer);
338  /* make it visible in the 'current acctive requests list' */
339  /* Set flags */
340  /* internal requests only makes sense in an
341  * accelerator today. TODO: accept flags ? */
342  http->flags.accel = true;
343  /* allow size for url rewriting */
344  url_sz = strlen(url) + Config.appendDomainLen + 5;
345  http->uri = (char *)xcalloc(url_sz, 1);
346  strcpy(http->uri, url); // XXX: polluting http->uri before parser validation
347 
348  if ((request = HttpRequest::FromUrl(http->uri, mx, method)) == NULL) {
349  debugs(85, 5, "Invalid URL: " << http->uri);
350  return -1;
351  }
352 
353  /*
354  * now update the headers in request with our supplied headers.
355  * HttpRequest::FromUrl() should return a blank header set, but
356  * we use Update to be sure of correctness.
357  */
358  if (header)
359  request->header.update(header);
360 
361  http->log_uri = xstrdup(urlCanonicalClean(request));
362 
363  /* http struct now ready */
364 
365  /*
366  * build new header list *? TODO
367  */
368  request->flags.accelerated = http->flags.accel;
369 
370  /* this is an internally created
371  * request, not subject to acceleration
372  * target overrides */
373  /*
374  * FIXME? Do we want to detect and handle internal requests of internal
375  * objects ?
376  */
377 
378  /* Internally created requests cannot have bodies today */
379  request->content_length = 0;
380 
381  request->client_addr.setNoAddr();
382 
383 #if FOLLOW_X_FORWARDED_FOR
384  request->indirect_client_addr.setNoAddr();
385 #endif /* FOLLOW_X_FORWARDED_FOR */
386 
387  request->my_addr.setNoAddr(); /* undefined for internal requests */
388 
389  request->my_addr.port(0);
390 
391  request->http_ver = Http::ProtocolVersion();
392 
393  http->request = request;
394  HTTPMSGLOCK(http->request);
395 
396  /* optional - skip the access check ? */
397  http->calloutContext = new ClientRequestContext(http);
398 
399  http->calloutContext->http_access_done = false;
400 
401  http->calloutContext->redirect_done = true;
402 
403  http->calloutContext->no_cache_done = true;
404 
405  http->doCallouts();
406 
407  return 0;
408 }
409 
410 bool
412 {
413  ClientHttpRequest *http_ = http;
414 
415  if (cbdataReferenceValid(http_))
416  return true;
417 
418  http = NULL;
419 
420  cbdataReferenceDone(http_);
421 
422  return false;
423 }
424 
425 #if FOLLOW_X_FORWARDED_FOR
426 
440 static void
442 {
443  ClientRequestContext *calloutContext = (ClientRequestContext *) data;
444 
445  if (!calloutContext->httpStateIsValid())
446  return;
447 
448  ClientHttpRequest *http = calloutContext->http;
449  HttpRequest *request = http->request;
450 
451  if (answer.allowed() && request->x_forwarded_for_iterator.size() != 0) {
452 
453  /*
454  * Remove the last comma-delimited element from the
455  * x_forwarded_for_iterator and use it to repeat the cycle.
456  */
457  const char *p;
458  const char *asciiaddr;
459  int l;
461  p = request->x_forwarded_for_iterator.termedBuf();
462  l = request->x_forwarded_for_iterator.size();
463 
464  /*
465  * XXX x_forwarded_for_iterator should really be a list of
466  * IP addresses, but it's a String instead. We have to
467  * walk backwards through the String, biting off the last
468  * comma-delimited part each time. As long as the data is in
469  * a String, we should probably implement and use a variant of
470  * strListGetItem() that walks backwards instead of forwards
471  * through a comma-separated list. But we don't even do that;
472  * we just do the work in-line here.
473  */
474  /* skip trailing space and commas */
475  while (l > 0 && (p[l-1] == ',' || xisspace(p[l-1])))
476  --l;
477  request->x_forwarded_for_iterator.cut(l);
478  /* look for start of last item in list */
479  while (l > 0 && ! (p[l-1] == ',' || xisspace(p[l-1])))
480  --l;
481  asciiaddr = p+l;
482  if ((addr = asciiaddr)) {
483  request->indirect_client_addr = addr;
484  request->x_forwarded_for_iterator.cut(l);
487  /* override the default src_addr tested if we have to go deeper than one level into XFF */
488  Filled(calloutContext->acl_checklist)->src_addr = request->indirect_client_addr;
489  }
491  return;
492  }
493  }
494 
495  /* clean up, and pass control to clientAccessCheck */
497  /*
498  * Ensure that the access log shows the indirect client
499  * instead of the direct client.
500  */
501  http->al->cache.caddr = request->indirect_client_addr;
502  if (ConnStateData *conn = http->getConn())
503  conn->log_addr = request->indirect_client_addr;
504  }
505  request->x_forwarded_for_iterator.clean();
506  request->flags.done_follow_x_forwarded_for = true;
507 
508  if (answer.conflicted()) {
509  debugs(28, DBG_CRITICAL, "ERROR: Processing X-Forwarded-For. Stopping at IP address: " << request->indirect_client_addr );
510  }
511 
512  /* process actual access ACL as normal. */
513  calloutContext->clientAccessCheck();
514 }
515 #endif /* FOLLOW_X_FORWARDED_FOR */
516 
517 static void
519 {
520  ClientRequestContext *c = static_cast<ClientRequestContext*>(data);
521  c->hostHeaderIpVerify(ia, dns);
522 }
523 
524 void
526 {
528 
529  // note the DNS details for the transaction stats.
530  http->request->recordLookup(dns);
531 
532  // Is the NAT destination IP in DNS?
533  if (ia && ia->have(clientConn->local)) {
534  debugs(85, 3, "validate IP " << clientConn->local << " possible from Host:");
535  http->request->flags.hostVerified = true;
536  http->doCallouts();
537  return;
538  }
539  debugs(85, 3, HERE << "FAIL: validate IP " << clientConn->local << " possible from Host:");
540  hostHeaderVerifyFailed("local IP", "any domain IP");
541 }
542 
543 void
545 {
546  // IP address validation for Host: failed. Admin wants to ignore them.
547  // NP: we do not yet handle CONNECT tunnels well, so ignore for them
549  debugs(85, 3, "SECURITY ALERT: Host header forgery detected on " << http->getConn()->clientConnection <<
550  " (" << A << " does not match " << B << ") on URL: " << http->request->effectiveRequestUri());
551 
552  // NP: it is tempting to use 'flags.noCache' but that is all about READing cache data.
553  // The problems here are about WRITE for new cache content, which means flags.cachable
554  http->request->flags.cachable = false; // MUST NOT cache (for now)
555  // XXX: when we have updated the cache key to base on raw-IP + URI this cacheable limit can go.
556  http->request->flags.hierarchical = false; // MUST NOT pass to peers (for now)
557  // XXX: when we have sorted out the best way to relay requests properly to peers this hierarchical limit can go.
558  http->doCallouts();
559  return;
560  }
561 
562  debugs(85, DBG_IMPORTANT, "SECURITY ALERT: Host header forgery detected on " <<
563  http->getConn()->clientConnection << " (" << A << " does not match " << B << ")");
564  if (const char *ua = http->request->header.getStr(Http::HdrType::USER_AGENT))
565  debugs(85, DBG_IMPORTANT, "SECURITY ALERT: By user agent: " << ua);
566  debugs(85, DBG_IMPORTANT, "SECURITY ALERT: on URL: " << http->request->effectiveRequestUri());
567 
568  // IP address validation for Host: failed. reject the connection.
570  clientReplyContext *repContext = dynamic_cast<clientReplyContext *>(node->data.getRaw());
571  assert (repContext);
572  repContext->setReplyToError(ERR_CONFLICT_HOST, Http::scConflict,
573  http->request->method, NULL,
575  http->request,
576  NULL,
577 #if USE_AUTH
578  http->getConn() != NULL && http->getConn()->getAuth() != NULL ?
580 #else
581  NULL);
582 #endif
584  clientStreamRead(node, http, node->readBuffer);
585 }
586 
587 void
589 {
590  // Require a Host: header.
591  const char *host = http->request->header.getStr(Http::HdrType::HOST);
592 
593  if (!host) {
594  // TODO: dump out the HTTP/1.1 error about missing host header.
595  // otherwise this is fine, can't forge a header value when its not even set.
596  debugs(85, 3, HERE << "validate skipped with no Host: header present.");
597  http->doCallouts();
598  return;
599  }
600 
601  if (http->request->flags.internal) {
602  // TODO: kill this when URL handling allows partial URLs out of accel mode
603  // and we no longer screw with the URL just to add our internal host there
604  debugs(85, 6, HERE << "validate skipped due to internal composite URL.");
605  http->doCallouts();
606  return;
607  }
608 
609  // Locate if there is a port attached, strip ready for IP lookup
610  char *portStr = NULL;
611  char *hostB = xstrdup(host);
612  host = hostB;
613  if (host[0] == '[') {
614  // IPv6 literal.
615  portStr = strchr(hostB, ']');
616  if (portStr && *(++portStr) != ':') {
617  portStr = NULL;
618  }
619  } else {
620  // Domain or IPv4 literal with port
621  portStr = strrchr(hostB, ':');
622  }
623 
624  uint16_t port = 0;
625  if (portStr) {
626  *portStr = '\0'; // strip the ':'
627  if (*(++portStr) != '\0') {
628  char *end = NULL;
629  int64_t ret = strtoll(portStr, &end, 10);
630  if (end == portStr || *end != '\0' || ret < 1 || ret > 0xFFFF) {
631  // invalid port details. Replace the ':'
632  *(--portStr) = ':';
633  portStr = NULL;
634  } else
635  port = (ret & 0xFFFF);
636  }
637  }
638 
639  debugs(85, 3, "validate host=" << host << ", port=" << port << ", portStr=" << (portStr?portStr:"NULL"));
641  // verify the Host: port (if any) matches the apparent destination
642  if (portStr && port != http->getConn()->clientConnection->local.port()) {
643  debugs(85, 3, "FAIL on validate port " << http->getConn()->clientConnection->local.port() <<
644  " matches Host: port " << port << " (" << portStr << ")");
645  hostHeaderVerifyFailed("intercepted port", portStr);
646  } else {
647  // XXX: match the scheme default port against the apparent destination
648 
649  // verify the destination DNS is one of the Host: headers IPs
651  }
652  } else if (!Config.onoff.hostStrictVerify) {
653  debugs(85, 3, "validate skipped.");
654  http->doCallouts();
655  } else if (strlen(host) != strlen(http->request->url.host())) {
656  // Verify forward-proxy requested URL domain matches the Host: header
657  debugs(85, 3, "FAIL on validate URL domain length " << http->request->url.host() << " matches Host: " << host);
659  } else if (matchDomainName(host, http->request->url.host()) != 0) {
660  // Verify forward-proxy requested URL domain matches the Host: header
661  debugs(85, 3, "FAIL on validate URL domain " << http->request->url.host() << " matches Host: " << host);
663  } else if (portStr && port != http->request->url.port()) {
664  // Verify forward-proxy requested URL domain matches the Host: header
665  debugs(85, 3, "FAIL on validate URL port " << http->request->url.port() << " matches Host: port " << portStr);
666  hostHeaderVerifyFailed("URL port", portStr);
667  } else if (!portStr && http->request->method != Http::METHOD_CONNECT && http->request->url.port() != http->request->url.getScheme().defaultPort()) {
668  // Verify forward-proxy requested URL domain matches the Host: header
669  // Special case: we don't have a default-port to check for CONNECT. Assume URL is correct.
670  debugs(85, 3, "FAIL on validate URL port " << http->request->url.port() << " matches Host: default port " << http->request->url.getScheme().defaultPort());
671  hostHeaderVerifyFailed("URL port", "default port");
672  } else {
673  // Okay no problem.
674  debugs(85, 3, "validate passed.");
675  http->request->flags.hostVerified = true;
676  http->doCallouts();
677  }
678  safe_free(hostB);
679 }
680 
681 /* This is the entry point for external users of the client_side routines */
682 void
684 {
685 #if FOLLOW_X_FORWARDED_FOR
686  if (!http->request->flags.doneFollowXff() &&
689 
690  /* we always trust the direct client address for actual use */
693 
694  /* setup the XFF iterator for processing */
696 
697  /* begin by checking to see if we trust direct client enough to walk XFF */
700  return;
701  }
702 #endif
703 
704  if (Config.accessList.http) {
707  } else {
708  debugs(0, DBG_CRITICAL, "No http_access configuration found. This will block ALL traffic");
710  }
711 }
712 
718 void
720 {
724  } else {
725  debugs(85, 2, HERE << "No adapted_http_access configuration. default: ALLOW");
727  }
728 }
729 
730 void
732 {
733  ClientRequestContext *calloutContext = (ClientRequestContext *) data;
734 
735  if (!calloutContext->httpStateIsValid())
736  return;
737 
738  calloutContext->clientAccessCheckDone(answer);
739 }
740 
741 void
743 {
745  err_type page_id;
746  Http::StatusCode status;
747  debugs(85, 2, "The request " << http->request->method << ' ' <<
748  http->uri << " is " << answer <<
749  "; last ACL checked: " << (AclMatchedName ? AclMatchedName : "[none]"));
750 
751 #if USE_AUTH
752  char const *proxy_auth_msg = "<null>";
753  if (http->getConn() != NULL && http->getConn()->getAuth() != NULL)
754  proxy_auth_msg = http->getConn()->getAuth()->denyMessage("<null>");
755  else if (http->request->auth_user_request != NULL)
756  proxy_auth_msg = http->request->auth_user_request->denyMessage("<null>");
757 #endif
758 
759  if (!answer.allowed()) {
760  // auth has a grace period where credentials can be expired but okay not to challenge.
761 
762  /* Send an auth challenge or error */
763  // XXX: do we still need aclIsProxyAuth() ?
764  bool auth_challenge = (answer == ACCESS_AUTH_REQUIRED || aclIsProxyAuth(AclMatchedName));
765  debugs(85, 5, "Access Denied: " << http->uri);
766  debugs(85, 5, "AclMatchedName = " << (AclMatchedName ? AclMatchedName : "<null>"));
767 #if USE_AUTH
768  if (auth_challenge)
769  debugs(33, 5, "Proxy Auth Message = " << (proxy_auth_msg ? proxy_auth_msg : "<null>"));
770 #endif
771 
772  /*
773  * NOTE: get page_id here, based on AclMatchedName because if
774  * USE_DELAY_POOLS is enabled, then AclMatchedName gets clobbered in
775  * the clientCreateStoreEntry() call just below. Pedro Ribeiro
776  * <pribeiro@isel.pt>
777  */
778  page_id = aclGetDenyInfoPage(&Config.denyInfoList, AclMatchedName, answer != ACCESS_AUTH_REQUIRED);
779 
781 
782  if (auth_challenge) {
783 #if USE_AUTH
784  if (http->request->flags.sslBumped) {
785  /*SSL Bumped request, authentication is not possible*/
786  status = Http::scForbidden;
787  } else if (!http->flags.accel) {
788  /* Proxy authorisation needed */
790  } else {
791  /* WWW authorisation needed */
792  status = Http::scUnauthorized;
793  }
794 #else
795  // need auth, but not possible to do.
796  status = Http::scForbidden;
797 #endif
798  if (page_id == ERR_NONE)
799  page_id = ERR_CACHE_ACCESS_DENIED;
800  } else {
801  status = Http::scForbidden;
802 
803  if (page_id == ERR_NONE)
804  page_id = ERR_ACCESS_DENIED;
805  }
806 
807  Ip::Address tmpnoaddr;
808  tmpnoaddr.setNoAddr();
809  error = clientBuildError(page_id, status,
810  NULL,
811  http->getConn() != NULL ? http->getConn()->clientConnection->remote : tmpnoaddr,
812  http->request
813  );
814 
815 #if USE_AUTH
817  http->getConn() != NULL && http->getConn()->getAuth() != NULL ?
819 #endif
820 
821  readNextRequest = true;
822  }
823 
824  /* ACCESS_ALLOWED continues here ... */
825  xfree(http->uri);
827  http->doCallouts();
828 }
829 
830 #if USE_ADAPTATION
831 void
833 {
834  debugs(93,3,HERE << this << " adaptationAclCheckDone called");
835 
836 #if ICAP_CLIENT
838  if (ih != NULL) {
839  if (getConn() != NULL && getConn()->clientConnection != NULL) {
840  ih->rfc931 = getConn()->clientConnection->rfc931;
841 #if USE_OPENSSL
842  if (getConn()->clientConnection->isOpen()) {
843  ih->ssluser = sslGetUserEmail(fd_table[getConn()->clientConnection->fd].ssl.get());
844  }
845 #endif
846  }
847  ih->log_uri = log_uri;
848  ih->req_sz = req_sz;
849  }
850 #endif
851 
852  if (!g) {
853  debugs(85,3, HERE << "no adaptation needed");
854  doCallouts();
855  return;
856  }
857 
858  startAdaptation(g);
859 }
860 
861 #endif
862 
863 static void
865 {
866  ClientRequestContext *context = (ClientRequestContext *)data;
867  ClientHttpRequest *http = context->http;
868  context->acl_checklist = NULL;
869 
870  if (answer.allowed())
872  else {
873  Helper::Reply const nilReply(Helper::Error);
874  context->clientRedirectDone(nilReply);
875  }
876 }
877 
878 void
880 {
881  debugs(33, 5, HERE << "'" << http->uri << "'");
886  } else
888 }
889 
894 static void
896 {
897  ClientRequestContext *context = static_cast<ClientRequestContext *>(data);
898  ClientHttpRequest *http = context->http;
899  context->acl_checklist = NULL;
900 
901  if (answer.allowed())
902  storeIdStart(http, clientStoreIdDoneWrapper, context);
903  else {
904  debugs(85, 3, "access denied expected ERR reply handling: " << answer);
905  Helper::Reply const nilReply(Helper::Error);
906  context->clientStoreIdDone(nilReply);
907  }
908 }
909 
915 void
917 {
918  debugs(33, 5,"'" << http->uri << "'");
919 
920  if (Config.accessList.store_id) {
923  } else
925 }
926 
927 static int
929 {
930  HttpRequest *request = http->request;
931  HttpRequestMethod method = request->method;
932 
933  // intercepted requests MUST NOT (yet) be sent to peers unless verified
934  if (!request->flags.hostVerified && (request->flags.intercepted || request->flags.interceptTproxy))
935  return 0;
936 
937  /*
938  * IMS needs a private key, so we can use the hierarchy for IMS only if our
939  * neighbors support private keys
940  */
941 
942  if (request->flags.ims && !neighbors_do_private_keys)
943  return 0;
944 
945  /*
946  * This is incorrect: authenticating requests can be sent via a hierarchy
947  * (they can even be cached if the correct headers are set on the reply)
948  */
949  if (request->flags.auth)
950  return 0;
951 
952  if (method == Http::METHOD_TRACE)
953  return 1;
954 
955  if (method != Http::METHOD_GET)
956  return 0;
957 
958  if (request->flags.loopDetected)
959  return 0;
960 
961  if (request->url.getScheme() == AnyP::PROTO_HTTP)
962  return method.respMaybeCacheable();
963 
964  if (request->url.getScheme() == AnyP::PROTO_GOPHER)
965  return gopherCachable(request);
966 
967  if (request->url.getScheme() == AnyP::PROTO_CACHE_OBJECT)
968  return 0;
969 
970  return 1;
971 }
972 
973 static void
975 {
976  HttpRequest *request = http->request;
977  HttpHeader *req_hdr = &request->header;
978  ConnStateData *http_conn = http->getConn();
979 
980  /* Internal requests such as those from ESI includes may be without
981  * a client connection
982  */
983  if (!http_conn)
984  return;
985 
986  request->flags.connectionAuthDisabled = http_conn->port->connection_auth_disabled;
987  if (!request->flags.connectionAuthDisabled) {
988  if (Comm::IsConnOpen(http_conn->pinning.serverConnection)) {
989  if (http_conn->pinning.auth) {
990  request->flags.connectionAuth = true;
991  request->flags.auth = true;
992  } else {
993  request->flags.connectionProxyAuth = true;
994  }
995  // These should already be linked correctly.
996  assert(request->clientConnectionManager == http_conn);
997  }
998  }
999 
1000  /* check if connection auth is used, and flag as candidate for pinning
1001  * in such case.
1002  * Note: we may need to set flags.connectionAuth even if the connection
1003  * is already pinned if it was pinned earlier due to proxy auth
1004  */
1005  if (!request->flags.connectionAuth) {
1008  HttpHeaderEntry *e;
1009  int may_pin = 0;
1010  while ((e = req_hdr->getEntry(&pos))) {
1012  const char *value = e->value.rawBuf();
1013  if (strncasecmp(value, "NTLM ", 5) == 0
1014  ||
1015  strncasecmp(value, "Negotiate ", 10) == 0
1016  ||
1017  strncasecmp(value, "Kerberos ", 9) == 0) {
1018  if (e->id == Http::HdrType::AUTHORIZATION) {
1019  request->flags.connectionAuth = true;
1020  may_pin = 1;
1021  } else {
1022  request->flags.connectionProxyAuth = true;
1023  may_pin = 1;
1024  }
1025  }
1026  }
1027  }
1028  if (may_pin && !request->pinnedConnection()) {
1029  // These should already be linked correctly. Just need the ServerConnection to pinn.
1030  assert(request->clientConnectionManager == http_conn);
1031  }
1032  }
1033  }
1034 }
1035 
1036 static void
1038 {
1039  HttpRequest *request = http->request;
1040  HttpHeader *req_hdr = &request->header;
1041  bool no_cache = false;
1042 
1043  request->imslen = -1;
1044  request->ims = req_hdr->getTime(Http::HdrType::IF_MODIFIED_SINCE);
1045 
1046  if (request->ims > 0)
1047  request->flags.ims = true;
1048 
1049  if (!request->flags.ignoreCc) {
1050  if (request->cache_control) {
1051  if (request->cache_control->hasNoCache())
1052  no_cache=true;
1053 
1054  // RFC 2616: treat Pragma:no-cache as if it was Cache-Control:no-cache when Cache-Control is missing
1055  } else if (req_hdr->has(Http::HdrType::PRAGMA))
1056  no_cache = req_hdr->hasListMember(Http::HdrType::PRAGMA,"no-cache",',');
1057  }
1058 
1059  if (request->method == Http::METHOD_OTHER) {
1060  no_cache=true;
1061  }
1062 
1063  if (no_cache) {
1064 #if USE_HTTP_VIOLATIONS
1065 
1067  request->flags.nocacheHack = true;
1068  else if (refresh_nocache_hack)
1069  request->flags.nocacheHack = true;
1070  else
1071 #endif
1072 
1073  request->flags.noCache = true;
1074  }
1075 
1076  /* ignore range header in non-GETs or non-HEADs */
1077  if (request->method == Http::METHOD_GET || request->method == Http::METHOD_HEAD) {
1078  // XXX: initialize if we got here without HttpRequest::parseHeader()
1079  if (!request->range)
1080  request->range = req_hdr->getRange();
1081 
1082  if (request->range) {
1083  request->flags.isRanged = true;
1085  /* XXX: This is suboptimal. We should give the stream the range set,
1086  * and thereby let the top of the stream set the offset when the
1087  * size becomes known. As it is, we will end up requesting from 0
1088  * for evey -X range specification.
1089  * RBC - this may be somewhat wrong. We should probably set the range
1090  * iter up at this point.
1091  */
1092  node->readBuffer.offset = request->range->lowestOffset(0);
1093  http->range_iter.pos = request->range->begin();
1094  http->range_iter.end = request->range->end();
1095  http->range_iter.valid = true;
1096  }
1097  }
1098 
1099  /* Only HEAD and GET requests permit a Range or Request-Range header.
1100  * If these headers appear on any other type of request, delete them now.
1101  */
1102  else {
1103  req_hdr->delById(Http::HdrType::RANGE);
1105  request->ignoreRange("neither HEAD nor GET");
1106  }
1107 
1108  if (req_hdr->has(Http::HdrType::AUTHORIZATION))
1109  request->flags.auth = true;
1110 
1111  clientCheckPinning(http);
1112 
1113  if (!request->url.userInfo().isEmpty())
1114  request->flags.auth = true;
1115 
1116  if (req_hdr->has(Http::HdrType::VIA)) {
1117  String s = req_hdr->getList(Http::HdrType::VIA);
1118  /*
1119  * ThisCache cannot be a member of Via header, "1.1 ThisCache" can.
1120  * Note ThisCache2 has a space prepended to the hostname so we don't
1121  * accidentally match super-domains.
1122  */
1123 
1124  if (strListIsSubstr(&s, ThisCache2, ',')) {
1125  debugObj(33, 1, "WARNING: Forwarding loop detected for:\n",
1126  request, (ObjPackMethod) & httpRequestPack);
1127  request->flags.loopDetected = true;
1128  }
1129 
1130 #if USE_FORW_VIA_DB
1131  fvdbCountVia(s.termedBuf());
1132 
1133 #endif
1134 
1135  s.clean();
1136  }
1137 
1138 #if USE_FORW_VIA_DB
1139 
1140  if (req_hdr->has(Http::HdrType::X_FORWARDED_FOR)) {
1142  fvdbCountForw(s.termedBuf());
1143  s.clean();
1144  }
1145 
1146 #endif
1147 
1148  request->flags.cachable = http->request->maybeCacheable();
1149 
1150  if (clientHierarchical(http))
1151  request->flags.hierarchical = true;
1152 
1153  debugs(85, 5, "clientInterpretRequestHeaders: REQ_NOCACHE = " <<
1154  (request->flags.noCache ? "SET" : "NOT SET"));
1155  debugs(85, 5, "clientInterpretRequestHeaders: REQ_CACHABLE = " <<
1156  (request->flags.cachable ? "SET" : "NOT SET"));
1157  debugs(85, 5, "clientInterpretRequestHeaders: REQ_HIERARCHICAL = " <<
1158  (request->flags.hierarchical ? "SET" : "NOT SET"));
1159 
1160 }
1161 
1162 void
1164 {
1165  ClientRequestContext *calloutContext = (ClientRequestContext *)data;
1166 
1167  if (!calloutContext->httpStateIsValid())
1168  return;
1169 
1170  calloutContext->clientRedirectDone(result);
1171 }
1172 
1173 void
1175 {
1176  ClientRequestContext *calloutContext = (ClientRequestContext *)data;
1177 
1178  if (!calloutContext->httpStateIsValid())
1179  return;
1180 
1181  calloutContext->clientStoreIdDone(result);
1182 }
1183 
1184 void
1186 {
1187  HttpRequest *old_request = http->request;
1188  debugs(85, 5, HERE << "'" << http->uri << "' result=" << reply);
1191 
1192  // Put helper response Notes into the transaction state record (ALE) eventually
1193  // do it early to ensure that no matter what the outcome the notes are present.
1194  if (http->al)
1195  http->al->syncNotes(old_request);
1196 
1197  UpdateRequestNotes(http->getConn(), *old_request, reply.notes);
1198 
1199  switch (reply.result) {
1200  case Helper::TimedOut:
1203  debugs(85, DBG_IMPORTANT, "ERROR: URL rewrite helper: Timedout");
1204  }
1205  break;
1206 
1207  case Helper::Unknown:
1208  case Helper::TT:
1209  // Handler in redirect.cc should have already mapped Unknown
1210  // IF it contained valid entry for the old URL-rewrite helper protocol
1211  debugs(85, DBG_IMPORTANT, "ERROR: URL rewrite helper returned invalid result code. Wrong helper? " << reply);
1212  break;
1213 
1214  case Helper::BrokenHelper:
1215  debugs(85, DBG_IMPORTANT, "ERROR: URL rewrite helper: " << reply);
1216  break;
1217 
1218  case Helper::Error:
1219  // no change to be done.
1220  break;
1221 
1222  case Helper::Okay: {
1223  // #1: redirect with a specific status code OK status=NNN url="..."
1224  // #2: redirect with a default status code OK url="..."
1225  // #3: re-write the URL OK rewrite-url="..."
1226 
1227  const char *statusNote = reply.notes.findFirst("status");
1228  const char *urlNote = reply.notes.findFirst("url");
1229 
1230  if (urlNote != NULL) {
1231  // HTTP protocol redirect to be done.
1232 
1233  // TODO: change default redirect status for appropriate requests
1234  // Squid defaults to 302 status for now for better compatibility with old clients.
1235  // HTTP/1.0 client should get 302 (Http::scFound)
1236  // HTTP/1.1 client contacting reverse-proxy should get 307 (Http::scTemporaryRedirect)
1237  // HTTP/1.1 client being diverted by forward-proxy should get 303 (Http::scSeeOther)
1239  if (statusNote != NULL) {
1240  const char * result = statusNote;
1241  status = static_cast<Http::StatusCode>(atoi(result));
1242  }
1243 
1244  if (status == Http::scMovedPermanently
1245  || status == Http::scFound
1246  || status == Http::scSeeOther
1247  || status == Http::scPermanentRedirect
1248  || status == Http::scTemporaryRedirect) {
1249  http->redirect.status = status;
1250  http->redirect.location = xstrdup(urlNote);
1251  // TODO: validate the URL produced here is RFC 2616 compliant absolute URI
1252  } else {
1253  debugs(85, DBG_CRITICAL, "ERROR: URL-rewrite produces invalid " << status << " redirect Location: " << urlNote);
1254  }
1255  } else {
1256  // URL-rewrite wanted. Ew.
1257  urlNote = reply.notes.findFirst("rewrite-url");
1258 
1259  // prevent broken helpers causing too much damage. If old URL == new URL skip the re-write.
1260  if (urlNote != NULL && strcmp(urlNote, http->uri)) {
1261  AnyP::Uri tmpUrl;
1262  if (tmpUrl.parse(old_request->method, urlNote)) {
1263  HttpRequest *new_request = old_request->clone();
1264  new_request->url = tmpUrl;
1265  debugs(61, 2, "URL-rewriter diverts URL from " << old_request->effectiveRequestUri() << " to " << new_request->effectiveRequestUri());
1266 
1267  // update the new request to flag the re-writing was done on it
1268  new_request->flags.redirected = true;
1269 
1270  // unlink bodypipe from the old request. Not needed there any longer.
1271  if (old_request->body_pipe != NULL) {
1272  old_request->body_pipe = NULL;
1273  debugs(61,2, HERE << "URL-rewriter diverts body_pipe " << new_request->body_pipe <<
1274  " from request " << old_request << " to " << new_request);
1275  }
1276 
1277  // update the current working ClientHttpRequest fields
1278  xfree(http->uri);
1279  http->uri = SBufToCstring(new_request->effectiveRequestUri());
1280  HTTPMSGUNLOCK(old_request);
1281  http->request = new_request;
1283  } else {
1284  debugs(85, DBG_CRITICAL, "ERROR: URL-rewrite produces invalid request: " <<
1285  old_request->method << " " << urlNote << " " << old_request->http_ver);
1286  }
1287  }
1288  }
1289  }
1290  break;
1291  }
1292 
1293  /* FIXME PIPELINE: This is innacurate during pipelining */
1294 
1297 
1298  assert(http->uri);
1299 
1300  http->doCallouts();
1301 }
1302 
1306 void
1308 {
1309  HttpRequest *old_request = http->request;
1310  debugs(85, 5, "'" << http->uri << "' result=" << reply);
1313 
1314  // Put helper response Notes into the transaction state record (ALE) eventually
1315  // do it early to ensure that no matter what the outcome the notes are present.
1316  if (http->al)
1317  http->al->syncNotes(old_request);
1318 
1319  UpdateRequestNotes(http->getConn(), *old_request, reply.notes);
1320 
1321  switch (reply.result) {
1322  case Helper::Unknown:
1323  case Helper::TT:
1324  // Handler in redirect.cc should have already mapped Unknown
1325  // IF it contained valid entry for the old helper protocol
1326  debugs(85, DBG_IMPORTANT, "ERROR: storeID helper returned invalid result code. Wrong helper? " << reply);
1327  break;
1328 
1329  case Helper::TimedOut:
1330  // Timeouts for storeID are not implemented
1331  case Helper::BrokenHelper:
1332  debugs(85, DBG_IMPORTANT, "ERROR: storeID helper: " << reply);
1333  break;
1334 
1335  case Helper::Error:
1336  // no change to be done.
1337  break;
1338 
1339  case Helper::Okay: {
1340  const char *urlNote = reply.notes.findFirst("store-id");
1341 
1342  // prevent broken helpers causing too much damage. If old URL == new URL skip the re-write.
1343  if (urlNote != NULL && strcmp(urlNote, http->uri) ) {
1344  // Debug section required for some very specific cases.
1345  debugs(85, 9, "Setting storeID with: " << urlNote );
1346  http->request->store_id = urlNote;
1347  http->store_id = urlNote;
1348  }
1349  }
1350  break;
1351  }
1352 
1353  http->doCallouts();
1354 }
1355 
1359 void
1361 {
1362  if (Config.accessList.noCache) {
1365  } else {
1366  /* unless otherwise specified, we try to cache. */
1368  }
1369 }
1370 
1371 static void
1373 {
1374  ClientRequestContext *calloutContext = (ClientRequestContext *) data;
1375 
1376  if (!calloutContext->httpStateIsValid())
1377  return;
1378 
1379  calloutContext->checkNoCacheDone(answer);
1380 }
1381 
1382 void
1384 {
1385  acl_checklist = NULL;
1386  if (answer.denied()) {
1387  http->request->flags.noCache = true; // do not read reply from cache
1388  http->request->flags.cachable = false; // do not store reply into cache
1389  }
1390  http->doCallouts();
1391 }
1392 
1393 #if USE_OPENSSL
1394 bool
1396 {
1397  if (!http->getConn()) {
1398  http->al->ssl.bumpMode = Ssl::bumpEnd; // SslBump does not apply; log -
1399  return false;
1400  }
1401 
1403  if (http->request->flags.forceTunnel) {
1404  debugs(85, 5, "not needed; already decided to tunnel " << http->getConn());
1405  if (bumpMode != Ssl::bumpEnd)
1406  http->al->ssl.bumpMode = bumpMode; // inherited from bumped connection
1407  return false;
1408  }
1409 
1410  // If SSL connection tunneling or bumping decision has been made, obey it.
1411  if (bumpMode != Ssl::bumpEnd) {
1412  debugs(85, 5, HERE << "SslBump already decided (" << bumpMode <<
1413  "), " << "ignoring ssl_bump for " << http->getConn());
1414 
1415  // We need the following "if" for transparently bumped TLS connection,
1416  // because in this case we are running ssl_bump access list before
1417  // the doCallouts runs. It can be removed after the bug #4340 fixed.
1418  // We do not want to proceed to bumping steps:
1419  // - if the TLS connection with the client is already established
1420  // because we are accepting normal HTTP requests on TLS port,
1421  // or because of the client-first bumping mode
1422  // - When the bumping is already started
1423  if (!http->getConn()->switchedToHttps() &&
1424  !http->getConn()->serverBump())
1425  http->sslBumpNeed(bumpMode); // for processRequest() to bump if needed and not already bumped
1426  http->al->ssl.bumpMode = bumpMode; // inherited from bumped connection
1427  return false;
1428  }
1429 
1430  // If we have not decided yet, decide whether to bump now.
1431 
1432  // Bumping here can only start with a CONNECT request on a bumping port
1433  // (bumping of intercepted SSL conns is decided before we get 1st request).
1434  // We also do not bump redirected CONNECT requests.
1437  !http->getConn()->port->flags.tunnelSslBumping) {
1438  http->al->ssl.bumpMode = Ssl::bumpEnd; // SslBump does not apply; log -
1439  debugs(85, 5, HERE << "cannot SslBump this request");
1440  return false;
1441  }
1442 
1443  // Do not bump during authentication: clients would not proxy-authenticate
1444  // if we delay a 407 response and respond with 200 OK to CONNECT.
1446  http->al->ssl.bumpMode = Ssl::bumpEnd; // SslBump does not apply; log -
1447  debugs(85, 5, HERE << "no SslBump during proxy authentication");
1448  return false;
1449  }
1450 
1451  if (error) {
1452  debugs(85, 5, "SslBump applies. Force bump action on error " << errorTypeName(error->type));
1455  return false;
1456  }
1457 
1458  debugs(85, 5, HERE << "SslBump possible, checking ACL");
1459 
1461  aclChecklist->nonBlockingCheck(sslBumpAccessCheckDoneWrapper, this);
1462  return true;
1463 }
1464 
1469 static void
1471 {
1472  ClientRequestContext *calloutContext = static_cast<ClientRequestContext *>(data);
1473 
1474  if (!calloutContext->httpStateIsValid())
1475  return;
1476  calloutContext->sslBumpAccessCheckDone(answer);
1477 }
1478 
1479 void
1481 {
1482  if (!httpStateIsValid())
1483  return;
1484 
1485  const Ssl::BumpMode bumpMode = answer.allowed() ?
1486  static_cast<Ssl::BumpMode>(answer.kind) : Ssl::bumpSplice;
1487  http->sslBumpNeed(bumpMode); // for processRequest() to bump if needed
1488  http->al->ssl.bumpMode = bumpMode; // for logging
1489 
1490  if (bumpMode == Ssl::bumpTerminate) {
1492  if (Comm::IsConnOpen(clientConn)) {
1493  debugs(85, 3, "closing after Ssl::bumpTerminate ");
1494  clientConn->close();
1495  }
1496  return;
1497  }
1498 
1499  http->doCallouts();
1500 }
1501 #endif
1502 
1503 /*
1504  * Identify requests that do not go through the store and client side stream
1505  * and forward them to the appropriate location. All other requests, request
1506  * them.
1507  */
1508 void
1510 {
1511  debugs(85, 4, request->method << ' ' << uri);
1512 
1513  const bool untouchedConnect = request->method == Http::METHOD_CONNECT && !redirect.status;
1514 
1515 #if USE_OPENSSL
1516  if (untouchedConnect && sslBumpNeeded()) {
1518  sslBumpStart();
1519  return;
1520  }
1521 #endif
1522 
1523  if (untouchedConnect || request->flags.forceTunnel) {
1524  getConn()->stopReading(); // tunnels read for themselves
1525  tunnelStart(this);
1526  return;
1527  }
1528 
1529  httpStart();
1530 }
1531 
1532 void
1534 {
1537  debugs(85, 4, logType.c_str() << " for '" << uri << "'");
1538 
1539  /* no one should have touched this */
1540  assert(out.offset == 0);
1541  /* Use the Stream Luke */
1543  clientStreamRead(node, this, node->readBuffer);
1545 }
1546 
1547 #if USE_OPENSSL
1548 
1549 void
1551 {
1552  debugs(83, 3, HERE << "sslBump required: "<< Ssl::bumpMode(mode));
1553  sslBumpNeed_ = mode;
1554 }
1555 
1556 // called when comm_write has completed
1557 static void
1558 SslBumpEstablish(const Comm::ConnectionPointer &, char *, size_t, Comm::Flag errflag, int, void *data)
1559 {
1560  ClientHttpRequest *r = static_cast<ClientHttpRequest*>(data);
1561  debugs(85, 5, HERE << "responded to CONNECT: " << r << " ? " << errflag);
1562 
1563  assert(r && cbdataReferenceValid(r));
1564  r->sslBumpEstablish(errflag);
1565 }
1566 
1567 void
1569 {
1570  // Bail out quickly on Comm::ERR_CLOSING - close handlers will tidy up
1571  if (errflag == Comm::ERR_CLOSING)
1572  return;
1573 
1574  if (errflag) {
1575  debugs(85, 3, HERE << "CONNECT response failure in SslBump: " << errflag);
1577  return;
1578  }
1579 
1580  // We lack HttpReply which logRequest() uses to log the status code.
1581  // TODO: Use HttpReply instead of the "200 Connection established" string.
1582  al->http.code = 200;
1583 
1584 #if USE_AUTH
1585  // Preserve authentication info for the ssl-bumped request
1586  if (request->auth_user_request != NULL)
1587  getConn()->setAuth(request->auth_user_request, "SSL-bumped CONNECT");
1588 #endif
1589 
1590  assert(sslBumpNeeded());
1592 }
1593 
1594 void
1596 {
1597  debugs(85, 5, HERE << "Confirming " << Ssl::bumpMode(sslBumpNeed_) <<
1598  "-bumped CONNECT tunnel on FD " << getConn()->clientConnection);
1600 
1601  AsyncCall::Pointer bumpCall = commCbCall(85, 5, "ClientSocketContext::sslBumpEstablish",
1603 
1605  CommIoCbParams &params = GetCommParams<CommIoCbParams>(bumpCall);
1606  params.flag = Comm::OK;
1607  params.conn = getConn()->clientConnection;
1608  ScheduleCallHere(bumpCall);
1609  return;
1610  }
1611 
1612  // send an HTTP 200 response to kick client SSL negotiation
1613  // TODO: Unify with tunnel.cc and add a Server(?) header
1614  static const char *const conn_established = "HTTP/1.1 200 Connection established\r\n\r\n";
1615  Comm::Write(getConn()->clientConnection, conn_established, strlen(conn_established), bumpCall, NULL);
1616 }
1617 
1618 #endif
1619 
1620 bool
1622 {
1624  int64_t contentLength =
1626  assert(contentLength >= 0);
1627 
1628  if (out.offset < contentLength)
1629  return false;
1630 
1631  return true;
1632 }
1633 
1634 void
1636 {
1637  entry_ = newEntry;
1638 }
1639 
1640 void
1642 {
1643  if (loggingEntry_)
1644  loggingEntry_->unlock("ClientHttpRequest::loggingEntry");
1645 
1646  loggingEntry_ = newEntry;
1647 
1648  if (loggingEntry_)
1649  loggingEntry_->lock("ClientHttpRequest::loggingEntry");
1650 }
1651 
1652 /*
1653  * doCallouts() - This function controls the order of "callout"
1654  * executions, including non-blocking access control checks, the
1655  * redirector, and ICAP. Previously, these callouts were chained
1656  * together such that "clientAccessCheckDone()" would call
1657  * "clientRedirectStart()" and so on.
1658  *
1659  * The ClientRequestContext (aka calloutContext) class holds certain
1660  * state data for the callout/callback operations. Previously
1661  * ClientHttpRequest would sort of hand off control to ClientRequestContext
1662  * for a short time. ClientRequestContext would then delete itself
1663  * and pass control back to ClientHttpRequest when all callouts
1664  * were finished.
1665  *
1666  * This caused some problems for ICAP because we want to make the
1667  * ICAP callout after checking ACLs, but before checking the no_cache
1668  * list. We can't stuff the ICAP state into the ClientRequestContext
1669  * class because we still need the ICAP state after ClientRequestContext
1670  * goes away.
1671  *
1672  * Note that ClientRequestContext is created before the first call
1673  * to doCallouts().
1674  *
1675  * If one of the callouts notices that ClientHttpRequest is no
1676  * longer valid, it should call cbdataReferenceDone() so that
1677  * ClientHttpRequest's reference count goes to zero and it will get
1678  * deleted. ClientHttpRequest will then delete ClientRequestContext.
1679  *
1680  * Note that we set the _done flags here before actually starting
1681  * the callout. This is strictly for convenience.
1682  */
1683 
1686 
1687 void
1689 {
1691 
1692  auto &ale = calloutContext->http->al;
1693  /*Save the original request for logging purposes*/
1694  if (!ale->request) {
1695  ale->request = request;
1696  HTTPMSGLOCK(ale->request);
1697 
1698  // Make the previously set client connection ID available as annotation.
1699  if (ConnStateData *csd = calloutContext->http->getConn()) {
1700  if (!csd->notes()->empty())
1701  calloutContext->http->request->notes()->appendNewOnly(csd->notes().getRaw());
1702  }
1703  ale->syncNotes(calloutContext->http->request);
1704  }
1705 
1706  if (!calloutContext->error) {
1707  // CVE-2009-0801: verify the Host: header is consistent with other known details.
1709  debugs(83, 3, HERE << "Doing calloutContext->hostHeaderVerify()");
1712  return;
1713  }
1714 
1716  debugs(83, 3, HERE << "Doing calloutContext->clientAccessCheck()");
1719  return;
1720  }
1721 
1722 #if USE_ADAPTATION
1727  request, NULL, calloutContext->http->al, this))
1728  return; // will call callback
1729  }
1730 #endif
1731 
1732  if (!calloutContext->redirect_done) {
1733  calloutContext->redirect_done = true;
1734 
1735  if (Config.Program.redirect) {
1736  debugs(83, 3, HERE << "Doing calloutContext->clientRedirectStart()");
1739  return;
1740  }
1741  }
1742 
1744  debugs(83, 3, HERE << "Doing calloutContext->clientAccessCheck2()");
1747  return;
1748  }
1749 
1750  if (!calloutContext->store_id_done) {
1751  calloutContext->store_id_done = true;
1752 
1753  if (Config.Program.store_id) {
1754  debugs(83, 3,"Doing calloutContext->clientStoreIdStart()");
1757  return;
1758  }
1759  }
1760 
1762  debugs(83, 3, HERE << "Doing clientInterpretRequestHeaders()");
1765  }
1766 
1767  if (!calloutContext->no_cache_done) {
1768  calloutContext->no_cache_done = true;
1769 
1771  debugs(83, 3, HERE << "Doing calloutContext->checkNoCache()");
1773  return;
1774  }
1775  }
1776  } // if !calloutContext->error
1777 
1778  // Set appropriate MARKs and CONNMARKs if needed.
1780  ACLFilledChecklist ch(nullptr, request, nullptr);
1781  ch.al = calloutContext->http->al;
1783  ch.my_addr = request->my_addr;
1784  ch.syncAle(request, log_uri);
1785 
1788  tos_t tos = aclMapTOS(Ip::Qos::TheConfig.tosToClient, &ch);
1789  if (tos)
1791 
1792  const auto packetMark = aclFindNfMarkConfig(Ip::Qos::TheConfig.nfmarkToClient, &ch);
1793  if (!packetMark.isEmpty())
1794  Ip::Qos::setSockNfmark(getConn()->clientConnection, packetMark.mark);
1795 
1796  const auto connmark = aclFindNfMarkConfig(Ip::Qos::TheConfig.nfConnmarkToClient, &ch);
1797  if (!connmark.isEmpty())
1799  }
1800  }
1801 
1802 #if USE_OPENSSL
1803  // Even with calloutContext->error, we call sslBumpAccessCheck() to decide
1804  // whether SslBump applies to this transaction. If it applies, we will
1805  // attempt to bump the client to serve the error.
1809  return;
1810  /* else no ssl bump required*/
1811  }
1812 #endif
1813 
1814  if (calloutContext->error) {
1815  // XXX: prformance regression. c_str() reallocates
1816  SBuf storeUriBuf(request->storeId());
1817  const char *storeUri = storeUriBuf.c_str();
1818  StoreEntry *e = storeCreateEntry(storeUri, storeUri, request->flags, request->method);
1819 #if USE_OPENSSL
1820  if (sslBumpNeeded()) {
1821  // We have to serve an error, so bump the client first.
1823  // set final error but delay sending until we bump
1827  getConn()->setServerBump(srvBump);
1828  e->unlock("ClientHttpRequest::doCallouts+sslBumpNeeded");
1829  } else
1830 #endif
1831  {
1832  // send the error to the client now
1834  clientReplyContext *repContext = dynamic_cast<clientReplyContext *>(node->data.getRaw());
1835  assert (repContext);
1836  repContext->setReplyToStoreEntry(e, "immediate SslBump error");
1840  getConn()->flags.readMore = true; // resume any pipeline reads.
1842  clientStreamRead(node, this, node->readBuffer);
1843  e->unlock("ClientHttpRequest::doCallouts-sslBumpNeeded");
1844  return;
1845  }
1846  }
1847 
1849  delete calloutContext;
1850  calloutContext = NULL;
1851 #if HEADERS_LOG
1852 
1853  headersLog(0, 1, request->method, request);
1854 #endif
1855 
1856  debugs(83, 3, HERE << "calling processRequest()");
1857  processRequest();
1858 
1859 #if ICAP_CLIENT
1861  if (ih != NULL)
1862  ih->logType = logType;
1863 #endif
1864 }
1865 
1866 #if USE_ADAPTATION
1867 void
1870 {
1871  debugs(85, 3, HERE << "adaptation needed for " << this);
1875  new Adaptation::Iterator(request, NULL, al, g));
1876 
1877  // we could try to guess whether we can bypass this adaptation
1878  // initiation failure, but it should not really happen
1880 }
1881 
1882 void
1884 {
1885  assert(cbdataReferenceValid(this)); // indicates bug
1888 
1889  switch (answer.kind) {
1891  handleAdaptedHeader(const_cast<Http::Message*>(answer.message.getRaw()));
1892  break;
1893 
1895  handleAdaptationBlock(answer);
1896  break;
1897 
1900  break;
1901  }
1902 }
1903 
1904 void
1906 {
1907  assert(msg);
1908 
1909  if (HttpRequest *new_req = dynamic_cast<HttpRequest*>(msg)) {
1910  /*
1911  * Replace the old request with the new request.
1912  */
1914  request = new_req;
1916 
1917  // update the new message to flag whether URL re-writing was done on it
1918  if (request->effectiveRequestUri().cmp(uri) != 0)
1919  request->flags.redirected = 1;
1920 
1921  /*
1922  * Store the new URI for logging
1923  */
1924  xfree(uri);
1927  assert(request->method.id());
1928  } else if (HttpReply *new_rep = dynamic_cast<HttpReply*>(msg)) {
1929  debugs(85,3,HERE << "REQMOD reply is HTTP reply");
1930 
1931  // subscribe to receive reply body
1932  if (new_rep->body_pipe != NULL) {
1933  adaptedBodySource = new_rep->body_pipe;
1934  int consumer_ok = adaptedBodySource->setConsumerIfNotLate(this);
1935  assert(consumer_ok);
1936  }
1937 
1939  clientReplyContext *repContext = dynamic_cast<clientReplyContext *>(node->data.getRaw());
1940  assert(repContext);
1941  repContext->createStoreEntry(request->method, request->flags);
1942 
1945  storeEntry()->replaceHttpReply(new_rep);
1947 
1948  if (!adaptedBodySource) // no body
1949  storeEntry()->complete();
1950  clientGetMoreData(node, this);
1951  }
1952 
1953  // we are done with getting headers (but may be receiving body)
1955 
1957  doCallouts();
1958 }
1959 
1960 void
1962 {
1964  AclMatchedName = answer.ruleId.termedBuf();
1967  AclMatchedName = NULL;
1968 }
1969 
1970 void
1972 {
1973  if (!adaptedBodySource)
1974  return;
1975 
1977 }
1978 
1979 void
1981 {
1984 
1985  if (size_t contentSize = adaptedBodySource->buf().contentSize()) {
1986  const size_t spaceAvailable = storeEntry()->bytesWanted(Range<size_t>(0,contentSize));
1987 
1988  if (spaceAvailable < contentSize ) {
1989  // No or partial body data consuming
1990  typedef NullaryMemFunT<ClientHttpRequest> Dialer;
1991  AsyncCall::Pointer call = asyncCall(93, 5, "ClientHttpRequest::resumeBodyStorage",
1992  Dialer(this, &ClientHttpRequest::resumeBodyStorage));
1993  storeEntry()->deferProducer(call);
1994  }
1995 
1996  if (!spaceAvailable)
1997  return;
1998 
1999  if (spaceAvailable < contentSize )
2000  contentSize = spaceAvailable;
2001 
2003  const StoreIOBuffer ioBuf(&bpc.buf, request_satisfaction_offset, contentSize);
2004  storeEntry()->write(ioBuf);
2005  // assume StoreEntry::write() writes the entire ioBuf
2007  bpc.buf.consume(contentSize);
2008  bpc.checkIn();
2009  }
2010 
2013  // else wait for more body data
2014 }
2015 
2016 void
2018 {
2020  // should we end request satisfaction now?
2023 }
2024 
2025 void
2027 {
2028  debugs(85,4, HERE << this << " ends request satisfaction");
2031 
2032  // TODO: anything else needed to end store entry formation correctly?
2033  storeEntry()->complete();
2034 }
2035 
2036 void
2038 {
2041 
2042  debugs(85,3, HERE << "REQMOD body production failed");
2043  if (request_satisfaction_mode) { // too late to recover or serve an error
2046  Must(Comm::IsConnOpen(c));
2047  c->close(); // drastic, but we may be writing a response already
2048  } else {
2050  }
2051 }
2052 
2053 void
2054 ClientHttpRequest::handleAdaptationFailure(int errDetail, bool bypassable)
2055 {
2056  debugs(85,3, HERE << "handleAdaptationFailure(" << bypassable << ")");
2057 
2058  const bool usedStore = storeEntry() && !storeEntry()->isEmpty();
2059  const bool usedPipe = request->body_pipe != NULL &&
2060  request->body_pipe->consumedSize() > 0;
2061 
2062  if (bypassable && !usedStore && !usedPipe) {
2063  debugs(85,3, HERE << "ICAP REQMOD callout failed, bypassing: " << calloutContext);
2064  if (calloutContext)
2065  doCallouts();
2066  return;
2067  }
2068 
2069  debugs(85,3, HERE << "ICAP REQMOD callout failed, responding with error");
2070 
2072  clientReplyContext *repContext = dynamic_cast<clientReplyContext *>(node->data.getRaw());
2073  assert(repContext);
2074 
2075  calloutsError(ERR_ICAP_FAILURE, errDetail);
2076 
2077  if (calloutContext)
2078  doCallouts();
2079 }
2080 
2081 void
2082 ClientHttpRequest::callException(const std::exception &ex)
2083 {
2084  if (const auto clientConn = getConn() ? getConn()->clientConnection : nullptr) {
2086  debugs(85, 3, "closing after exception: " << ex.what());
2087  clientConn->close(); // initiate orderly top-to-bottom cleanup
2088  return;
2089  }
2090  }
2091  debugs(85, DBG_IMPORTANT, "ClientHttpRequest exception without connection. Ignoring " << ex.what());
2092  // XXX: Normally, we mustStop() but we cannot do that here because it is
2093  // likely to leave Http::Stream and ConnStateData with a dangling http
2094  // pointer. See r13480 or XXX in Http::Stream class description.
2095 }
2096 #endif
2097 
2098 // XXX: modify and use with ClientRequestContext::clientAccessCheckDone too.
2099 void
2101 {
2102  // The original author of the code also wanted to pass an errno to
2103  // setReplyToError, but it seems unlikely that the errno reflects the
2104  // true cause of the error at this point, so I did not pass it.
2105  if (calloutContext) {
2106  Ip::Address noAddr;
2107  noAddr.setNoAddr();
2108  ConnStateData * c = getConn();
2110  NULL,
2111  c != NULL ? c->clientConnection->remote : noAddr,
2112  request
2113  );
2114 #if USE_AUTH
2116  c != NULL && c->getAuth() != NULL ? c->getAuth() : request->auth_user_request;
2117 #endif
2118  calloutContext->error->detailError(errDetail);
2120  if (c != NULL)
2121  c->expectNoForwarding();
2122  }
2123  //else if(calloutContext == NULL) is it possible?
2124 }
2125 
iterates services in ServiceGroup, starting adaptation launchers
Definition: Iterator.h:31
bool switchedToHttps() const
Definition: client_side.h:252
void recordLookup(const Dns::LookupDetails &detail)
Definition: HttpRequest.cc:586
int delById(Http::HdrType id)
Definition: HttpHeader.cc:672
void nonBlockingCheck(ACLCB *callback, void *callback_data)
Definition: Checklist.cc:238
summarizes adaptation service answer for the noteAdaptationAnswer() API
Definition: Answer.h:22
AnyP::ProtocolVersion ProtocolVersion(unsigned int aMajor, unsigned int aMinor)
HTTP version label information.
static void sslBumpAccessCheckDoneWrapper(allow_t, void *)
static void clientInterpretRequestHeaders(ClientHttpRequest *http)
int has(Http::HdrType id) const
Definition: HttpHeader.cc:1002
bool interceptTproxy
Set for requests handled by a "tproxy" port.
Definition: RequestFlags.h:68
void redirectStart(ClientHttpRequest *http, HLPCB *handler, void *data)
Definition: redirect.cc:288
err_type errType
Definition: HttpRequest.h:149
void setAuth(const Auth::UserRequest::Pointer &aur, const char *cause)
Definition: client_side.cc:502
#define fd_table
Definition: fde.h:157
Ssl::ServerBump * serverBump()
Definition: client_side.h:253
ConnStateData * pinnedConnection()
Definition: HttpRequest.cc:653
CbcPointer< Initiate > initiateAdaptation(Initiate *x)
< starts freshly created initiate and returns a safe pointer to it
Definition: Initiator.cc:23
SQUIDCEXTERN CSD clientReplyDetach
ClientHttpRequest * http
HttpHdrRange * range
Definition: HttpRequest.h:131
#define assert(EX)
Definition: assert.h:17
Ip::Address my_addr
Definition: HttpRequest.h:143
int matchDomainName(const char *h, const char *d, uint flags)
Definition: Uri.cc:660
void clientStreamInit(dlink_list *list, CSR *func, CSD *rdetach, CSS *readstatus, ClientStreamData readdata, CSCB *callback, CSD *cdetach, ClientStreamData callbackdata, StoreIOBuffer tailBuffer)
String ruleId
ACL (or similar rule) name that blocked forwarding.
Definition: Answer.h:40
static void checkFailureRatio(err_type, hier_code)
bool hierarchical
Definition: RequestFlags.h:34
int neighbors_do_private_keys
#define HttpHeaderInitPos
Definition: HttpHeader.h:48
ConnStateData * getConn() const
#define cbdataReferenceDone(var)
Definition: cbdata.h:350
static HLPCB clientRedirectDoneWrapper
wordlist * store_id
Definition: SquidConfig.h:191
void UpdateRequestNotes(ConnStateData *csd, HttpRequest &request, NotePairs const &helperNotes)
Definition: HttpRequest.cc:688
HttpHdrCc * cache_control
Definition: Message.h:76
int unlock(const char *context)
Definition: store.cc:460
struct SquidConfig::@100 Port
void fd_note(int fd, const char *s)
Definition: fd.cc:251
Ssl::BumpMode sslBumpNeed() const
returns raw sslBump mode value
struct ClientHttpRequest::Redirect redirect
bool loopDetected
Definition: RequestFlags.h:36
virtual void noteBodyProducerAborted(BodyPipe::Pointer)
Definition: Acl.h:113
bool timestampsSet()
Definition: store.cc:1472
Definition: SBuf.h:86
static uint32 B
Definition: md4.c:43
struct SquidConfig::@113 onoff
virtual void noteBodyProductionEnded(BodyPipe::Pointer)
#define xcalloc
Definition: membanger.c:57
#define REDIRECT_NONE
Definition: defines.h:87
Ip::Address src_addr
void checkNoCacheDone(const allow_t &answer)
Comm::ConnectionPointer clientConnection
int log_uses_indirect_client
Definition: SquidConfig.h:328
acl_access * redirector
Definition: SquidConfig.h:373
void consume(mb_size_t sz)
removes sz bytes and "packs" by moving content left
Definition: MemBuf.cc:171
ACLFilledChecklist * Filled(ACLChecklist *checklist)
convenience and safety wrapper for dynamic_cast<ACLFilledChecklist*>
HttpRequestMethod method
Definition: HttpRequest.h:102
void setLogUri(ClientHttpRequest *http, char const *uri, bool cleanUrl)
const MemBuf & buf() const
Definition: BodyPipe.h:137
#define SQUIDCEXTERN
Definition: squid.h:26
struct _request * request(char *urlin)
Definition: tcp-banger2.c:291
void error(char *format,...)
Http::MessagePointer message
HTTP request or response to forward.
Definition: Answer.h:39
bool initiated(const CbcPointer< AsyncJob > &job) const
Must(initiated(initiate)) instead of Must(initiate.set()), for clarity.
Definition: Initiator.h:52
int bumpMode
whether and how the request was SslBumped
#define xstrdup
ClientHttpRequest(ConnStateData *csd)
struct timeval start_time
The time the master transaction started.
void announceInitiatorAbort(CbcPointer< Initiate > &x)
inform the transaction about abnormal termination and clear the pointer
Definition: Initiator.cc:38
#define safe_free(x)
Definition: xalloc.h:73
bool exhausted() const
Definition: BodyPipe.cc:174
const char * bumpMode(int bm)
Definition: support.h:144
int64_t bodySize(const HttpRequestMethod &) const
Definition: HttpReply.cc:361
Definition: Flag.h:16
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)
AccessLogEntry::Pointer al
info for the future access.log, and external ACL
Definition: Range.h:18
static void hostHeaderIpVerifyWrapper(const ipcache_addrs *ia, const Dns::LookupDetails &dns, void *data)
encapsulates DNS lookup results
Definition: LookupDetails.h:20
void HTTPMSGLOCK(Http::Message *a)
Definition: Message.h:154
void calloutsError(const err_type error, const int errDetail)
Build an error reply. For use with the callouts.
void handleAdaptedHeader(Http::Message *msg)
void appendNewOnly(const NotePairs *src)
Definition: Notes.cc:349
#define Must(condition)
Like assert() but throws an exception instead of aborting the process.
Definition: TextException.h:69
HttpHeaderEntry * getEntry(HttpHeaderPos *pos) const
Definition: HttpHeader.cc:589
virtual void noteAdaptationAclCheckDone(Adaptation::ServiceGroupPointer group)
Comm::ConnectionPointer tcpClient
TCP/IP level details about the client connection.
AnyP::ProtocolVersion http_ver
Definition: Message.h:72
#define xisspace(x)
Definition: xis.h:17
HttpHdrRange * getRange() const
Definition: HttpHeader.cc:1263
#define DBG_CRITICAL
Definition: Debug.h:45
Auth::UserRequest::Pointer auth_user_request
Definition: errorpage.h:145
bool doneFollowXff() const
Definition: RequestFlags.h:121
char * p
Definition: membanger.c:43
wordlist * redirect
Definition: SquidConfig.h:190
int conn
the current server connection FD
Definition: Transport.cc:26
time_t ims
Definition: HttpRequest.h:133
bool done_follow_x_forwarded_for
Definition: RequestFlags.h:101
void clientStreamRead(clientStreamNode *thisObject, ClientHttpRequest *http, StoreIOBuffer readBuffer)
bool hostVerified
Definition: RequestFlags.h:66
void SBufToCstring(char *d, const SBuf &s)
Definition: SBuf.h:741
Ip::Address log_addr
Definition: client_side.h:127
struct timeval current_time
Definition: stub_time.cc:15
void startAdaptation(const Adaptation::ServiceGroupPointer &g)
Initiate an asynchronous adaptation transaction which will call us back.
int aclIsProxyAuth(const char *name)
Definition: Gadgets.cc:74
size_type size() const
Definition: SquidString.h:72
iterator end()
const SBuf storeId()
Definition: HttpRequest.cc:661
time_t squid_curtime
Definition: stub_time.cc:17
Comm::ConnectionPointer serverConnection
Definition: client_side.h:134
void replaceHttpReply(HttpReply *, bool andStartWriting=true)
Definition: store.cc:1800
no adapted message will come; see bypassable
Definition: Answer.h:29
bool readMore
needs comm_read (for this request or new requests)
Definition: client_side.h:130
uint64_t consumedSize() const
Definition: BodyPipe.h:111
a netfilter mark/mask pair
Definition: NfMarkConfig.h:20
int64_t lowestOffset(int64_t) const
HttpHdrRangeIter range_iter
bool connectionAuth
Definition: RequestFlags.h:78
AsyncCall * asyncCall(int aDebugSection, int aDebugLevel, const char *aName, const Dialer &aDialer)
Definition: AsyncCall.h:156
Helper::ResultCode result
The helper response 'result' field.
Definition: Reply.h:58
MemObject * memObject() const
virtual void complete()
Definition: store.cc:1076
unsigned char tos_t
Definition: forward.h:26
Http::HdrType id
Definition: HttpHeader.h:63
static const char *const conn_established
Definition: tunnel.cc:240
size_t appendDomainLen
Definition: SquidConfig.h:212
bool readNextRequest
whether Squid should read after error handling
void fvdbCountVia(const char *key)
int gopherCachable(const HttpRequest *req)
Definition: gopher.cc:294
NotePairs::Pointer notes()
Definition: HttpRequest.cc:680
ACLFilledChecklist * clientAclChecklistCreate(const acl_access *acl, ClientHttpRequest *http)
static const char *const crlf
bool setNfConnmark(Comm::ConnectionPointer &conn, const ConnectionDirection connDir, const NfMarkConfig &cm)
void setNoAddr()
Definition: Address.cc:285
void HLPCB(void *, const Helper::Reply &)
Definition: forward.h:27
Comm::ConnectionPointer conn
Definition: CommCalls.h:85
bool IsConnOpen(const Comm::ConnectionPointer &conn)
Definition: Connection.cc:24
acl_access * followXFF
Definition: SquidConfig.h:387
void const char HLPCB void * data
Definition: stub_helper.cc:16
NotePairs notes
Definition: Reply.h:61
int64_t offset
Definition: StoreIOBuffer.h:55
LogTags logType
the processing tags associated with this request transaction.
Definition: parse.c:104
iterator begin()
StatusCode
Definition: StatusCode.h:20
bool have(const Ip::Address &ip, size_t *position=nullptr) const
Definition: ipcache.cc:974
String store_id
Definition: HttpRequest.h:127
int64_t content_length
Definition: Message.h:83
void setConn(ConnStateData *aConn)
int reload_into_ims
Definition: SquidConfig.h:291
void port(unsigned short p)
Definition: Uri.h:80
struct SquidConfig::UrlHelperTimeout onUrlRewriteTimeout
#define debugs(SECTION, LEVEL, CONTENT)
Definition: Debug.h:124
#define cbdataReference(var)
Definition: cbdata.h:341
unsigned short defaultPort() const
Definition: UriScheme.cc:52
StoreEntry * storeCreateEntry(const char *url, const char *logUrl, const RequestFlags &flags, const HttpRequestMethod &method)
Definition: store.cc:794
void stopReading()
cancels Comm::Read() if it is scheduled
Definition: Server.cc:56
#define DBG_IMPORTANT
Definition: Debug.h:46
char const * rawBuf() const
Definition: SquidString.h:85
bool hasNoCache(const String **val=nullptr) const
Definition: HttpHdrCc.h:89
static void SslBumpEstablish(const Comm::ConnectionPointer &, char *, size_t, Comm::Flag errflag, int, void *data)
bool parse(const HttpRequestMethod &, const char *url)
Definition: Uri.cc:191
bool connectionAuthDisabled
Definition: RequestFlags.h:80
void expectNoForwarding()
cleans up virgin request [body] forwarding state
virtual HttpRequest * clone() const
Definition: HttpRequest.cc:175
Ip::Address client_addr
Definition: HttpRequest.h:137
void CSCB(clientStreamNode *, ClientHttpRequest *, HttpReply *, StoreIOBuffer)
client stream read callback
static void clientAccessCheckDoneWrapper(allow_t, void *)
bool connectionProxyAuth
Definition: RequestFlags.h:83
char const * termedBuf() const
Definition: SquidString.h:91
int kind
which custom access list verb matched
Definition: Acl.h:153
const char * c_str() const
compute the status access.log field
Definition: LogTags.cc:47
String getList(Http::HdrType id) const
Definition: HttpHeader.cc:819
bool onlyIfCached() const
StoreEntry * storeEntry() const
unsigned short icp
Definition: SquidConfig.h:131
const SBuf & effectiveRequestUri() const
RFC 7230 section 5.5 - Effective Request URI.
Definition: HttpRequest.cc:672
common parts of HttpRequest and HttpReply
Definition: Message.h:24
Config TheConfig
Globally available instance of Qos::Config.
Definition: QosConfig.cc:271
AnyP::Uri url
the request URI
Definition: HttpRequest.h:103
int strListIsSubstr(const String *list, const char *s, char del)
Definition: StrList.cc:54
void * addr
Definition: membanger.c:46
void handleAdaptationBlock(const Adaptation::Answer &answer)
void userInfo(const SBuf &s)
Definition: Uri.h:72
CbcPointer< ConnStateData > clientConnectionManager
Definition: HttpRequest.h:218
HttpRequest * request
bool allowed() const
Definition: Acl.h:141
AnyP::UriScheme const & getScheme() const
Definition: Uri.h:64
BodyPipe::Pointer adaptedBodySource
Http::StatusCode httpStatus
Definition: errorpage.h:143
bool setConsumerIfNotLate(const Consumer::Pointer &aConsumer)
Definition: BodyPipe.cc:228
Ip::NfMarkConfig aclFindNfMarkConfig(acl_nfmark *head, ACLChecklist *ch)
Checks for a netfilter mark value to apply depending on the ACL.
Definition: FwdState.cc:1284
const char * c_str()
Definition: SBuf.cc:526
bool conflicted() const
whether Squid is uncertain about the allowed() or denied() answer
Definition: Acl.h:150
ClientStreamData data
Definition: clientStream.h:94
AccessLogEntry::Pointer al
access.log entry
void ipcache_nbgethostbyname(const char *name, IPH *handler, void *handlerData)
Definition: ipcache.cc:600
void resumeBodyStorage()
called by StoreEntry when it has more buffer space available
const char * AclMatchedName
Definition: Acl.cc:30
class AccessLogEntry::HttpDetails http
void host(const char *src)
Definition: Uri.cc:47
bool update(HttpHeader const *fresh)
Definition: HttpHeader.cc:280
ClientRequestContext * calloutContext
static int port
Definition: ldap_backend.cc:69
void tunnelStart(ClientHttpRequest *)
Definition: tunnel.cc:1084
ErrorState * clientBuildError(err_type, Http::StatusCode, char const *url, Ip::Address &, HttpRequest *)
int hasListMember(Http::HdrType id, const char *member, const char separator) const
Definition: HttpHeader.cc:1665
void cut(size_type newLength)
Definition: String.cc:236
String x_forwarded_for_iterator
Definition: HttpRequest.h:176
Security::CertPointer sslClientCert
cert received from the client
struct ClientHttpRequest::Out out
static HttpRequest * FromUrl(const char *url, const MasterXaction::Pointer &, const HttpRequestMethod &method=Http::METHOD_GET)
Definition: HttpRequest.cc:522
void ignoreRange(const char *reason)
forgets about the cached Range header (for a reason)
Definition: HttpRequest.cc:627
acl_access * adapted_http
Definition: SquidConfig.h:356
std::ostream & HERE(std::ostream &s)
Definition: Debug.h:153
class AccessLogEntry::CacheDetails cache
ssize_t HttpHeaderPos
Definition: HttpHeader.h:45
static uint32 A
Definition: md4.c:43
void handleAdaptationFailure(int errDetail, bool bypassable=false)
class AccessLogEntry::SslDetails ssl
char const * denyMessage(char const *const default_message=NULL) const
Definition: UserRequest.cc:127
unsigned short port() const
Definition: Address.cc:771
#define FAILURE_MODE_TIME
acl_access * noCache
Definition: SquidConfig.h:362
mb_size_t contentSize() const
available data size
Definition: MemBuf.h:47
Flag
Definition: Flag.h:15
Ip::Address local
Definition: Connection.h:135
HttpHeader header
Definition: Message.h:74
bool accelerated
Definition: RequestFlags.h:60
Http::MethodType id() const
Definition: RequestMethod.h:73
bool final
whether the error, if any, cannot be bypassed
Definition: Answer.h:41
Ssl::BumpMode sslBumpNeed_
whether (and how) the request needs to be bumped
AclDenyInfoList * denyInfoList
Definition: SquidConfig.h:404
char rfc931[USER_IDENT_SZ]
Definition: Connection.h:165
struct SquidConfig::@105 Program
RequestFlags flags
Definition: HttpRequest.h:129
#define REDIRECT_DONE
Definition: defines.h:89
Adaptation::Icap::History::Pointer icapHistory() const
Returns possibly nil history, creating it if icap logging is enabled.
Definition: HttpRequest.cc:398
ClientRequestContext(ClientHttpRequest *)
bool maybeCacheable()
Definition: HttpRequest.cc:537
void setServerBump(Ssl::ServerBump *srvBump)
Definition: client_side.h:254
virtual void noteMoreBodyDataAvailable(BodyPipe::Pointer)
err_type type
Definition: errorpage.h:140
Ip::Address remote
Definition: Connection.h:138
void Comm::ConnectionPointer & clientConn
Definition: stub_tunnel.cc:19
hier_code
Definition: hier_code.h:12
#define ScheduleCallHere(call)
Definition: AsyncCall.h:166
void httpRequestPack(void *obj, Packable *p)
Definition: HttpRequest.cc:370
Definition: Uri.h:30
StoreEntry * loggingEntry_
int acl_uses_indirect_client
Definition: SquidConfig.h:326
virtual void write(StoreIOBuffer)
Definition: store.cc:815
bool intercepted
Definition: RequestFlags.h:64
bool sslBumpNeeded() const
returns true if and only if the request needs to be bumped
#define PROF_start(probename)
Definition: Profiler.h:62
StoreIOBuffer readBuffer
Definition: clientStream.h:95
bool isOpen() const
Definition: Connection.h:87
bool respMaybeCacheable() const
AnyP::PortCfgPointer port
Kind kind
the type of the answer
Definition: Answer.h:42
#define CBDATA_CLASS_INIT(type)
Definition: cbdata.h:318
void detailError(err_type aType, int aDetail)
sets error detail if no earlier detail was available
Definition: HttpRequest.cc:455
forward the supplied adapted HTTP message
Definition: Answer.h:27
struct ClientHttpRequest::Flags flags
Comm::Flag flag
comm layer result status.
Definition: CommCalls.h:87
CbcPointer< Adaptation::Initiate > virginHeadSource
struct SquidConfig::@114 accessList
double request_failure_ratio
bool denied() const
Definition: Acl.h:147
static void clientStoreIdAccessCheckDone(allow_t answer, void *data)
static int clientHierarchical(ClientHttpRequest *http)
block or deny the master xaction; see authority
Definition: Answer.h:28
void(* ObjPackMethod)(void *obj, Packable *p)
Definition: tools.h:33
struct ConnStateData::@39 flags
size_t HttpReply *STUB StoreEntry const KeyScope scope const HttpRequestMethod & method
Definition: stub_store.cc:126
static bool Start(Method method, VectPoint vp, HttpRequest *req, HttpReply *rep, AccessLogEntry::Pointer &al, Adaptation::Initiator *initiator)
Definition: AccessCheck.cc:30
void syncNotes(HttpRequest *request)
int cmp(const SBuf &S, const size_type n) const
shorthand version for compare()
Definition: SBuf.h:264
accepted (from a client by Squid)
Definition: QosConfig.h:67
ConnStateData * conn_
void stopConsumingFrom(RefCount< BodyPipe > &)
Definition: BodyPipe.cc:118
void storeIdStart(ClientHttpRequest *http, HLPCB *handler, void *data)
Definition: redirect.cc:314
Comm::ConnectionPointer clientConnection
Definition: Server.h:97
void hostHeaderIpVerify(const ipcache_addrs *ia, const Dns::LookupDetails &dns)
Auth::UserRequest::Pointer auth_user_request
Definition: HttpRequest.h:115
const char * errorTypeName(err_type err)
Definition: err_type.h:100
time_t getTime(Http::HdrType id) const
Definition: HttpHeader.cc:1186
int setSockNfmark(const Comm::ConnectionPointer &conn, nfmark_t mark)
Definition: QosConfig.cc:586
void errorAppendEntry(StoreEntry *entry, ErrorState *err)
Definition: errorpage.cc:575
clientStream_status_t CSS(clientStreamNode *, ClientHttpRequest *)
int hostStrictVerify
Definition: SquidConfig.h:337
BodyPipe::Pointer body_pipe
optional pipeline to receive message body
Definition: Message.h:97
CommCbFunPtrCallT< Dialer > * commCbCall(int debugSection, int debugLevel, const char *callName, const Dialer &dialer)
Definition: CommCalls.h:342
#define REDIRECT_PENDING
Definition: defines.h:88
int cbdataReferenceValid(const void *p)
Definition: cbdata.cc:412
HttpHdrRange::iterator end
void sslBumpEstablish(Comm::Flag errflag)
Ssl::BumpMode sslBumpMode
ssl_bump decision (Ssl::bumpEnd if n/a).
Definition: client_side.h:272
const HttpReplyPointer & getReply() const
Definition: MemObject.h:57
static void checkNoCacheDoneWrapper(allow_t, void *)
static void clientRedirectAccessCheckDone(allow_t answer, void *data)
void clientRedirectDone(const Helper::Reply &reply)
const char * getStr(Http::HdrType id) const
Definition: HttpHeader.cc:1203
void detailError(int dCode)
set error type-specific detail code
Definition: errorpage.h:97
virtual size_t bytesWanted(Range< size_t > const aRange, bool ignoreDelayPool=false) const
Definition: store.cc:227
time_t hit_only_mode_until
virtual void noteAdaptationAnswer(const Adaptation::Answer &answer)
void deferProducer(const AsyncCall::Pointer &producer)
call back producer when more buffer space is available
Definition: store.cc:351
static void clientCheckPinning(ClientHttpRequest *http)
void clean()
Definition: String.cc:125
void switchToHttps(HttpRequest *request, Ssl::BumpMode bumpServerMode)
BumpMode
Definition: support.h:130
#define PROF_stop(probename)
Definition: Profiler.h:63
ACLChecklist * acl_checklist
struct ConnStateData::@40 pinning
void sslBumpAccessCheckDone(const allow_t &answer)
The callback function for ssl-bump access check list.
int64_t strtoll(const char *nptr, char **endptr, int base)
Definition: strtoll.c:81
virtual bool isEmpty() const
Definition: Store.h:60
HttpHdrRange::iterator pos
void CSD(clientStreamNode *, ClientHttpRequest *)
client stream detach
void CSR(clientStreamNode *, ClientHttpRequest *)
client stream read
void clientAccessCheckDone(const allow_t &answer)
bool hasOnlyIfCached() const
Definition: HttpHdrCc.h:145
StoreEntry * loggingEntry() const
#define xfree
const char * findFirst(const char *noteKey) const
Definition: Notes.cc:265
SQUIDCEXTERN CSR clientGetMoreData
char * urlCanonicalClean(const HttpRequest *request)
Definition: Uri.cc:518
const char * sslGetUserEmail(SSL *ssl)
Definition: support.cc:686
int setSockTos(const Comm::ConnectionPointer &conn, tos_t tos)
Definition: QosConfig.cc:558
acl_access * http
Definition: SquidConfig.h:355
HierarchyLogEntry hier
static void clientFollowXForwardedForCheck(allow_t answer, void *data)
void httpRequestFree(void *data)
Definition: client_side.cc:487
static HLPCB clientStoreIdDoneWrapper
Ip::Address indirect_client_addr
Definition: HttpRequest.h:140
C * getRaw() const
Definition: RefCount.h:74
class SquidConfig Config
Definition: SquidConfig.cc:12
tos_t aclMapTOS(acl_tos *head, ACLChecklist *ch)
Checks for a TOS value to apply depending on the ACL.
Definition: FwdState.cc:1272
squidaio_request_t * head
Definition: aiops.cc:127
acl_access * ssl_bump
Definition: SquidConfig.h:384
#define NULL
Definition: types.h:166
const Auth::UserRequest::Pointer & getAuth() const
Definition: client_side.h:114
void hostHeaderVerifyFailed(const char *A, const char *B)
void HTTPMSGUNLOCK(Http::Message *a)
Definition: Message.h:144
SQUIDCEXTERN CSS clientReplyStatus
ErrorState * error
saved error page for centralized/delayed processing
void debugObj(int section, int level, const char *label, void *obj, ObjPackMethod pm)
Definition: tools.cc:900
int refresh_nocache_hack
#define false
Definition: GnuRegex.c:233
virtual void syncAle(HttpRequest *adaptedRequest, const char *logUri) const
assigns uninitialized adapted_request and url ALE components
void Write(const Comm::ConnectionPointer &conn, const char *buf, int size, AsyncCall::Pointer &callback, FREE *free_func)
Definition: Write.cc:35
void clientStoreIdDone(const Helper::Reply &reply)
err_type
Definition: err_type.h:12
err_type aclGetDenyInfoPage(AclDenyInfoList **head, const char *name, int redirect_allowed)
Definition: Gadgets.cc:40
MemBuf & buf
Definition: BodyPipe.h:74
bool forceTunnel
whether to forward via TunnelStateData (instead of FwdState)
Definition: RequestFlags.h:113
bool nocacheHack
Definition: RequestFlags.h:58
void fvdbCountForw(const char *key)
void clearAdaptation(CbcPointer< Initiate > &x)
clears the pointer (does not call announceInitiatorAbort)
Definition: Initiator.cc:32
char ThisCache2[RFC2181_MAXHOSTNAMELEN<< 1]
void lock(const char *context)
Definition: store.cc:435
virtual void callException(const std::exception &ex)
called when the job throws during an async call

 

Introduction

Documentation

Support

Miscellaneous

Web Site Translations

Mirrors