client_side_reply.cc
Go to the documentation of this file.
1 /*
2  * Copyright (C) 1996-2020 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 88 Client-side Reply Routines */
10 
11 #include "squid.h"
12 #include "acl/FilledChecklist.h"
13 #include "acl/Gadgets.h"
14 #include "anyp/PortCfg.h"
15 #include "client_side_reply.h"
16 #include "errorpage.h"
17 #include "ETag.h"
18 #include "fd.h"
19 #include "fde.h"
20 #include "format/Token.h"
21 #include "FwdState.h"
22 #include "globals.h"
23 #include "http/Stream.h"
24 #include "HttpHeaderTools.h"
25 #include "HttpReply.h"
26 #include "HttpRequest.h"
27 #include "ip/QosConfig.h"
28 #include "ipcache.h"
29 #include "log/access_log.h"
30 #include "MemObject.h"
31 #include "mime_header.h"
32 #include "neighbors.h"
33 #include "refresh.h"
34 #include "RequestFlags.h"
35 #include "SquidConfig.h"
36 #include "SquidTime.h"
37 #include "Store.h"
38 #include "StrList.h"
39 #include "tools.h"
40 #if USE_AUTH
41 #include "auth/UserRequest.h"
42 #endif
43 #if USE_DELAY_POOLS
44 #include "DelayPools.h"
45 #endif
46 #if USE_SQUID_ESI
47 #include "esi/Esi.h"
48 #endif
49 
50 #include <memory>
51 
53 
54 /* Local functions */
57 
58 /* privates */
59 
61 {
62  deleting = true;
63  /* This may trigger a callback back into SendMoreData as the cbdata
64  * is still valid
65  */
67  /* old_entry might still be set if we didn't yet get the reply
68  * code in HandleIMSReply() */
73 }
74 
76  purgeStatus(Http::scNone),
77  lookingforstore(0),
78  http(cbdataReference(clientContext)),
79  headers_sz(0),
80  sc(NULL),
81  old_reqsize(0),
82  reqsize(0),
83  reqofs(0),
84 #if USE_CACHE_DIGESTS
85  lookup_type(NULL),
86 #endif
87  ourNode(NULL),
88  reply(NULL),
89  old_entry(NULL),
90  old_sc(NULL),
91  old_lastmod(-1),
92  deleting(false),
93  collapsedRevalidation(crNone)
94 {
95  *tempbuf = 0;
96 }
97 
103 void
105  err_type err, Http::StatusCode status, const HttpRequestMethod& method, char const *uri,
106  Ip::Address &addr, HttpRequest * failedrequest, const char *unparsedrequest,
107 #if USE_AUTH
108  Auth::UserRequest::Pointer auth_user_request
109 #else
110  void*
111 #endif
112 )
113 {
114  auto errstate = clientBuildError(err, status, uri, addr, failedrequest, http->al);
115 
116  if (unparsedrequest)
117  errstate->request_hdrs = xstrdup(unparsedrequest);
118 
119 #if USE_AUTH
120  errstate->auth_user_request = auth_user_request;
121 #endif
122  setReplyToError(method, errstate);
123 }
124 
126 {
127  if (errstate->httpStatus == Http::scNotImplemented && http->request)
128  /* prevent confusion over whether we default to persistent or not */
129  http->request->flags.proxyKeepalive = false;
130 
131  http->al->http.code = errstate->httpStatus;
132 
133  if (http->request)
134  http->request->ignoreRange("responding with a Squid-generated error");
135 
137  assert(errstate->callback_data == NULL);
138  errorAppendEntry(http->storeEntry(), errstate);
139  /* Now the caller reads to get this */
140 }
141 
142 void
144 {
145  Must(futureReply);
146  http->al->http.code = futureReply->sline.status();
147 
149  if (http->request) { // nil on responses to unparsable requests
150  http->request->ignoreRange("responding with a Squid-generated reply");
152  }
153 
155 
156  http->storeEntry()->storeErrorResponse(futureReply);
157  /* Now the caller reads to get futureReply */
158 }
159 
160 // Assumes that the entry contains an error response without Content-Range.
161 // To use with regular entries, make HTTP Range header removal conditional.
162 void clientReplyContext::setReplyToStoreEntry(StoreEntry *entry, const char *reason)
163 {
164  entry->lock("clientReplyContext::setReplyToStoreEntry"); // removeClientStoreReference() unlocks
165  sc = storeClientListAdd(entry, this);
166 #if USE_DELAY_POOLS
168 #endif
169  reqofs = 0;
170  reqsize = 0;
171  if (http->request)
172  http->request->ignoreRange(reason);
174  http->storeEntry(entry);
175 }
176 
177 void
179  StoreEntry ** ep)
180 {
181  StoreEntry *e;
182  store_client *sc_tmp = *scp;
183 
184  if ((e = *ep) != NULL) {
185  *ep = NULL;
186  storeUnregister(sc_tmp, e, this);
187  *scp = NULL;
188  e->unlock("clientReplyContext::removeStoreReference");
189  }
190 }
191 
192 void
194 {
195  StoreEntry *reference = aHttpRequest->storeEntry();
196  removeStoreReference(scp, &reference);
197  aHttpRequest->storeEntry(reference);
198 }
199 
200 void
202 {
203  assert(old_sc == NULL);
204  debugs(88, 3, "clientReplyContext::saveState: saving store context");
206  old_sc = sc;
211  /* Prevent accessing the now saved entries */
212  http->storeEntry(NULL);
213  sc = NULL;
214  reqsize = 0;
215  reqofs = 0;
216 }
217 
218 void
220 {
221  assert(old_sc != NULL);
222  debugs(88, 3, "clientReplyContext::restoreState: Restoring store context");
225  sc = old_sc;
230  /* Prevent accessed the old saved entries */
231  old_entry = NULL;
232  old_sc = NULL;
233  old_lastmod = -1;
234  old_etag.clean();
235  old_reqsize = 0;
236  tempBuffer.offset = 0;
237 }
238 
239 void
241 {
245 }
246 
249 {
250  return (clientStreamNode *)ourNode->node.next->data;
251 }
252 
253 /* This function is wrong - the client parameters don't include the
254  * header offset
255  */
256 void
258 {
259  /* when confident, 0 becomes reqofs, and then this factors into
260  * startSendProcess
261  */
262  assert(reqofs == 0);
263  StoreIOBuffer localTempBuffer (next()->readBuffer.length, 0, next()->readBuffer.data);
264  storeClientCopy(sc, http->storeEntry(), localTempBuffer, SendMoreData, this);
265 }
266 
267 /* there is an expired entry in the store.
268  * setup a temporary buffer area and perform an IMS to the origin
269  */
270 void
272 {
273  const char *url = storeId();
274  debugs(88, 3, "clientReplyContext::processExpired: '" << http->uri << "'");
275  const time_t lastmod = http->storeEntry()->lastModified();
276  assert(lastmod >= 0);
277  /*
278  * check if we are allowed to contact other servers
279  * @?@: Instead of a 504 (Gateway Timeout) reply, we may want to return
280  * a stale entry *if* it matches client requirements
281  */
282 
283  if (http->onlyIfCached()) {
285  return;
286  }
287 
289  http->request->flags.refresh = true;
290 #if STORE_CLIENT_LIST_DEBUG
291  /* Prevent a race with the store client memory free routines
292  */
294 #endif
295  /* Prepare to make a new temporary request */
296  saveState();
297 
298  // TODO: Consider also allowing regular (non-collapsed) revalidation hits.
299  // TODO: support collapsed revalidation for Vary-controlled entries
300  bool collapsingAllowed = Config.onoff.collapsed_forwarding &&
303 
304  StoreEntry *entry = nullptr;
305  if (collapsingAllowed) {
306  if (const auto e = storeGetPublicByRequest(http->request, ksRevalidation)) {
307  if (e->hittingRequiresCollapsing() && startCollapsingOn(*e, true)) {
308  entry = e;
309  entry->lock("clientReplyContext::processExpired#alreadyRevalidating");
310  } else {
311  e->abandon(__FUNCTION__);
312  // assume mayInitiateCollapsing() would fail too
313  collapsingAllowed = false;
314  }
315  }
316  }
317 
318  if (entry) {
319  entry->ensureMemObject(url, http->log_uri, http->request->method);
320  debugs(88, 5, "collapsed on existing revalidation entry: " << *entry);
322  } else {
323  entry = storeCreateEntry(url,
325  /* NOTE, don't call StoreEntry->lock(), storeCreateEntry() does it */
326 
327  if (collapsingAllowed && mayInitiateCollapsing() &&
328  Store::Root().allowCollapsing(entry, http->request->flags, http->request->method)) {
329  debugs(88, 5, "allow other revalidation requests to collapse on " << *entry);
331  } else {
333  }
334  }
335 
336  sc = storeClientListAdd(entry, this);
337 #if USE_DELAY_POOLS
338  /* delay_id is already set on original store client */
340 #endif
341 
342  http->request->lastmod = lastmod;
343 
345  ETag etag = {NULL, -1}; // TODO: make that a default ETag constructor
346  if (old_entry->hasEtag(etag) && !etag.weak)
347  http->request->etag = etag.str;
348  }
349 
350  debugs(88, 5, "lastmod " << entry->lastModified());
351  http->storeEntry(entry);
352  assert(http->out.offset == 0);
354 
356  /*
357  * A refcounted pointer so that FwdState stays around as long as
358  * this clientReplyContext does
359  */
362  }
363  /* Register with storage manager to receive updates when data comes in. */
364 
365  if (EBIT_TEST(entry->flags, ENTRY_ABORTED))
366  debugs(88, DBG_CRITICAL, "clientReplyContext::processExpired: Found ENTRY_ABORTED object");
367 
368  {
369  /* start counting the length from 0 */
370  StoreIOBuffer localTempBuffer(HTTP_REQBUF_SZ, 0, tempbuf);
371  storeClientCopy(sc, entry, localTempBuffer, HandleIMSReply, this);
372  }
373 }
374 
375 void
377 {
378  StoreIOBuffer tempresult;
380  /* here the data to send is the data we just received */
381  tempBuffer.offset = 0;
382  old_reqsize = 0;
383  /* sendMoreData tracks the offset as well.
384  * Force it back to zero */
385  reqofs = 0;
387  /* TODO: provide sendMoreData with the ready parsed reply */
388  tempresult.length = reqsize;
389  tempresult.data = tempbuf;
390  sendMoreData(tempresult);
391 }
392 
393 void
395 {
397  context->handleIMSReply(result);
398 }
399 
400 void
402 {
403  /* Get the old request back */
404  restoreState();
405  /* here the data to send is in the next nodes buffers already */
407  /* sendMoreData tracks the offset as well.
408  * Force it back to zero */
409  reqofs = 0;
410  StoreIOBuffer tempresult (reqsize, reqofs, next()->readBuffer.data);
411  sendMoreData(tempresult);
412 }
413 
414 /* This is the workhorse of the HandleIMSReply callback.
415  *
416  * It is called when we've got data back from the origin following our
417  * IMS request to revalidate a stale entry.
418  */
419 void
421 {
422  if (deleting)
423  return;
424 
425  debugs(88, 3, http->storeEntry()->url() << ", " << (long unsigned) result.length << " bytes");
426 
427  if (http->storeEntry() == NULL)
428  return;
429 
430  if (result.flags.error && !EBIT_TEST(http->storeEntry()->flags, ENTRY_ABORTED))
431  return;
432 
434  debugs(88, 3, "CF slave hit private non-shareable " << *http->storeEntry() << ". MISS");
435  // restore context to meet processMiss() expectations
436  restoreState();
438  processMiss();
439  return;
440  }
441 
442  /* update size of the request */
443  reqsize = result.length + reqofs;
444 
445  // request to origin was aborted
447  debugs(88, 3, "request to origin aborted '" << http->storeEntry()->url() << "', sending old entry to client");
450  }
451 
452  const auto oldStatus = old_entry->mem().freshestReply().sline.status();
453  const auto &new_rep = http->storeEntry()->mem().freshestReply();
454  const auto status = new_rep.sline.status();
455 
456  // origin replied 304
457  if (status == Http::scNotModified) {
459  http->request->flags.staleIfHit = false; // old_entry is no longer stale
460 
461  // TODO: The update may not be instantaneous. Should we wait for its
462  // completion to avoid spawning too much client-disassociated work?
464 
465  // if client sent IMS
466 
468  // forward the 304 from origin
469  debugs(88, 3, "origin replied 304, revalidating existing entry and forwarding 304 to client");
471  } else {
472  // send existing entry, it's still valid
473  debugs(88, 3, "origin replied 304, revalidating existing entry and sending " <<
474  oldStatus << " to client");
476  }
477  }
478 
479  // origin replied with a non-error code
480  else if (status > Http::scNone && status < Http::scInternalServerError) {
481  // RFC 7234 section 4: a cache MUST use the most recent response
482  // (as determined by the Date header field)
483  if (new_rep.olderThan(&old_entry->mem().freshestReply())) {
484  http->logType.err.ignored = true;
485  debugs(88, 3, "origin replied " << status <<
486  " but with an older date header, sending old entry (" <<
487  oldStatus << ") to client");
489  } else {
491  debugs(88, 3, "origin replied " << status <<
492  ", replacing existing entry and forwarding to client");
493 
496 
498  }
499  }
500 
501  // origin replied with an error
504  debugs(88, 3, "origin replied with error " << status <<
505  ", forwarding to client due to fail_on_validation_err");
507  } else {
508  // ignore and let client have old entry
510  debugs(88, 3, "origin replied with error " <<
511  status << ", sending old entry (" << oldStatus << ") to client");
513  }
514 }
515 
518 
526 void
528 {
530  context->cacheHit(result);
531 }
532 
536 void
538 {
540  if (deleting) {
541  debugs(88, 3, "HIT object being deleted. Ignore the HIT.");
542  return;
543  }
544 
545  StoreEntry *e = http->storeEntry();
546 
547  HttpRequest *r = http->request;
548 
549  debugs(88, 3, "clientCacheHit: " << http->uri << ", " << result.length << " bytes");
550 
551  if (http->storeEntry() == NULL) {
552  debugs(88, 3, "clientCacheHit: request aborted");
553  return;
554  } else if (result.flags.error) {
555  /* swap in failure */
556  debugs(88, 3, "clientCacheHit: swapin failure for " << http->uri);
559  processMiss();
560  return;
561  }
562 
563  // The previously identified hit suddenly became unshareable!
564  // This is common for collapsed forwarding slaves but might also
565  // happen to regular hits because we are called asynchronously.
566  if (!e->mayStartHitting()) {
567  debugs(88, 3, "unshareable " << *e << ". MISS");
569  processMiss();
570  return;
571  }
572 
573  if (result.length == 0) {
574  debugs(88, 5, "store IO buffer has no content. MISS");
575  /* the store couldn't get enough data from the file for us to id the
576  * object
577  */
578  /* treat as a miss */
580  processMiss();
581  return;
582  }
583 
585  /* update size of the request */
586  reqsize = result.length + reqofs;
587 
588  /*
589  * Got the headers, now grok them
590  */
592 
593  if (http->request->storeId().cmp(e->mem_obj->storeId()) != 0) {
594  debugs(33, DBG_IMPORTANT, "clientProcessHit: URL mismatch, '" << e->mem_obj->storeId() << "' != '" << http->request->storeId() << "'");
595  http->logType.update(LOG_TCP_MISS); // we lack a more precise LOG_*_MISS code
596  processMiss();
597  return;
598  }
599 
600  switch (varyEvaluateMatch(e, r)) {
601 
602  case VARY_NONE:
603  /* No variance detected. Continue as normal */
604  break;
605 
606  case VARY_MATCH:
607  /* This is the correct entity for this request. Continue */
608  debugs(88, 2, "clientProcessHit: Vary MATCH!");
609  break;
610 
611  case VARY_OTHER:
612  /* This is not the correct entity for this request. We need
613  * to requery the cache.
614  */
616  e = NULL;
617  /* Note: varyEvalyateMatch updates the request with vary information
618  * so we only get here once. (it also takes care of cancelling loops)
619  */
620  debugs(88, 2, "clientProcessHit: Vary detected!");
622  return;
623 
624  case VARY_CANCEL:
625  /* varyEvaluateMatch found a object loop. Process as miss */
626  debugs(88, DBG_IMPORTANT, "clientProcessHit: Vary object loop!");
627  http->logType.update(LOG_TCP_MISS); // we lack a more precise LOG_*_MISS code
628  processMiss();
629  return;
630  }
631 
632  if (r->method == Http::METHOD_PURGE) {
633  debugs(88, 5, "PURGE gets a HIT");
635  e = NULL;
636  purgeRequest();
637  return;
638  }
639 
640  if (e->checkNegativeHit() && !r->flags.noCacheHack()) {
641  debugs(88, 5, "negative-HIT");
643  sendMoreData(result);
644  return;
645  } else if (blockedHit()) {
646  debugs(88, 5, "send_hit forces a MISS");
648  processMiss();
649  return;
650  } else if (!http->flags.internal && refreshCheckHTTP(e, r)) {
651  debugs(88, 5, "clientCacheHit: in refreshCheck() block");
652  /*
653  * We hold a stale copy; it needs to be validated
654  */
655  /*
656  * The 'needValidation' flag is used to prevent forwarding
657  * loops between siblings. If our copy of the object is stale,
658  * then we should probably only use parents for the validation
659  * request. Otherwise two siblings could generate a loop if
660  * both have a stale version of the object.
661  */
662  r->flags.needValidation = true;
663 
664  if (e->lastModified() < 0) {
665  debugs(88, 3, "validate HIT object? NO. Can't calculate entry modification time. Do MISS.");
666  /*
667  * We cannot revalidate entries without knowing their
668  * modification time.
669  * XXX: BUG 1890 objects without Date do not get one added.
670  */
672  processMiss();
673  } else if (r->flags.noCache) {
674  debugs(88, 3, "validate HIT object? NO. Client sent CC:no-cache. Do CLIENT_REFRESH_MISS");
675  /*
676  * This did not match a refresh pattern that overrides no-cache
677  * we should honour the client no-cache header.
678  */
680  processMiss();
681  } else if (r->url.getScheme() == AnyP::PROTO_HTTP || r->url.getScheme() == AnyP::PROTO_HTTPS) {
682  debugs(88, 3, "validate HIT object? YES.");
683  /*
684  * Object needs to be revalidated
685  * XXX This could apply to FTP as well, if Last-Modified is known.
686  */
687  processExpired();
688  } else {
689  debugs(88, 3, "validate HIT object? NO. Client protocol non-HTTP. Do MISS.");
690  /*
691  * We don't know how to re-validate other protocols. Handle
692  * them as if the object has expired.
693  */
695  processMiss();
696  }
697  return;
698  } else if (r->conditional()) {
699  debugs(88, 5, "conditional HIT");
700  if (processConditional(result))
701  return;
702  }
703 
704  /*
705  * plain ol' cache hit
706  */
707  debugs(88, 5, "plain old HIT");
708 
709 #if USE_DELAY_POOLS
710  if (e->store_status != STORE_OK)
712  else
713 #endif
714  if (e->mem_status == IN_MEMORY)
716  else if (Config.onoff.offline)
718 
719  sendMoreData(result);
720 }
721 
725 void
727 {
728  char *url = http->uri;
729  HttpRequest *r = http->request;
730  ErrorState *err = NULL;
731  debugs(88, 4, r->method << ' ' << url);
732 
737  if (http->storeEntry()) {
739  debugs(88, DBG_CRITICAL, "clientProcessMiss: miss on a special object (" << url << ").");
740  debugs(88, DBG_CRITICAL, "\tlog_type = " << http->logType.c_str());
741  http->storeEntry()->dump(1);
742  }
743 
745  }
746 
748  if (r->method == Http::METHOD_PURGE) {
749  purgeRequest();
750  return;
751  }
752 
754  if (r->method == Http::METHOD_OTHER) {
755  purgeAllCached();
756  }
757 
759  if (http->onlyIfCached()) {
761  return;
762  }
763 
764  Comm::ConnectionPointer conn = http->getConn() != nullptr ? http->getConn()->clientConnection : nullptr;
766  if (r->flags.loopDetected) {
768  Ip::Address tmp_noaddr;
769  tmp_noaddr.setNoAddr();
770  err = clientBuildError(ERR_ACCESS_DENIED, Http::scForbidden, nullptr, conn ? conn->remote : tmp_noaddr, http->request, http->al);
774  return;
775  } else {
776  assert(http->out.offset == 0);
777  createStoreEntry(r->method, r->flags);
779 
780  if (http->redirect.status) {
781  const HttpReplyPointer rep(new HttpReply);
786  http->storeEntry()->complete();
787  return;
788  }
789 
791 
794  }
795 }
796 
803 void
805 {
806  debugs(88, 4, http->request->method << ' ' << http->uri);
808  Ip::Address tmp_noaddr;
809  tmp_noaddr.setNoAddr();
811  http->getConn() ? http->getConn()->clientConnection->remote : tmp_noaddr,
812  http->request, http->al);
814  startError(err);
815 }
816 
818 bool
820 {
821  StoreEntry *const e = http->storeEntry();
822 
823  const auto replyStatusCode = e->mem().baseReply().sline.status();
824  if (replyStatusCode != Http::scOkay) {
825  debugs(88, 4, "miss because " << replyStatusCode << " != 200");
827  processMiss();
828  return true;
829  }
830 
831  HttpRequest &r = *http->request;
832 
834  // RFC 2616: reply with 412 Precondition Failed if If-Match did not match
836  return true;
837  }
838 
840  // RFC 7232: If-None-Match recipient MUST ignore IMS
841  r.flags.ims = false;
842  r.ims = -1;
843  r.imslen = 0;
845 
846  if (e->hasIfNoneMatchEtag(r)) {
848  return true;
849  }
850 
851  // None-Match is true (no ETag matched); treat as an unconditional hit
852  return false;
853  }
854 
855  if (r.flags.ims) {
856  // handle If-Modified-Since requests from the client
857  if (e->modifiedSince(r.ims, r.imslen)) {
858  // Modified-Since is true; treat as an unconditional hit
859  return false;
860 
861  } else {
862  // otherwise reply with 304 Not Modified
863  sendNotModified();
864  }
865  return true;
866  }
867 
868  return false;
869 }
870 
872 bool
874 {
876  return false; // hits are not blocked by default
877 
878  if (http->flags.internal)
879  return false; // internal content "hits" cannot be blocked
880 
881  const auto &rep = http->storeEntry()->mem().freshestReply();
882  {
883  std::unique_ptr<ACLFilledChecklist> chl(clientAclChecklistCreate(Config.accessList.sendHit, http));
884  chl->reply = const_cast<HttpReply*>(&rep); // ACLChecklist API bug
885  HTTPMSGLOCK(chl->reply);
886  return !chl->fastCheck().allowed(); // when in doubt, block
887  }
888 }
889 
890 void
892 {
893  /* Try to find a base entry */
894  http->flags.purging = true;
895  lookingforstore = 1;
896 
897  // TODO: can we use purgeAllCached() here instead of doing the
898  // getPublicByRequestMethod() dance?
900 }
901 
902 // Purges all entries with a given url
903 // TODO: move to SideAgent parent, when we have one
904 /*
905  * We probably cannot purge Vary-affected responses because their MD5
906  * keys depend on vary headers.
907  */
908 void
909 purgeEntriesByUrl(HttpRequest * req, const char *url)
910 {
912  if (m.respMaybeCacheable()) {
913  const cache_key *key = storeKeyPublic(url, m);
914  debugs(88, 5, m << ' ' << url << ' ' << storeKeyText(key));
915 #if USE_HTCP
916  neighborsHtcpClear(nullptr, req, m, HTCP_CLR_INVALIDATION);
917 #endif
918  Store::Root().evictIfFound(key);
919  }
920  }
921 }
922 
923 void
925 {
926  // XXX: performance regression, c_str() reallocates
929 }
930 
931 void
933 {
934  if (lookingforstore == 1)
935  purgeFoundGet(newEntry);
936  else if (lookingforstore == 2)
937  purgeFoundHead(newEntry);
938  else if (lookingforstore == 3)
939  purgeDoPurgeGet(newEntry);
940  else if (lookingforstore == 4)
941  purgeDoPurgeHead(newEntry);
942  else if (lookingforstore == 5)
943  identifyFoundObject(newEntry);
944 }
945 
946 LogTags *
948 {
949  // XXX: clientReplyContext code assumes that http cbdata is always valid.
950  // TODO: Either add cbdataReferenceValid(http) checks in all the relevant
951  // places, like this one, or remove cbdata protection of the http member.
952  return &http->logType;
953 }
954 
955 void
957 {
958  if (!newEntry) {
959  lookingforstore = 2;
961  } else
962  purgeFoundObject (newEntry);
963 }
964 
965 void
967 {
968  if (!newEntry)
970  else
971  purgeFoundObject (newEntry);
972 }
973 
974 void
976 {
977  assert (entry);
978 
979  if (EBIT_TEST(entry->flags, ENTRY_SPECIAL)) {
981  Ip::Address tmp_noaddr;
982  tmp_noaddr.setNoAddr(); // TODO: make a global const
984  http->getConn() ? http->getConn()->clientConnection->remote : tmp_noaddr,
985  http->request, http->al);
986  startError(err);
987  return; // XXX: leaking unused entry if some store does not keep it
988  }
989 
990  StoreIOBuffer localTempBuffer;
991  /* Swap in the metadata */
992  http->storeEntry(entry);
993 
994  http->storeEntry()->lock("clientReplyContext::purgeFoundObject");
996  http->request->method);
997 
998  sc = storeClientListAdd(http->storeEntry(), this);
999 
1001 
1002  reqofs = 0;
1003 
1004  localTempBuffer.offset = http->out.offset;
1005 
1006  localTempBuffer.length = next()->readBuffer.length;
1007 
1008  localTempBuffer.data = next()->readBuffer.data;
1009 
1011  localTempBuffer, CacheHit, this);
1012 }
1013 
1014 void
1016 {
1017  debugs(88, 3, "Config2.onoff.enable_purge = " <<
1019 
1020  if (!Config2.onoff.enable_purge) {
1022  Ip::Address tmp_noaddr;
1023  tmp_noaddr.setNoAddr();
1025  http->getConn() ? http->getConn()->clientConnection->remote : tmp_noaddr, http->request, http->al);
1026  startError(err);
1027  return;
1028  }
1029 
1030  /* Release both IP cache */
1032 
1033  if (!http->flags.purging)
1035  else
1036  purgeDoMissPurge();
1037 }
1038 
1039 void
1041 {
1043  lookingforstore = 3;
1045 }
1046 
1047 void
1049 {
1050  if (newEntry) {
1051  /* Release the cached URI */
1052  debugs(88, 4, "clientPurgeRequest: GET '" << newEntry->url() << "'" );
1053 #if USE_HTCP
1055 #endif
1056  newEntry->release(true);
1058  }
1059 
1060  lookingforstore = 4;
1062 }
1063 
1064 void
1066 {
1067  if (newEntry) {
1068  debugs(88, 4, "HEAD " << newEntry->url());
1069 #if USE_HTCP
1071 #endif
1072  newEntry->release(true);
1074  }
1075 
1076  /* And for Vary, release the base URI if none of the headers was included in the request */
1077  if (!http->request->vary_headers.isEmpty()
1078  && http->request->vary_headers.find('=') != SBuf::npos) {
1079  // XXX: performance regression, c_str() reallocates
1082 
1083  if (entry) {
1084  debugs(88, 4, "Vary GET " << entry->url());
1085 #if USE_HTCP
1087 #endif
1088  entry->release(true);
1090  }
1091 
1092  entry = storeGetPublic(tmp.c_str(), Http::METHOD_HEAD);
1093 
1094  if (entry) {
1095  debugs(88, 4, "Vary HEAD " << entry->url());
1096 #if USE_HTCP
1098 #endif
1099  entry->release(true);
1101  }
1102  }
1103 
1104  if (purgeStatus == Http::scNone)
1106 
1107  /*
1108  * Make a new entry to hold the reply to be written
1109  * to the client.
1110  */
1111  /* FIXME: This doesn't need to go through the store. Simply
1112  * push down the client chain
1113  */
1115 
1117 
1118  const HttpReplyPointer rep(new HttpReply);
1119  rep->setHeaders(purgeStatus, NULL, NULL, 0, 0, -1);
1120  http->storeEntry()->replaceHttpReply(rep);
1121  http->storeEntry()->complete();
1122 }
1123 
1124 void
1126 {
1127  clientStreamNode *nextNode = (clientStreamNode *)node->node.next->data;
1128  StoreIOBuffer localTempBuffer;
1130  localTempBuffer.offset = nextNode->readBuffer.offset + headers_sz;
1131  localTempBuffer.length = nextNode->readBuffer.length;
1132  localTempBuffer.data = nextNode->readBuffer.data;
1134  localTempBuffer, SendMoreData, this);
1136  http->storeEntry()->buffer();
1137  const HttpReplyPointer rep(new HttpReply);
1138  rep->setHeaders(Http::scOkay, NULL, "text/plain", http->request->prefixLen(), 0, squid_curtime);
1139  http->storeEntry()->replaceHttpReply(rep);
1141  http->storeEntry()->complete();
1142 }
1143 
1144 #define SENDING_BODY 0
1145 #define SENDING_HDRSONLY 1
1146 int
1148 {
1149  StoreEntry *entry = http->storeEntry();
1150 
1151  if (entry == NULL)
1152  return 0;
1153 
1154  /*
1155  * For now, 'done_copying' is used for special cases like
1156  * Range and HEAD requests.
1157  */
1158  if (http->flags.done_copying)
1159  return 1;
1160 
1162  // last-chunk was not sent
1163  return 0;
1164  }
1165 
1166  /*
1167  * Handle STORE_OK objects.
1168  * objectLen(entry) will be set proprely.
1169  * RC: Does objectLen(entry) include the Headers?
1170  * RC: Yes.
1171  */
1172  if (entry->store_status == STORE_OK) {
1173  return storeOKTransferDone();
1174  } else {
1175  return storeNotOKTransferDone();
1176  }
1177 }
1178 
1179 int
1181 {
1182  assert(http->storeEntry()->objectLen() >= 0);
1184  if (http->out.offset >= http->storeEntry()->objectLen() - headers_sz) {
1185  debugs(88,3,HERE << "storeOKTransferDone " <<
1186  " out.offset=" << http->out.offset <<
1187  " objectLen()=" << http->storeEntry()->objectLen() <<
1188  " headers_sz=" << headers_sz);
1189  return 1;
1190  }
1191 
1192  return 0;
1193 }
1194 
1195 int
1197 {
1198  /*
1199  * Now, handle STORE_PENDING objects
1200  */
1201  MemObject *mem = http->storeEntry()->mem_obj;
1202  assert(mem != NULL);
1203  assert(http->request != NULL);
1204 
1205  /* mem->reply was wrong because it uses the UPSTREAM header length!!! */
1206  if (headers_sz == 0)
1207  /* haven't found end of headers yet */
1208  return 0;
1209 
1210  // TODO: Use MemObject::expectedReplySize(method) after resolving XXX below.
1211  const auto expectedBodySize = mem->baseReply().content_length;
1212 
1213  // XXX: The code below talks about sending data, and checks stats about
1214  // bytes written to the client connection, but this method must determine
1215  // whether we are done _receiving_ data from Store. This code should work OK
1216  // when expectedBodySize is unknown or matches written data, but it may
1217  // malfunction when we are writing ranges while receiving a full response.
1218 
1219  /*
1220  * Figure out how much data we are supposed to send.
1221  * If we are sending a body and we don't have a content-length,
1222  * then we must wait for the object to become STORE_OK.
1223  */
1224  if (expectedBodySize < 0)
1225  return 0;
1226 
1227  const uint64_t expectedLength = expectedBodySize + http->out.headers_sz;
1228 
1229  if (http->out.size < expectedLength)
1230  return 0;
1231  else {
1232  debugs(88,3,HERE << "storeNotOKTransferDone " <<
1233  " out.size=" << http->out.size <<
1234  " expectedLength=" << expectedLength);
1235  return 1;
1236  }
1237 }
1238 
1239 /* A write has completed, what is the next status based on the
1240  * canonical request data?
1241  * 1 something is wrong
1242  * 0 nothing is wrong.
1243  *
1244  */
1245 int
1247 {
1248 #if SIZEOF_INT64_T == 4
1249  if (http->out.size > 0x7FFF0000) {
1250  debugs(88, DBG_IMPORTANT, "WARNING: closing FD " << fd << " to prevent out.size counter overflow");
1251  if (http->getConn())
1252  debugs(88, DBG_IMPORTANT, "\tclient " << http->getConn()->peer);
1253  debugs(88, DBG_IMPORTANT, "\treceived " << http->out.size << " bytes");
1254  debugs(88, DBG_IMPORTANT, "\tURI " << http->log_uri);
1255  return 1;
1256  }
1257 
1258  if (http->out.offset > 0x7FFF0000) {
1259  debugs(88, DBG_IMPORTANT, "WARNING: closing FD " << fd < " to prevent out.offset counter overflow");
1260  if (http->getConn())
1261  debugs(88, DBG_IMPORTANT, "\tclient " << http->getConn()->peer);
1262  debugs(88, DBG_IMPORTANT, "\treceived " << http->out.size << " bytes, offset " << http->out.offset);
1263  debugs(88, DBG_IMPORTANT, "\tURI " << http->log_uri);
1264  return 1;
1265  }
1266 
1267 #endif
1268  return 0;
1269 }
1270 
1271 /* Preconditions:
1272  * *http is a valid structure.
1273  * fd is either -1, or an open fd.
1274  *
1275  * TODO: enumify this
1276  *
1277  * This function is used by any http request sink, to determine the status
1278  * of the object.
1279  */
1282 {
1283  clientReplyContext *context = dynamic_cast<clientReplyContext *>(aNode->data.getRaw());
1284  assert (context);
1285  assert (context->http == http);
1286  return context->replyStatus();
1287 }
1288 
1291 {
1292  int done;
1293  /* Here because lower nodes don't need it */
1294 
1295  if (http->storeEntry() == NULL) {
1296  debugs(88, 5, "clientReplyStatus: no storeEntry");
1297  return STREAM_FAILED; /* yuck, but what can we do? */
1298  }
1299 
1301  /* TODO: Could upstream read errors (result.flags.error) be
1302  * lost, and result in undersize requests being considered
1303  * complete. Should we tcp reset such connections ?
1304  */
1305  debugs(88, 5, "clientReplyStatus: aborted storeEntry");
1306  return STREAM_FAILED;
1307  }
1308 
1309  if ((done = checkTransferDone()) != 0 || flags.complete) {
1310  debugs(88, 5, "clientReplyStatus: transfer is DONE: " << done << flags.complete);
1311  /* Ok we're finished, but how? */
1312 
1314  debugs(88, 5, "clientReplyStatus: truncated response body");
1316  }
1317 
1318  if (!done) {
1319  debugs(88, 5, "clientReplyStatus: closing, !done, but read 0 bytes");
1320  return STREAM_FAILED;
1321  }
1322 
1323  // TODO: See also (and unify with) storeNotOKTransferDone() checks.
1324  const int64_t expectedBodySize =
1326  if (expectedBodySize >= 0 && !http->gotEnough()) {
1327  debugs(88, 5, "clientReplyStatus: client didn't get all it expected");
1329  }
1330 
1331  debugs(88, 5, "clientReplyStatus: stream complete; keepalive=" <<
1333  return STREAM_COMPLETE;
1334  }
1335 
1336  // XXX: Should this be checked earlier? We could return above w/o checking.
1337  if (reply->receivedBodyTooLarge(*http->request, http->out.offset - 4096)) {
1338  /* 4096 is a margin for the HTTP headers included in out.offset */
1339  debugs(88, 5, "clientReplyStatus: client reply body is too large");
1340  return STREAM_FAILED;
1341  }
1342 
1343  return STREAM_NONE;
1344 }
1345 
1346 /* Responses with no body will not have a content-type header,
1347  * which breaks the rep_mime_type acl, which
1348  * coincidentally, is the most common acl for reply access lists.
1349  * A better long term fix for this is to allow acl matches on the various
1350  * status codes, and then supply a default ruleset that puts these
1351  * codes before any user defines access entries. That way the user
1352  * can choose to block these responses where appropriate, but won't get
1353  * mysterious breakages.
1354  */
1355 bool
1357 {
1358  bool result;
1359 
1360  switch (sline) {
1361 
1362  case Http::scContinue:
1363 
1365 
1366  case Http::scProcessing:
1367 
1368  case Http::scNoContent:
1369 
1370  case Http::scNotModified:
1371  result = true;
1372  break;
1373 
1374  default:
1375  result = false;
1376  }
1377 
1378  return result;
1379 }
1380 
1388 void
1390 {
1391  HttpHeader *hdr = &reply->header;
1392  const bool is_hit = http->logType.isTcpHit();
1394 #if DONT_FILTER_THESE
1395  /* but you might want to if you run Squid as an HTTP accelerator */
1396  /* hdr->delById(HDR_ACCEPT_RANGES); */
1397  hdr->delById(HDR_ETAG);
1398 #endif
1399 
1400  if (is_hit || collapsedRevalidation == crSlave)
1402  // TODO: RFC 2965 : Must honour Cache-Control: no-cache="set-cookie2" and remove header.
1403 
1404  // if there is not configured a peer proxy with login=PASS or login=PASSTHRU option enabled
1405  // remove the Proxy-Authenticate header
1406  if ( !request->peer_login || (strcmp(request->peer_login,"PASS") != 0 && strcmp(request->peer_login,"PASSTHRU") != 0)) {
1407 #if USE_ADAPTATION
1408  // but allow adaptation services to authenticate clients
1409  // via request satisfaction
1410  if (!http->requestSatisfactionMode())
1411 #endif
1413  }
1414 
1416  // paranoid: ContentLengthInterpreter has cleaned non-generated replies
1418 
1419  // if (request->range)
1420  // clientBuildRangeHeader(http, reply);
1421 
1422  /*
1423  * Add a estimated Age header on cache hits.
1424  */
1425  if (is_hit) {
1426  /*
1427  * Remove any existing Age header sent by upstream caches
1428  * (note that the existing header is passed along unmodified
1429  * on cache misses)
1430  */
1432  /*
1433  * This adds the calculated object age. Note that the details of the
1434  * age calculation is performed by adjusting the timestamp in
1435  * StoreEntry::timestampsSet(), not here.
1436  */
1440  } else if (http->getConn() && http->getConn()->port->actAsOrigin) {
1441  // Swap the Date: header to current time if we are simulating an origin
1443  if (h)
1444  hdr->putExt("X-Origin-Date", h->value.termedBuf());
1448  if (h && http->storeEntry()->expires >= 0) {
1449  hdr->putExt("X-Origin-Expires", h->value.termedBuf());
1452  }
1453  if (http->storeEntry()->timestamp <= squid_curtime) {
1454  // put X-Cache-Age: instead of Age:
1455  char age[64];
1456  snprintf(age, sizeof(age), "%" PRId64, static_cast<int64_t>(squid_curtime - http->storeEntry()->timestamp));
1457  hdr->putExt("X-Cache-Age", age);
1458  }
1459  } else if (http->storeEntry()->timestamp <= squid_curtime) {
1462  /* Signal old objects. NB: rfc 2616 is not clear,
1463  * by implication, on whether we should do this to all
1464  * responses, or only cache hits.
1465  * 14.46 states it ONLY applies for heuristically calculated
1466  * freshness values, 13.2.4 doesn't specify the same limitation.
1467  * We interpret RFC 2616 under the combination.
1468  */
1469  /* TODO: if maxage or s-maxage is present, don't do this */
1470 
1471  if (squid_curtime - http->storeEntry()->timestamp >= 86400)
1472  hdr->putWarning(113, "This cache hit is still fresh and more than 1 day old");
1473  }
1474  }
1475 
1476  /* RFC 2616: Section 14.18
1477  *
1478  * Add a Date: header if missing.
1479  * We have access to a clock therefore are required to amend any shortcoming in servers.
1480  *
1481  * NP: done after Age: to prevent ENTRY_SPECIAL double-handling this header.
1482  */
1483  if ( !hdr->has(Http::HdrType::DATE) ) {
1484  if (!http->storeEntry())
1486  else if (http->storeEntry()->timestamp > 0)
1488  else {
1489  debugs(88,DBG_IMPORTANT,"BUG 3279: HTTP reply without Date:");
1490  /* dump something useful about the problem */
1492  }
1493  }
1494 
1495  // add Warnings required by RFC 2616 if serving a stale hit
1497  hdr->putWarning(110, "Response is stale");
1499  hdr->putWarning(111, "Revalidation failed");
1500  }
1501 
1502  /* Filter unproxyable authentication types */
1503  if (http->logType.oldType != LOG_TCP_DENIED &&
1506  HttpHeaderEntry *e;
1507 
1508  int connection_auth_blocked = 0;
1509  while ((e = hdr->getEntry(&pos))) {
1510  if (e->id == Http::HdrType::WWW_AUTHENTICATE) {
1511  const char *value = e->value.rawBuf();
1512 
1513  if ((strncasecmp(value, "NTLM", 4) == 0 &&
1514  (value[4] == '\0' || value[4] == ' '))
1515  ||
1516  (strncasecmp(value, "Negotiate", 9) == 0 &&
1517  (value[9] == '\0' || value[9] == ' '))
1518  ||
1519  (strncasecmp(value, "Kerberos", 8) == 0 &&
1520  (value[8] == '\0' || value[8] == ' '))) {
1521  if (request->flags.connectionAuthDisabled) {
1522  hdr->delAt(pos, connection_auth_blocked);
1523  continue;
1524  }
1525  request->flags.mustKeepalive = true;
1526  if (!request->flags.accelerated && !request->flags.intercepted) {
1527  httpHeaderPutStrf(hdr, Http::HdrType::PROXY_SUPPORT, "Session-Based-Authentication");
1528  /*
1529  We send "Connection: Proxy-Support" header to mark
1530  Proxy-Support as a hop-by-hop header for intermediaries that do not
1531  understand the semantics of this header. The RFC should have included
1532  this recommendation.
1533  */
1534  httpHeaderPutStrf(hdr, Http::HdrType::CONNECTION, "Proxy-support");
1535  }
1536  break;
1537  }
1538  }
1539  }
1540 
1541  if (connection_auth_blocked)
1542  hdr->refreshMask();
1543  }
1544 
1545 #if USE_AUTH
1546  /* Handle authentication headers */
1547  if (http->logType.oldType == LOG_TCP_DENIED &&
1550  ) {
1551  /* Add authentication header */
1557  Auth::UserRequest::AddReplyAuthHeader(reply, request->auth_user_request, request, 0, 1);
1558  } else if (request->auth_user_request != NULL)
1560 #endif
1561 
1562  /* Append X-Cache */
1563  httpHeaderPutStrf(hdr, Http::HdrType::X_CACHE, "%s from %s",
1564  is_hit ? "HIT" : "MISS", getMyHostname());
1565 
1566 #if USE_CACHE_DIGESTS
1567  /* Append X-Cache-Lookup: -- temporary hack, to be removed @?@ @?@ */
1568  httpHeaderPutStrf(hdr, Http::HdrType::X_CACHE_LOOKUP, "%s from %s:%d",
1569  lookup_type ? lookup_type : "NONE",
1570  getMyHostname(), getMyPort());
1571 
1572 #endif
1573 
1574  const bool maySendChunkedReply = !request->multipartRangeRequest() &&
1575  reply->sline.protocol == AnyP::PROTO_HTTP && // response is HTTP
1576  (request->http_ver >= Http::ProtocolVersion(1,1));
1577 
1578  /* Check whether we should send keep-alive */
1579  if (!Config.onoff.error_pconns && reply->sline.status() >= 400 && !request->flags.mustKeepalive) {
1580  debugs(33, 3, "clientBuildReplyHeader: Error, don't keep-alive");
1581  request->flags.proxyKeepalive = false;
1582  } else if (!Config.onoff.client_pconns && !request->flags.mustKeepalive) {
1583  debugs(33, 2, "clientBuildReplyHeader: Connection Keep-Alive not requested by admin or client");
1584  request->flags.proxyKeepalive = false;
1585  } else if (request->flags.proxyKeepalive && shutting_down) {
1586  debugs(88, 3, "clientBuildReplyHeader: Shutting down, don't keep-alive.");
1587  request->flags.proxyKeepalive = false;
1588  } else if (request->flags.connectionAuth && !reply->keep_alive) {
1589  debugs(33, 2, "clientBuildReplyHeader: Connection oriented auth but server side non-persistent");
1590  request->flags.proxyKeepalive = false;
1591  } else if (reply->bodySize(request->method) < 0 && !maySendChunkedReply) {
1592  debugs(88, 3, "clientBuildReplyHeader: can't keep-alive, unknown body size" );
1593  request->flags.proxyKeepalive = false;
1594  } else if (fdUsageHigh()&& !request->flags.mustKeepalive) {
1595  debugs(88, 3, "clientBuildReplyHeader: Not many unused FDs, can't keep-alive");
1596  request->flags.proxyKeepalive = false;
1597  } else if (request->flags.sslBumped && !reply->persistent()) {
1598  // We do not really have to close, but we pretend we are a tunnel.
1599  debugs(88, 3, "clientBuildReplyHeader: bumped reply forces close");
1600  request->flags.proxyKeepalive = false;
1601  } else if (request->pinnedConnection() && !reply->persistent()) {
1602  // The peer wants to close the pinned connection
1603  debugs(88, 3, "pinned reply forces close");
1604  request->flags.proxyKeepalive = false;
1605  } else if (http->getConn()) {
1606  ConnStateData * conn = http->getConn();
1607  if (!Comm::IsConnOpen(conn->port->listenConn)) {
1608  // The listening port closed because of a reconfigure
1609  debugs(88, 3, "listening port closed");
1610  request->flags.proxyKeepalive = false;
1611  }
1612  }
1613 
1614  // Decide if we send chunked reply
1615  if (maySendChunkedReply && reply->bodySize(request->method) < 0) {
1616  debugs(88, 3, "clientBuildReplyHeader: chunked reply");
1617  request->flags.chunkedReply = true;
1618  hdr->putStr(Http::HdrType::TRANSFER_ENCODING, "chunked");
1619  }
1620 
1621  hdr->addVia(reply->sline.version);
1622 
1623  /* Signal keep-alive or close explicitly */
1624  hdr->putStr(Http::HdrType::CONNECTION, request->flags.proxyKeepalive ? "keep-alive" : "close");
1625 
1626 #if ADD_X_REQUEST_URI
1627  /*
1628  * Knowing the URI of the request is useful when debugging persistent
1629  * connections in a client; we cannot guarantee the order of http headers,
1630  * but X-Request-URI is likely to be the very last header to ease use from a
1631  * debugger [hdr->entries.count-1].
1632  */
1634  http->memOjbect()->url ? http->memObject()->url : http->uri);
1635 
1636 #endif
1637 
1638  /* Surrogate-Control requires Surrogate-Capability from upstream to pass on */
1639  if ( hdr->has(Http::HdrType::SURROGATE_CONTROL) ) {
1640  if (!request->header.has(Http::HdrType::SURROGATE_CAPABILITY)) {
1642  }
1643  /* TODO: else case: drop any controls intended specifically for our surrogate ID */
1644  }
1645 
1647 }
1648 
1649 void
1651 {
1652  assert(reply == NULL);
1653 
1655  HTTPMSGLOCK(reply);
1656 
1657  http->al->reply = reply;
1658 
1660  /* RFC 2616 requires us to advertise our version (but only on real HTTP traffic) */
1662  }
1663 
1664  /* do header conversions */
1665  buildReplyHeader();
1666 }
1667 
1671 void
1673 {
1674  StoreEntry *e = http->storeEntry();
1675  assert(e); // or we are not dealing with a hit
1676  // We probably have not locked the entry earlier, unfortunately. We lock it
1677  // now so that we can unlock two lines later (and trigger cleanup).
1678  // Ideally, ClientHttpRequest::storeEntry() should lock/unlock, but it is
1679  // used so inconsistently that simply adding locking there leads to bugs.
1680  e->lock("clientReplyContext::forgetHit");
1681  http->storeEntry(NULL);
1682  e->unlock("clientReplyContext::forgetHit"); // may delete e
1683 }
1684 
1685 void
1687 {
1688  HttpRequest *r = http->request;
1689 
1690  // client sent CC:no-cache or some other condition has been
1691  // encountered which prevents delivering a public/cached object.
1692  if (!r->flags.noCache || r->flags.internal) {
1693  lookingforstore = 5;
1695  } else {
1696  identifyFoundObject(nullptr);
1697  }
1698 }
1699 
1704 void
1706 {
1707  HttpRequest *r = http->request;
1708  http->storeEntry(newEntry);
1709  const auto e = http->storeEntry();
1710 
1711  /* Release IP-cache entries on reload */
1715  if (r->flags.noCache || r->flags.noCacheHack())
1717 
1718 #if USE_CACHE_DIGESTS
1719  lookup_type = e ? "HIT" : "MISS";
1720 #endif
1721 
1722  if (!e) {
1724  debugs(85, 3, "StoreEntry is NULL - MISS");
1726  doGetMoreData();
1727  return;
1728  }
1729 
1730  if (Config.onoff.offline) {
1732  debugs(85, 3, "offline HIT " << *e);
1734  doGetMoreData();
1735  return;
1736  }
1737 
1738  if (http->redirect.status) {
1740  debugs(85, 3, "REDIRECT status forced StoreEntry to NULL (no body on 3XX responses) " << *e);
1741  forgetHit();
1743  doGetMoreData();
1744  return;
1745  }
1746 
1747  if (!e->validToSend()) {
1748  debugs(85, 3, "!storeEntryValidToSend MISS " << *e);
1749  forgetHit();
1751  doGetMoreData();
1752  return;
1753  }
1754 
1755  if (EBIT_TEST(e->flags, ENTRY_SPECIAL)) {
1756  /* \li Special entries are always hits, no matter what the client says */
1757  debugs(85, 3, "ENTRY_SPECIAL HIT " << *e);
1759  doGetMoreData();
1760  return;
1761  }
1762 
1763  if (r->flags.noCache) {
1764  debugs(85, 3, "no-cache REFRESH MISS " << *e);
1765  forgetHit();
1767  doGetMoreData();
1768  return;
1769  }
1770 
1771  if (e->hittingRequiresCollapsing() && !startCollapsingOn(*e, false)) {
1772  debugs(85, 3, "prohibited CF MISS " << *e);
1773  forgetHit();
1775  doGetMoreData();
1776  return;
1777  }
1778 
1779  debugs(85, 3, "default HIT " << *e);
1781  doGetMoreData();
1782 }
1783 
1793 void
1795 {
1796  /* Test preconditions */
1797  assert(aNode != NULL);
1798  assert(cbdataReferenceValid(aNode));
1799  assert(aNode->node.prev == NULL);
1800  assert(aNode->node.next != NULL);
1801  clientReplyContext *context = dynamic_cast<clientReplyContext *>(aNode->data.getRaw());
1802  assert (context);
1803  assert(context->http == http);
1804 
1805  clientStreamNode *next = ( clientStreamNode *)aNode->node.next->data;
1806 
1807  if (!context->ourNode)
1808  context->ourNode = aNode;
1809 
1810  /* no cbdatareference, this is only used once, and safely */
1811  if (context->flags.storelogiccomplete) {
1812  StoreIOBuffer tempBuffer;
1813  tempBuffer.offset = next->readBuffer.offset + context->headers_sz;
1814  tempBuffer.length = next->readBuffer.length;
1815  tempBuffer.data = next->readBuffer.data;
1816 
1817  storeClientCopy(context->sc, http->storeEntry(),
1818  tempBuffer, clientReplyContext::SendMoreData, context);
1819  return;
1820  }
1821 
1822  if (context->http->request->method == Http::METHOD_PURGE) {
1823  context->purgeRequest();
1824  return;
1825  }
1826 
1827  // OPTIONS with Max-Forwards:0 handled in clientProcessRequest()
1828 
1829  if (context->http->request->method == Http::METHOD_TRACE) {
1830  if (context->http->request->header.getInt64(Http::HdrType::MAX_FORWARDS) == 0) {
1831  context->traceReply(aNode);
1832  return;
1833  }
1834 
1835  /* continue forwarding, not finished yet. */
1836  http->logType.update(LOG_TCP_MISS);
1837 
1838  context->doGetMoreData();
1839  } else
1840  context->identifyStoreObject();
1841 }
1842 
1843 void
1845 {
1846  /* We still have to do store logic processing - vary, cache hit etc */
1847  if (http->storeEntry() != NULL) {
1848  /* someone found the object in the cache for us */
1849  StoreIOBuffer localTempBuffer;
1850 
1851  http->storeEntry()->lock("clientReplyContext::doGetMoreData");
1852 
1854 
1855  sc = storeClientListAdd(http->storeEntry(), this);
1856 #if USE_DELAY_POOLS
1858 #endif
1859 
1861  reqofs = 0;
1862  /* guarantee nothing has been sent yet! */
1863  assert(http->out.size == 0);
1864  assert(http->out.offset == 0);
1865 
1866  if (ConnStateData *conn = http->getConn()) {
1867  if (Ip::Qos::TheConfig.isHitTosActive()) {
1868  Ip::Qos::doTosLocalHit(conn->clientConnection);
1869  }
1870 
1871  if (Ip::Qos::TheConfig.isHitNfmarkActive()) {
1872  Ip::Qos::doNfmarkLocalHit(conn->clientConnection);
1873  }
1874  }
1875 
1876  localTempBuffer.offset = reqofs;
1877  localTempBuffer.length = getNextNode()->readBuffer.length;
1878  localTempBuffer.data = getNextNode()->readBuffer.data;
1879  storeClientCopy(sc, http->storeEntry(), localTempBuffer, CacheHit, this);
1880  } else {
1881  /* MISS CASE, http->logType is already set! */
1882  processMiss();
1883  }
1884 }
1885 
1887 void
1889 {
1891  clientStreamDetach(node, http);
1892 }
1893 
1898 void
1900 {
1901  clientReplyContext *context = static_cast<clientReplyContext *>(data);
1902  context->sendMoreData (result);
1903 }
1904 
1905 void
1907 {
1908  /* At least, I think that's what this does */
1911 }
1912 
1913 bool
1914 clientReplyContext::errorInStream(StoreIOBuffer const &result, size_t const &sizeToProcess)const
1915 {
1916  return /* aborted request */
1918  /* Upstream read error */ (result.flags.error) ||
1919  /* Upstream EOF */ (sizeToProcess == 0);
1920 }
1921 
1922 void
1924 {
1930  debugs(88, 5, "A stream error has occurred, marking as complete and sending no data.");
1931  StoreIOBuffer localTempBuffer;
1932  flags.complete = 1;
1933  http->request->flags.streamError = true;
1934  localTempBuffer.flags.error = result.flags.error;
1936  localTempBuffer);
1937 }
1938 
1939 void
1941 {
1942  StoreIOBuffer localTempBuffer;
1943 
1944  if (result.length == 0) {
1945  debugs(88, 5, "clientReplyContext::pushStreamData: marking request as complete due to 0 length store result");
1946  flags.complete = 1;
1947  }
1948 
1949  assert(result.offset - headers_sz == next()->readBuffer.offset);
1950  localTempBuffer.offset = result.offset - headers_sz;
1951  localTempBuffer.length = result.length;
1952 
1953  if (localTempBuffer.length)
1954  localTempBuffer.data = source;
1955 
1957  localTempBuffer);
1958 }
1959 
1962 {
1964  return getNextNode();
1965 }
1966 
1967 void
1969 {
1970  Ip::Address tmp_noaddr;
1971  tmp_noaddr.setNoAddr(); // TODO: make a global const
1974  http->getConn() != NULL ? http->getConn()->clientConnection->remote : tmp_noaddr,
1975  http->request, http->al);
1978  startError(err);
1979 
1980 }
1981 
1983 void
1985 {
1987  Ip::Address tmp_noaddr;
1988  tmp_noaddr.setNoAddr();
1989  ErrorState *const err =
1991  NULL, http->getConn() ? http->getConn()->clientConnection->remote : tmp_noaddr, http->request, http->al);
1994  startError(err);
1995 }
1996 
1998 void
2000 {
2001  StoreEntry *e = http->storeEntry();
2002  const time_t timestamp = e->timestamp;
2003  const auto temprep = e->mem().freshestReply().make304();
2004  // log as TCP_INM_HIT if code 304 generated for
2005  // If-None-Match request
2006  if (!http->request->flags.ims)
2008  else
2012  e = http->storeEntry();
2013  // Copy timestamp from the original entry so the 304
2014  // reply has a meaningful Age: header.
2015  e->timestampsSet();
2016  e->timestamp = timestamp;
2017  e->replaceHttpReply(temprep);
2018  e->complete();
2019  /*
2020  * TODO: why put this in the store and then serialise it and
2021  * then parse it again. Simply mark the request complete in
2022  * our context and write the reply struct to the client side.
2023  */
2025 }
2026 
2029 void
2031 {
2032  if (http->request->method == Http::METHOD_GET ||
2034  sendNotModified();
2035  else
2037 }
2038 
2039 void
2041 {
2042  /* NP: this should probably soft-fail to a zero-sized-reply error ?? */
2043  assert(reply);
2044 
2046  if (http->logType.oldType == LOG_TCP_DENIED ||
2049  headers_sz = reply->hdr_sz;
2051  return;
2052  }
2053 
2057  return;
2058  }
2059 
2060  headers_sz = reply->hdr_sz;
2061 
2063  if (!Config.accessList.reply) {
2065  return;
2066  }
2067 
2069  ACLFilledChecklist *replyChecklist =
2071  replyChecklist->reply = reply;
2072  HTTPMSGLOCK(replyChecklist->reply);
2073  replyChecklist->nonBlockingCheck(ProcessReplyAccessResult, this);
2074 }
2075 
2076 void
2078 {
2079  clientReplyContext *me = static_cast<clientReplyContext *>(voidMe);
2080  me->processReplyAccessResult(rv);
2081 }
2082 
2083 void
2085 {
2086  debugs(88, 2, "The reply for " << http->request->method
2087  << ' ' << http->uri << " is " << accessAllowed << ", because it matched "
2088  << (AclMatchedName ? AclMatchedName : "NO ACL's"));
2089 
2090  if (!accessAllowed.allowed()) {
2091  ErrorState *err;
2092  err_type page_id;
2094 
2096 
2097  if (page_id == ERR_NONE)
2098  page_id = ERR_ACCESS_DENIED;
2099 
2100  Ip::Address tmp_noaddr;
2101  tmp_noaddr.setNoAddr();
2102  err = clientBuildError(page_id, Http::scForbidden, NULL,
2103  http->getConn() != NULL ? http->getConn()->clientConnection->remote : tmp_noaddr,
2104  http->request, http->al);
2105 
2107 
2109 
2110  startError(err);
2111 
2112  return;
2113  }
2114 
2115  /* Ok, the reply is allowed, */
2117 
2118  ssize_t body_size = reqofs - reply->hdr_sz;
2119  if (body_size < 0) {
2120  reqofs = reply->hdr_sz;
2121  body_size = 0;
2122  }
2123 
2124  debugs(88, 3, "clientReplyContext::sendMoreData: Appending " <<
2125  (int) body_size << " bytes after " << reply->hdr_sz <<
2126  " bytes of headers");
2127 
2128 #if USE_SQUID_ESI
2129 
2133  debugs(88, 2, "Enabling ESI processing for " << http->uri);
2136  }
2137 
2138 #endif
2139 
2140  if (http->request->method == Http::METHOD_HEAD) {
2141  /* do not forward body for HEAD replies */
2142  body_size = 0;
2143  http->flags.done_copying = true;
2144  flags.complete = 1;
2145  }
2146 
2148  flags.headersSent = true;
2149 
2150  StoreIOBuffer localTempBuffer;
2151  char *buf = next()->readBuffer.data;
2152  char *body_buf = buf + reply->hdr_sz;
2153 
2154  //Server side may disable ranges under some circumstances.
2155 
2156  if ((!http->request->range))
2157  next()->readBuffer.offset = 0;
2158 
2159  body_buf -= next()->readBuffer.offset;
2160 
2161  if (next()->readBuffer.offset != 0) {
2162  if (next()->readBuffer.offset > body_size) {
2163  /* Can't use any of the body we received. send nothing */
2164  localTempBuffer.length = 0;
2165  localTempBuffer.data = NULL;
2166  } else {
2167  localTempBuffer.length = body_size - next()->readBuffer.offset;
2168  localTempBuffer.data = body_buf + next()->readBuffer.offset;
2169  }
2170  } else {
2171  localTempBuffer.length = body_size;
2172  localTempBuffer.data = body_buf;
2173  }
2174 
2175  /* TODO??: move the data in the buffer back by the request header size */
2177  http, reply, localTempBuffer);
2178 
2179  return;
2180 }
2181 
2182 void
2184 {
2185  if (deleting)
2186  return;
2187 
2188  StoreEntry *entry = http->storeEntry();
2189 
2190  if (ConnStateData * conn = http->getConn()) {
2191  if (!conn->isOpen()) {
2192  debugs(33,3, "not sending more data to closing connection " << conn->clientConnection);
2193  return;
2194  }
2195  if (conn->pinning.zeroReply) {
2196  debugs(33,3, "not sending more data after a pinned zero reply " << conn->clientConnection);
2197  return;
2198  }
2199 
2200  if (reqofs==0 && !http->logType.isTcpHit()) {
2201  if (Ip::Qos::TheConfig.isHitTosActive()) {
2202  Ip::Qos::doTosLocalMiss(conn->clientConnection, http->request->hier.code);
2203  }
2204  if (Ip::Qos::TheConfig.isHitNfmarkActive()) {
2205  Ip::Qos::doNfmarkLocalMiss(conn->clientConnection, http->request->hier.code);
2206  }
2207  }
2208 
2209  debugs(88, 5, conn->clientConnection <<
2210  " '" << entry->url() << "'" <<
2211  " out.offset=" << http->out.offset);
2212  }
2213 
2214  char *buf = next()->readBuffer.data;
2215 
2216  if (buf != result.data) {
2217  /* we've got to copy some data */
2218  assert(result.length <= next()->readBuffer.length);
2219  memcpy(buf, result.data, result.length);
2220  }
2221 
2222  /* We've got the final data to start pushing... */
2224 
2225  reqofs += result.length;
2226 
2228 
2229  assert(http->request != NULL);
2230 
2231  /* ESI TODO: remove this assert once everything is stable */
2234 
2235  makeThisHead();
2236 
2237  debugs(88, 5, "clientReplyContext::sendMoreData: " << http->uri << ", " <<
2238  reqofs << " bytes (" << result.length <<
2239  " new bytes)");
2240 
2241  /* update size of the request */
2242  reqsize = reqofs;
2243 
2244  if (errorInStream(result, reqofs)) {
2245  sendStreamError(result);
2246  return;
2247  }
2248 
2249  if (flags.headersSent) {
2250  pushStreamData (result, buf);
2251  return;
2252  }
2253 
2254  cloneReply();
2255 
2256 #if USE_DELAY_POOLS
2257  if (sc)
2259 #endif
2260 
2261  holdingBuffer = result;
2263  return;
2264 }
2265 
2266 void
2268 {
2269  clientAclChecklistFill(checklist, http);
2270 }
2271 
2272 /* Using this breaks the client layering just a little!
2273  */
2274 void
2276 {
2277  assert(http != NULL);
2278  /*
2279  * For erroneous requests, we might not have a h->request,
2280  * so make a fake one.
2281  */
2282 
2283  if (http->request == NULL) {
2285  // XXX: These fake URI parameters shadow the real (or error:...) URI.
2286  // TODO: Either always set the request earlier and assert here OR use
2287  // http->uri (converted to Anyp::Uri) to create this catch-all request.
2288  const_cast<HttpRequest *&>(http->request) = new HttpRequest(m, AnyP::PROTO_NONE, "http", null_string, mx);
2290  }
2291 
2292  StoreEntry *e = storeCreateEntry(storeId(), http->log_uri, reqFlags, m);
2293 
2294  // Make entry collapsible ASAP, to increase collapsing chances for others,
2295  // TODO: every must-revalidate and similar request MUST reach the origin,
2296  // but do we have to prohibit others from collapsing on that request?
2297  if (reqFlags.cachable &&
2298  !reqFlags.needValidation &&
2299  (m == Http::METHOD_GET || m == Http::METHOD_HEAD) &&
2301  // make the entry available for future requests now
2302  (void)Store::Root().allowCollapsing(e, reqFlags, m);
2303  }
2304 
2305  sc = storeClientListAdd(e, this);
2306 
2307 #if USE_DELAY_POOLS
2309 #endif
2310 
2311  reqofs = 0;
2312 
2313  reqsize = 0;
2314 
2315  /* I don't think this is actually needed! -- adrian */
2316  /* http->reqbuf = http->norm_reqbuf; */
2317  // assert(http->reqbuf == http->norm_reqbuf);
2318  /* The next line is illegal because we don't know if the client stream
2319  * buffers have been set up
2320  */
2321  // storeClientCopy(http->sc, e, 0, HTTP_REQBUF_SZ, http->reqbuf,
2322  // SendMoreData, this);
2323  /* So, we mark the store logic as complete */
2325 
2326  /* and get the caller to request a read, from wherever they are */
2327  /* NOTE: after ANY data flows down the pipe, even one step,
2328  * this function CAN NOT be used to manage errors
2329  */
2330  http->storeEntry(e);
2331 }
2332 
2333 ErrorState *
2334 clientBuildError(err_type page_id, Http::StatusCode status, char const *url,
2335  Ip::Address &src_addr, HttpRequest * request, const AccessLogEntry::Pointer &al)
2336 {
2337  const auto err = new ErrorState(page_id, status, request, al);
2338  err->src_addr = src_addr;
2339 
2340  if (url)
2341  err->url = xstrdup(url);
2342 
2343  return err;
2344 }
2345 
@ initClient
HTTP or FTP client.
int hdr_sz
Definition: Message.h:82
HttpReplyPointer make304() const
Definition: HttpReply.cc:128
Definition: parse.c:104
@ LOG_TCP_IMS_HIT
Definition: LogTags.h:32
char method[16]
Definition: tcp-banger2.c:115
void refreshMask()
Definition: HttpHeader.cc:740
int storeClientIsThisAClient(store_client *sc, void *someClient)
static DelayId DelayClient(ClientHttpRequest *, HttpReply *reply=nullptr)
Definition: DelayId.cc:67
@ SURROGATE_CONTROL
@ METHOD_OTHER
Definition: MethodType.h:95
virtual void buffer()
Definition: store.cc:1647
size_type find(char c, size_type startPos=0) const
Definition: SBuf.cc:594
int getMyPort(void)
Definition: tools.cc:1003
void removeClientStoreReference(store_client **scp, ClientHttpRequest *http)
bool expectedBodyTooLarge(HttpRequest &request)
Definition: HttpReply.cc:525
time_t timestamp
Definition: Store.h:212
static void AddReplyAuthHeader(HttpReply *rep, UserRequest::Pointer auth_user_request, HttpRequest *request, int accelerated, int internal)
Add the appropriate [Proxy-]Authenticate header to the given reply.
Definition: UserRequest.cc:479
void ignoreRange(const char *reason)
forgets about the cached Range header (for a reason)
Definition: HttpRequest.cc:646
@ scUnauthorized
Definition: StatusCode.h:45
@ METHOD_HEAD
Definition: MethodType.h:28
StoreIOBuffer tempBuffer
const char * rawBuf() const
Definition: SquidString.h:85
dlink_node node
Definition: clientStream.h:88
AnyP::Uri url
the request URI
Definition: HttpRequest.h:115
Definition: ETag.h:17
@ scProcessing
Definition: StatusCode.h:24
ClientStreamData data
Definition: clientStream.h:94
int esiEnableProcessing(HttpReply *rep)
Definition: Esi.cc:2257
CachePeer * peer
Definition: client_side.h:144
ClientHttpRequest * http
void purgeFoundObject(StoreEntry *entry)
void ensureMemObject(const char *storeId, const char *logUri, const HttpRequestMethod &aMethod)
initialize mem_obj (if needed) and set URIs/method (if missing)
Definition: store.cc:1635
const char * storeId() const
Definition: MemObject.cc:54
CSS clientReplyStatus
@ VARY_NONE
Definition: enums.h:189
void releaseRequest(const bool shareable=false)
Definition: store.cc:452
void traceReply(clientStreamNode *node)
ACLFilledChecklist * clientAclChecklistCreate(const acl_access *acl, ClientHttpRequest *http)
@ scNone
Definition: StatusCode.h:21
bool needValidation
Definition: RequestFlags.h:46
struct ClientHttpRequest::Redirect redirect
unsigned char cache_key
Store key.
Definition: forward.h:29
@ METHOD_ENUM_END
Definition: MethodType.h:96
void removeHopByHopEntries()
Definition: HttpHeader.cc:1716
HttpHeader header
Definition: Message.h:75
LogTags logType
the processing tags associated with this request transaction.
void ipcacheInvalidate(const char *name)
Definition: ipcache.cc:856
void errorAppendEntry(StoreEntry *entry, ErrorState *err)
Definition: errorpage.cc:711
bool isEmpty() const
Definition: SBuf.h:420
MemObject * mem_obj
Definition: Store.h:209
RequestFlags flags
Definition: HttpRequest.h:141
void sendNotModifiedOrPreconditionFailedError()
int varyEvaluateMatch(StoreEntry *entry, HttpRequest *request)
int fdUsageHigh(void)
Definition: fd.cc:301
ssize_t HttpHeaderPos
Definition: HttpHeader.h:45
const cache_key * storeKeyPublic(const char *url, const HttpRequestMethod &method, const KeyScope keyScope)
void clearPublicKeyScope()
Definition: store.cc:633
bool isTcpHit() const
determine if the log tag code indicates a cache HIT
Definition: LogTags.cc:91
struct node * next
Definition: parse.c:105
const char * url() const
Definition: store.cc:1612
ConnStateData * getConn() const
@ PROTO_NONE
Definition: ProtocolType.h:24
void createStoreEntry(const HttpRequestMethod &m, RequestFlags flags)
@ STREAM_NONE
Definition: enums.h:122
virtual void fillChecklist(ACLFilledChecklist &) const
configure the ACL checklist with the current transaction state
@ ksRevalidation
Definition: store_key_md5.h:20
static bool SmpAware()
whether there are any SMP-aware storages
Definition: Controller.cc:887
MemObject & mem()
Definition: Store.h:52
static void getPublicByRequest(StoreClient *aClient, HttpRequest *request)
Definition: store.cc:508
@ ERR_NONE
Definition: err_type.h:13
#define HttpHeaderInitPos
Definition: HttpHeader.h:48
void purgeFoundGet(StoreEntry *newEntry)
void lock(const char *context)
Definition: store.cc:439
void ipcacheInvalidateNegative(const char *name)
Definition: ipcache.cc:873
struct SquidConfig::@113 accessList
bool loopDetected
Definition: RequestFlags.h:36
int doTosLocalMiss(const Comm::ConnectionPointer &conn, const hier_code hierCode)
Definition: QosConfig.cc:214
void httpHdrMangleList(HttpHeader *l, HttpRequest *request, const AccessLogEntryPointer &al, req_or_rep_t req_or_rep)
HttpReplyPointer reply
int64_t bodySize(const HttpRequestMethod &) const
Definition: HttpReply.cc:375
int64_t offset
Definition: StoreIOBuffer.h:55
Definition: SBuf.h:86
char tempbuf[HTTP_REQBUF_SZ]
a temporary buffer if we need working storage
const char * str
quoted-string
Definition: ETag.h:20
#define xstrdup
void sendStreamError(StoreIOBuffer const &result)
void removeStoreReference(store_client **scp, StoreEntry **ep)
struct ClientHttpRequest::Flags flags
@ LOG_TCP_CLIENT_REFRESH_MISS
Definition: LogTags.h:31
clientStream_status_t CSS(clientStreamNode *, ClientHttpRequest *)
@ ERR_ONLY_IF_CACHED_MISS
Definition: err_type.h:37
struct ClientHttpRequest::Out out
C * getRaw() const
Definition: RefCount.h:80
uint16_t flags
Definition: Store.h:220
int cbdataReferenceValid(const void *p)
Definition: cbdata.cc:412
bool IsConnOpen(const Comm::ConnectionPointer &conn)
Definition: Connection.cc:26
Http::StatusLine sline
Definition: HttpReply.h:60
time_t expires
Definition: Store.h:214
void HTTPMSGUNLOCK(M *&a)
Definition: Message.h:149
int64_t objectLen() const
Definition: Store.h:248
void replaceHttpReply(const HttpReplyPointer &, const bool andStartWriting=true)
Definition: store.cc:1772
#define DBG_CRITICAL
Definition: Debug.h:45
@ STREAM_COMPLETE
Definition: enums.h:123
StatusCode
Definition: StatusCode.h:20
Definition: forward.h:21
CSS esiStreamStatus
void purgeDoPurgeGet(StoreEntry *entry)
#define cbdataReference(var)
Definition: cbdata.h:341
Http::StatusCode purgeStatus
CSD esiStreamDetach
static void Start(const Comm::ConnectionPointer &client, StoreEntry *, HttpRequest *, const AccessLogEntryPointer &alp)
Initiates request forwarding to a peer or origin server.
Definition: FwdState.cc:341
@ LOG_TCP_HIT
Definition: LogTags.h:24
@ IF_MODIFIED_SINCE
#define DBG_IMPORTANT
Definition: Debug.h:46
bool conditional() const
has at least one recognized If-* header
Definition: HttpRequest.cc:597
void httpHeaderPutStrf(HttpHeader *hdr, Http::HdrType id, const char *fmt,...)
StoreEntry * storeGetPublicByRequest(HttpRequest *req, const KeyScope keyScope)
Definition: store.cc:534
AclDenyInfoList * denyInfoList
Definition: SquidConfig.h:412
@ LOG_TCP_MISS
Definition: LogTags.h:25
int refreshCheckHTTP(const StoreEntry *entry, HttpRequest *request)
Definition: refresh.cc:584
StoreIOBuffer holdingBuffer
bool allowCollapsing(StoreEntry *, const RequestFlags &, const HttpRequestMethod &)
tries to make the entry available for collapsing future requests
Definition: Controller.cc:725
CollapsedRevalidation collapsedRevalidation
class AccessLogEntry::HttpDetails http
@ STREAM_FAILED
Definition: enums.h:133
void sendPreconditionFailedError()
send 412 (Precondition Failed) to client
@ LOG_TCP_REFRESH_FAIL_OLD
Definition: LogTags.h:27
const char * c_str() const
compute the status access.log field
Definition: LogTags.cc:56
AnyP::ProtocolType protocol
Definition: StatusLine.h:68
bool noCacheHack() const
Definition: RequestFlags.h:124
void clientStreamDetach(clientStreamNode *thisObject, ClientHttpRequest *http)
HttpReply * clone() const
Definition: HttpReply.cc:573
@ ENTRY_BAD_LENGTH
Definition: enums.h:110
@ ENTRY_SPECIAL
Definition: enums.h:80
@ scGatewayTimeout
Definition: StatusCode.h:75
@ WWW_AUTHENTICATE
class SquidConfig2 Config2
Definition: SquidConfig.cc:14
bool persistent() const
Definition: Message.cc:261
time_t lastmod
Definition: HttpRequest.h:168
void removeIrrelevantContentLength()
Some response status codes prohibit sending Content-Length (RFC 7230 section 3.3.2).
Definition: HttpReply.cc:672
bool streamError
Definition: RequestFlags.h:92
@ HTCP_CLR_INVALIDATION
Definition: enums.h:239
const char * AclMatchedName
Definition: Acl.cc:30
void update(const LogTags_ot t)
Definition: LogTags.cc:44
@ LOG_TCP_DENIED_REPLY
Definition: LogTags.h:38
String etag
A strong etag of the cached entry. Used for refreshing that entry.
Definition: HttpRequest.h:192
acl_access * sendHit
Definition: SquidConfig.h:371
@ crSlave
we collapsed on the existing revalidation request
#define NULL
Definition: types.h:166
bool mayStartHitting() const
Definition: Store.h:279
bool requestSatisfactionMode() const
void startError(ErrorState *err)
@ scSwitchingProtocols
Definition: StatusCode.h:23
void CSD(clientStreamNode *, ClientHttpRequest *)
client stream detach
@ LOG_TCP_REFRESH_FAIL_ERR
Definition: LogTags.h:28
bool hasIfNoneMatchEtag(const HttpRequest &request) const
has ETag matching at least one of the If-None-Match etags
Definition: store.cc:1931
void CSR(clientStreamNode *, ClientHttpRequest *)
client stream read
@ scForbidden
Definition: StatusCode.h:47
err_type aclGetDenyInfoPage(AclDenyInfoList **head, const char *name, int redirect_allowed)
Definition: Gadgets.cc:41
bool errorInStream(StoreIOBuffer const &result, size_t const &sizeToProcess) const
#define debugs(SECTION, LEVEL, CONTENT)
Definition: Debug.h:128
@ IN_MEMORY
Definition: enums.h:36
void purgeDoPurgeHead(StoreEntry *entry)
void cacheHit(StoreIOBuffer result)
void sendMoreData(StoreIOBuffer result)
@ scPreconditionFailed
Definition: StatusCode.h:56
Http::StatusCode status() const
retrieve the status code for this status line
Definition: StatusLine.h:45
@ scNotImplemented
Definition: StatusCode.h:72
const HttpReply & baseReply() const
Definition: MemObject.h:60
void setNoAddr()
Definition: Address.cc:292
int clientHttpRequestStatus(int fd, ClientHttpRequest const *http)
@ LOG_TCP_REFRESH_MODIFIED
Definition: LogTags.h:29
@ HTCP_CLR_PURGE
Definition: enums.h:238
bool mayInitiateCollapsing() const
whether Squid configuration allows us to become a CF initiator
Definition: StoreClient.h:52
void pushStreamData(StoreIOBuffer const &result, char *source)
const Acl::Answer & fastCheck()
Definition: Checklist.cc:336
#define HTTP_REQBUF_SZ
Definition: defines.h:216
void setReplyToReply(HttpReply *reply)
creates a store entry for the reply and appends error reply to it
int doNfmarkLocalHit(const Comm::ConnectionPointer &conn)
Definition: QosConfig.cc:263
#define SQUIDCEXTERN
Definition: squid.h:26
void putWarning(const int code, const char *const text)
add a Warning header
Definition: HttpHeader.cc:1121
unsigned error
Definition: StoreIOBuffer.h:52
virtual LogTags * loggingTags()
void setReplyToStoreEntry(StoreEntry *e, const char *reason)
replaces current response store entry with the given one
@ STREAM_UNPLANNED_COMPLETE
Definition: enums.h:128
struct StoreIOBuffer::@148 flags
#define EBIT_TEST(flag, bit)
Definition: defines.h:107
int collapsed_forwarding
Definition: SquidConfig.h:329
bool failOnValidationError
Definition: RequestFlags.h:48
int error_pconns
Definition: SquidConfig.h:311
void setReplyToError(err_type, Http::StatusCode, const HttpRequestMethod &, char const *, Ip::Address &, HttpRequest *, const char *, Auth::UserRequest::Pointer)
builds error using clientBuildError() and calls setReplyToError() below
std::ostream & HERE(std::ostream &s)
Definition: Debug.h:157
void handleIMSReply(StoreIOBuffer result)
virtual void evictIfFound(const cache_key *) override
Definition: Controller.cc:480
AccessLogEntry::Pointer al
access.log entry
clientStream_status_t replyStatus()
bool startCollapsingOn(const StoreEntry &, const bool doingRevalidation)
Definition: store_client.cc:66
int delById(Http::HdrType id)
Definition: HttpHeader.cc:684
Http::HdrType id
Definition: HttpHeader.h:63
err_type
Definition: err_type.h:12
void const char HLPCB void * data
Definition: stub_helper.cc:16
struct clientReplyContext::Flags flags
void putExt(const char *name, const char *value)
Definition: HttpHeader.cc:1130
int unlock(const char *context)
Definition: store.cc:463
void purgeEntriesByUrl(HttpRequest *req, const char *url)
int64_t getInt64(Http::HdrType id) const
Definition: HttpHeader.cc:1151
#define safe_free(x)
Definition: xalloc.h:73
@ LOG_TCP_REFRESH_UNMODIFIED
Definition: LogTags.h:26
Ip::Address remote
Definition: Connection.h:152
store_status_t store_status
Definition: Store.h:232
int weak
true if it is a weak validator
Definition: ETag.h:21
struct SquidConfig2::@127 onoff
void putTime(Http::HdrType id, time_t htime)
Definition: HttpHeader.cc:1032
int conn
the current server connection FD
Definition: Transport.cc:26
#define assert(EX)
Definition: assert.h:19
CSR esiStreamRead
@ scContinue
Definition: StatusCode.h:22
clientReplyContext(ClientHttpRequest *)
int storeOKTransferDone() const
HierarchyLogEntry hier
Definition: HttpRequest.h:157
int checkNegativeHit() const
Definition: store.cc:1341
void HTTPMSGLOCK(Http::Message *a)
Definition: Message.h:160
void neighborsHtcpClear(StoreEntry *e, HttpRequest *req, const HttpRequestMethod &method, htcp_clr_reason reason)
Definition: neighbors.cc:1814
@ TRANSFER_ENCODING
SBuf vary_headers
The variant second-stage cache key. Generated from Vary header pattern for this request.
Definition: HttpRequest.h:171
const AnyP::UriScheme & getScheme() const
Definition: Uri.h:67
@ METHOD_TRACE
Definition: MethodType.h:30
#define cbdataReferenceDone(var)
Definition: cbdata.h:350
CSCB esiProcessStream
void redirect(Http::StatusCode, const char *)
Definition: HttpReply.cc:203
@ scInternalServerError
Definition: StatusCode.h:71
HttpHdrRange * range
Definition: HttpRequest.h:143
ErrorState * clientBuildError(err_type, Http::StatusCode, char const *, Ip::Address &, HttpRequest *, const AccessLogEntry::Pointer &)
class LogTags::Errors err
SQUIDCEXTERN CSD clientReplyDetach
mem_status_t mem_status
Definition: Store.h:228
static int sc[16]
Definition: smbdes.c:121
const char * null_string
const char * c_str()
Definition: SBuf.cc:526
@ LOG_TCP_REFRESH
Definition: LogTags.h:30
#define CBDATA_CLASS_INIT(type)
Definition: cbdata.h:318
int prefixLen() const
Definition: HttpRequest.cc:372
void dump(int debug_lvl) const
Definition: store.cc:1545
@ ERR_PRECONDITION_FAILED
Definition: err_type.h:45
@ STORE_OK
Definition: enums.h:46
time_t squid_curtime
Definition: stub_time.cc:17
Comm::ConnectionPointer clientConnection
Definition: Server.h:97
@ crInitiator
we initiated collapsed revalidation request
uint64_t size
Response header and body bytes written to the client connection.
@ LOG_TCP_INM_HIT
Definition: LogTags.h:33
StoreEntry * storeCreateEntry(const char *url, const char *logUrl, const RequestFlags &flags, const HttpRequestMethod &method)
Definition: store.cc:783
int64_t content_length
Definition: Message.h:84
@ VARY_OTHER
Definition: enums.h:191
struct SquidConfig::@112 onoff
int client_pconns
Definition: SquidConfig.h:309
bool receivedBodyTooLarge(HttpRequest &, int64_t receivedBodySize)
Definition: HttpReply.cc:517
@ scNotModified
Definition: StatusCode.h:40
void clientAclChecklistFill(ACLFilledChecklist &checklist, ClientHttpRequest *http)
bool chunkedReply
Definition: RequestFlags.h:90
static const size_type npos
Definition: SBuf.h:92
clientStreamNode * getNextNode() const
void clientStreamInsertHead(dlink_list *list, CSR *func, CSCB *callback, CSD *detach, CSS *status, ClientStreamData data)
@ METHOD_PURGE
Definition: MethodType.h:94
bool proxyKeepalive
Definition: RequestFlags.h:38
void complete()
Definition: store.cc:1058
static void getPublicByRequestMethod(StoreClient *aClient, HttpRequest *request, const HttpRequestMethod &method)
Definition: store.cc:501
@ PROTO_HTTPS
Definition: ProtocolType.h:27
void putInt(Http::HdrType id, int number)
Definition: HttpHeader.cc:1014
HttpRequestMethod method
Definition: HttpRequest.h:114
Config TheConfig
Globally available instance of Qos::Config.
Definition: QosConfig.cc:271
@ scNotFound
Definition: StatusCode.h:48
acl_access * reply
Definition: SquidConfig.h:383
HttpHeaderEntry * findEntry(Http::HdrType id) const
Definition: HttpHeader.cc:620
@ ENTRY_ABORTED
Definition: enums.h:111
bool blockedHit() const
whether squid.conf send_hit prevents us from serving this hit
@ PROTO_HTTP
Definition: ProtocolType.h:25
const char * termedBuf() const
Definition: SquidString.h:91
@ LOG_TCP_DENIED
Definition: LogTags.h:37
int doNfmarkLocalMiss(const Comm::ConnectionPointer &conn, const hier_code hierCode)
Definition: QosConfig.cc:235
bool allowed() const
Definition: Acl.h:143
@ VARY_MATCH
Definition: enums.h:190
const char * storeId() const
int cmp(const SBuf &S, const size_type n) const
shorthand version for compare()
Definition: SBuf.h:264
AnyP::ProtocolVersion version
breakdown of protocol version label: (HTTP/ICY) and (0.9/1.0/1.1)
Definition: StatusLine.h:70
void updateOnNotModified(StoreEntry *old, StoreEntry &e304)
using a 304 response, update the old entry (metadata and reply headers)
Definition: Controller.cc:692
bool timestampsSet()
Definition: store.cc:1438
@ LOG_TCP_OFFLINE_HIT
Definition: LogTags.h:39
@ scNoContent
Definition: StatusCode.h:30
@ PROXY_AUTHENTICATE
int has(Http::HdrType id) const
Definition: HttpHeader.cc:980
const SBuf storeId()
Definition: HttpRequest.cc:694
int storeNotOKTransferDone() const
bool processConditional(StoreIOBuffer &result)
process conditional request from client
void putStr(Http::HdrType id, const char *str)
Definition: HttpHeader.cc:1041
const char * getMyHostname(void)
Definition: tools.cc:412
@ METHOD_NONE
Definition: MethodType.h:22
@ ERR_TOO_BIG
Definition: err_type.h:38
@ crNone
collapsed revalidation is not allowed for this context
size_t HttpReply *STUB StoreEntry const KeyScope scope const HttpRequestMethod & method
Definition: stub_store.cc:108
@ ERR_ACCESS_DENIED
Definition: err_type.h:16
clientStream_status_t
Definition: enums.h:121
#define Must(condition)
Like assert() but throws an exception instead of aborting the process.
Definition: TextException.h:69
bool alwaysAllowResponse(Http::StatusCode sline) const
@ SURROGATE_CAPABILITY
@ ACCESS_ALLOWED
Definition: Acl.h:104
@ VARY_CANCEL
Definition: enums.h:192
@ scProxyAuthenticationRequired
Definition: StatusCode.h:51
const char * storeKeyText(const cache_key *key)
LogTags_ot oldType
a set of client protocol, cache use, and other transaction outcome tags
Definition: LogTags.h:84
time_t ims
Definition: HttpRequest.h:145
StoreEntry * storeGetPublic(const char *uri, const HttpRequestMethod &method)
Definition: store.cc:522
void release(const bool shareable=false)
Definition: store.cc:1186
#define PRId64
Definition: types.h:110
const HttpReply & freshestReply() const
Definition: MemObject.h:68
void purgeFoundHead(StoreEntry *newEntry)
int shutting_down
@ LOG_TCP_REDIRECT
Definition: LogTags.h:40
store_client * old_sc
int doTosLocalHit(const Comm::ConnectionPointer &conn)
Definition: QosConfig.cc:256
clientStreamNode * next() const
void lastModified(const time_t when)
Definition: Store.h:164
void clientStreamCallback(clientStreamNode *thisObject, ClientHttpRequest *http, HttpReply *rep, StoreIOBuffer replyBuffer)
StoreIOBuffer readBuffer
Definition: clientStream.h:95
void delAt(HttpHeaderPos pos, int &headers_deleted)
Definition: HttpHeader.cc:712
static ACLCB ProcessReplyAccessResult
void setHeaders(Http::StatusCode status, const char *reason, const char *ctype, int64_t clen, time_t lmt, time_t expires)
Definition: HttpReply.cc:168
void sendNotModified()
send 304 (Not Modified) to client
StoreEntry * storeEntry() const
void processReplyAccessResult(const Acl::Answer &accessAllowed)
bool ignored
_IGNORED: the response was not used for anything
Definition: LogTags.h:72
StoreEntry * loggingEntry() const
@ scOkay
Definition: StatusCode.h:26
clientStreamNode * ourNode
void swapOut(StoreEntry *e)
Definition: HttpRequest.cc:337
HttpHeaderEntry * getEntry(HttpHeaderPos *pos) const
Definition: HttpHeader.cc:601
@ METHOD_GET
Definition: MethodType.h:25
void setDelayId(DelayId delay_id)
void * callback_data
Definition: errorpage.h:188
bool modifiedSince(const time_t ims, const int imslen=-1) const
Definition: store.cc:1887
MemObject * memObject() const
static STCB SendMoreData
@ LOG_TCP_MEM_HIT
Definition: LogTags.h:36
int storeUnregister(store_client *sc, StoreEntry *e, void *data)
#define false
Definition: GnuRegex.c:233
const SBuf & effectiveRequestUri() const
RFC 7230 section 5.5 - Effective Request URI.
Definition: HttpRequest.cc:705
unsigned complete
we have read all we can from upstream
void addVia(const AnyP::ProtocolVersion &ver, const HttpHeader *from=0)
Definition: HttpHeader.cc:988
bool hasIfMatchEtag(const HttpRequest &request) const
has ETag matching at least one of the If-Match etags
Definition: store.cc:1924
void storeClientCopy(store_client *sc, StoreEntry *e, StoreIOBuffer copyInto, STCB *callback, void *data)
bool hasEtag(ETag &etag) const
whether this entry has an ETag; if yes, puts ETag value into parameter
Definition: store.cc:1913
void host(const char *src)
Definition: Uri.cc:98
const char * lookup_type
struct _request * request(char *urlin)
Definition: tcp-banger2.c:291
static STCB HandleIMSReply
short int keep_alive
Definition: HttpReply.h:57
virtual void created(StoreEntry *newEntry)
void nonBlockingCheck(ACLCB *callback, void *callback_data)
Definition: Checklist.cc:238
void identifyFoundObject(StoreEntry *entry)
void const char * buf
Definition: stub_helper.cc:16
@ LOG_TCP_SWAPFAIL_MISS
Definition: LogTags.h:34
Http::StatusCode httpStatus
Definition: errorpage.h:174
void storeErrorResponse(HttpReply *reply)
Store a prepared error response. MemObject locks the reply object.
Definition: store.cc:1755
@ LOG_TCP_NEGATIVE_HIT
Definition: LogTags.h:35
CbcPointer< ConnStateData > clientConnectionManager
Definition: HttpRequest.h:233
SQUIDCEXTERN CSR clientGetMoreData
@ ROR_REPLY
class SquidConfig Config
Definition: SquidConfig.cc:12
store_client * storeClientListAdd(StoreEntry *e, void *data)
HttpRequest *const request
void clean()
Definition: String.cc:125
AnyP::ProtocolVersion ProtocolVersion(unsigned int aMajor, unsigned int aMinor)
HTTP version label information.
Controller & Root()
safely access controller singleton
Definition: Controller.cc:905

 

Introduction

Documentation

Support

Miscellaneous

Web Site Translations

Mirrors