client_side_reply.cc
Go to the documentation of this file.
1 /*
2  * Copyright (C) 1996-2019 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 
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
86 #endif
87  ourNode(NULL),
88  reply(NULL),
89  old_entry(NULL),
90  old_sc(NULL),
91  old_lastmod(-1),
92  deleting(false),
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 
136  createStoreEntry(method, RequestFlags());
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");
151  method = http->request->method;
152  }
153 
154  createStoreEntry(method, RequestFlags());
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  const Http::StatusCode status = http->storeEntry()->getReply()->sline.status();
446 
447  // request to origin was aborted
449  debugs(88, 3, "request to origin aborted '" << http->storeEntry()->url() << "', sending old entry to client");
452  }
453 
454  const HttpReply *old_rep = old_entry->getReply();
455 
456  // origin replied 304
457  if (status == Http::scNotModified) {
459  http->request->flags.staleIfHit = false; // old_entry is no longer stale
460 
461  // update headers on existing entry
463 
464  // if client sent IMS
465 
467  // forward the 304 from origin
468  debugs(88, 3, "origin replied 304, revalidating existing entry and forwarding 304 to client");
470  } else {
471  // send existing entry, it's still valid
472  debugs(88, 3, "origin replied 304, revalidating existing entry and sending " <<
473  old_rep->sline.status() << " to client");
475  }
476  }
477 
478  // origin replied with a non-error code
479  else if (status > Http::scNone && status < Http::scInternalServerError) {
480  const HttpReply *new_rep = http->storeEntry()->getReply();
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_rep)) {
484  http->logType.err.ignored = true;
485  debugs(88, 3, "origin replied " << status <<
486  " but with an older date header, sending old entry (" <<
487  old_rep->sline.status() << ") 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 (" << old_rep->sline.status() << ") to client");
513  }
514 }
515 
518 
526 void
528 {
529  clientReplyContext *context = (clientReplyContext *)data;
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 unsharable!
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, "unsharable " << *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  HttpReply *rep = new HttpReply;
786  http->storeEntry()->complete();
787  return;
788  }
789 
791 
793  FwdState::Start(conn, http->storeEntry(), r, http->al);
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  if (e->getReply()->sline.status() != Http::scOkay) {
824  debugs(88, 4, "Reply code " << e->getReply()->sline.status() << " != 200");
826  processMiss();
827  return true;
828  }
829 
830  HttpRequest &r = *http->request;
831 
833  // RFC 2616: reply with 412 Precondition Failed if If-Match did not match
835  return true;
836  }
837 
839  // RFC 7232: If-None-Match recipient MUST ignore IMS
840  r.flags.ims = false;
841  r.ims = -1;
842  r.imslen = 0;
844 
845  if (e->hasIfNoneMatchEtag(r)) {
847  return true;
848  }
849 
850  // None-Match is true (no ETag matched); treat as an unconditional hit
851  return false;
852  }
853 
854  if (r.flags.ims) {
855  // handle If-Modified-Since requests from the client
856  if (e->modifiedSince(r.ims, r.imslen)) {
857  // Modified-Since is true; treat as an unconditional hit
858  return false;
859 
860  } else {
861  // otherwise reply with 304 Not Modified
862  sendNotModified();
863  }
864  return true;
865  }
866 
867  return false;
868 }
869 
871 bool
873 {
875  return false; // hits are not blocked by default
876 
877  if (http->flags.internal)
878  return false; // internal content "hits" cannot be blocked
879 
880  if (const HttpReply *rep = http->storeEntry()->getReply()) {
881  std::unique_ptr<ACLFilledChecklist> chl(clientAclChecklistCreate(Config.accessList.sendHit, http));
882  chl->reply = const_cast<HttpReply*>(rep); // ACLChecklist API bug
883  HTTPMSGLOCK(chl->reply);
884  return !chl->fastCheck().allowed(); // when in doubt, block
885  }
886 
887  // This does not happen, I hope, because we are called from CacheHit, which
888  // is called via a storeClientCopy() callback, and store should initialize
889  // the reply before calling that callback.
890  debugs(88, 3, "Missing reply!");
891  return false;
892 }
893 
894 void
896 {
897  /* Try to find a base entry */
898  http->flags.purging = true;
899  lookingforstore = 1;
900 
901  // TODO: can we use purgeAllCached() here instead of doing the
902  // getPublicByRequestMethod() dance?
904 }
905 
906 // Purges all entries with a given url
907 // TODO: move to SideAgent parent, when we have one
908 /*
909  * We probably cannot purge Vary-affected responses because their MD5
910  * keys depend on vary headers.
911  */
912 void
913 purgeEntriesByUrl(HttpRequest * req, const char *url)
914 {
916  if (m.respMaybeCacheable()) {
917  const cache_key *key = storeKeyPublic(url, m);
918  debugs(88, 5, m << ' ' << url << ' ' << storeKeyText(key));
919 #if USE_HTCP
920  neighborsHtcpClear(nullptr, url, req, m, HTCP_CLR_INVALIDATION);
921 #endif
922  Store::Root().evictIfFound(key);
923  }
924  }
925 }
926 
927 void
929 {
930  // XXX: performance regression, c_str() reallocates
932  purgeEntriesByUrl(http->request, url.c_str());
933 }
934 
935 void
937 {
938  if (lookingforstore == 1)
939  purgeFoundGet(newEntry);
940  else if (lookingforstore == 2)
941  purgeFoundHead(newEntry);
942  else if (lookingforstore == 3)
943  purgeDoPurgeGet(newEntry);
944  else if (lookingforstore == 4)
945  purgeDoPurgeHead(newEntry);
946  else if (lookingforstore == 5)
947  identifyFoundObject(newEntry);
948 }
949 
950 LogTags *
952 {
953  // XXX: clientReplyContext code assumes that http cbdata is always valid.
954  // TODO: Either add cbdataReferenceValid(http) checks in all the relevant
955  // places, like this one, or remove cbdata protection of the http member.
956  return &http->logType;
957 }
958 
959 void
961 {
962  if (!newEntry) {
963  lookingforstore = 2;
965  } else
966  purgeFoundObject (newEntry);
967 }
968 
969 void
971 {
972  if (!newEntry)
974  else
975  purgeFoundObject (newEntry);
976 }
977 
978 void
980 {
981  assert (entry);
982 
983  if (EBIT_TEST(entry->flags, ENTRY_SPECIAL)) {
985  Ip::Address tmp_noaddr;
986  tmp_noaddr.setNoAddr(); // TODO: make a global const
988  http->getConn() ? http->getConn()->clientConnection->remote : tmp_noaddr,
989  http->request, http->al);
990  startError(err);
991  return; // XXX: leaking unused entry if some store does not keep it
992  }
993 
994  StoreIOBuffer localTempBuffer;
995  /* Swap in the metadata */
996  http->storeEntry(entry);
997 
998  http->storeEntry()->lock("clientReplyContext::purgeFoundObject");
1000  http->request->method);
1001 
1002  sc = storeClientListAdd(http->storeEntry(), this);
1003 
1005 
1006  reqofs = 0;
1007 
1008  localTempBuffer.offset = http->out.offset;
1009 
1010  localTempBuffer.length = next()->readBuffer.length;
1011 
1012  localTempBuffer.data = next()->readBuffer.data;
1013 
1015  localTempBuffer, CacheHit, this);
1016 }
1017 
1018 void
1020 {
1021  debugs(88, 3, "Config2.onoff.enable_purge = " <<
1023 
1024  if (!Config2.onoff.enable_purge) {
1026  Ip::Address tmp_noaddr;
1027  tmp_noaddr.setNoAddr();
1029  http->getConn() ? http->getConn()->clientConnection->remote : tmp_noaddr, http->request, http->al);
1030  startError(err);
1031  return;
1032  }
1033 
1034  /* Release both IP cache */
1036 
1037  if (!http->flags.purging)
1039  else
1040  purgeDoMissPurge();
1041 }
1042 
1043 void
1045 {
1047  lookingforstore = 3;
1049 }
1050 
1051 void
1053 {
1054  if (newEntry) {
1055  /* Move to new() when that is created */
1057  /* Release the cached URI */
1058  debugs(88, 4, "clientPurgeRequest: GET '" << newEntry->url() << "'" );
1059 #if USE_HTCP
1061 #endif
1062  newEntry->release(true);
1064  }
1065 
1066  lookingforstore = 4;
1068 }
1069 
1070 void
1072 {
1073  if (newEntry) {
1074  debugs(88, 4, "HEAD " << newEntry->url());
1075 #if USE_HTCP
1077 #endif
1078  newEntry->release(true);
1080  }
1081 
1082  /* And for Vary, release the base URI if none of the headers was included in the request */
1083  if (!http->request->vary_headers.isEmpty()
1084  && http->request->vary_headers.find('=') != SBuf::npos) {
1085  // XXX: performance regression, c_str() reallocates
1087  StoreEntry *entry = storeGetPublic(tmp.c_str(), Http::METHOD_GET);
1088 
1089  if (entry) {
1090  debugs(88, 4, "Vary GET " << entry->url());
1091 #if USE_HTCP
1093 #endif
1094  entry->release(true);
1096  }
1097 
1098  entry = storeGetPublic(tmp.c_str(), Http::METHOD_HEAD);
1099 
1100  if (entry) {
1101  debugs(88, 4, "Vary HEAD " << entry->url());
1102 #if USE_HTCP
1104 #endif
1105  entry->release(true);
1107  }
1108  }
1109 
1110  /*
1111  * Make a new entry to hold the reply to be written
1112  * to the client.
1113  */
1114  /* FIXME: This doesn't need to go through the store. Simply
1115  * push down the client chain
1116  */
1118 
1120 
1121  HttpReply *rep = new HttpReply;
1122  rep->setHeaders(purgeStatus, NULL, NULL, 0, 0, -1);
1123  http->storeEntry()->replaceHttpReply(rep);
1124  http->storeEntry()->complete();
1125 }
1126 
1127 void
1129 {
1130  clientStreamNode *nextNode = (clientStreamNode *)node->node.next->data;
1131  StoreIOBuffer localTempBuffer;
1133  localTempBuffer.offset = nextNode->readBuffer.offset + headers_sz;
1134  localTempBuffer.length = nextNode->readBuffer.length;
1135  localTempBuffer.data = nextNode->readBuffer.data;
1137  localTempBuffer, SendMoreData, this);
1139  http->storeEntry()->buffer();
1140  HttpReply *rep = new HttpReply;
1141  rep->setHeaders(Http::scOkay, NULL, "text/plain", http->request->prefixLen(), 0, squid_curtime);
1142  http->storeEntry()->replaceHttpReply(rep);
1144  http->storeEntry()->complete();
1145 }
1146 
1147 #define SENDING_BODY 0
1148 #define SENDING_HDRSONLY 1
1149 int
1151 {
1152  StoreEntry *entry = http->storeEntry();
1153 
1154  if (entry == NULL)
1155  return 0;
1156 
1157  /*
1158  * For now, 'done_copying' is used for special cases like
1159  * Range and HEAD requests.
1160  */
1161  if (http->flags.done_copying)
1162  return 1;
1163 
1165  // last-chunk was not sent
1166  return 0;
1167  }
1168 
1169  /*
1170  * Handle STORE_OK objects.
1171  * objectLen(entry) will be set proprely.
1172  * RC: Does objectLen(entry) include the Headers?
1173  * RC: Yes.
1174  */
1175  if (entry->store_status == STORE_OK) {
1176  return storeOKTransferDone();
1177  } else {
1178  return storeNotOKTransferDone();
1179  }
1180 }
1181 
1182 int
1184 {
1185  assert(http->storeEntry()->objectLen() >= 0);
1187  if (http->out.offset >= http->storeEntry()->objectLen() - headers_sz) {
1188  debugs(88,3,HERE << "storeOKTransferDone " <<
1189  " out.offset=" << http->out.offset <<
1190  " objectLen()=" << http->storeEntry()->objectLen() <<
1191  " headers_sz=" << headers_sz);
1192  return 1;
1193  }
1194 
1195  return 0;
1196 }
1197 
1198 int
1200 {
1201  /*
1202  * Now, handle STORE_PENDING objects
1203  */
1204  MemObject *mem = http->storeEntry()->mem_obj;
1205  assert(mem != NULL);
1206  assert(http->request != NULL);
1207 
1208  /* mem->reply was wrong because it uses the UPSTREAM header length!!! */
1209  if (headers_sz == 0)
1210  /* haven't found end of headers yet */
1211  return 0;
1212 
1213  const HttpReplyPointer curReply(mem->getReply());
1214 
1215  /*
1216  * Figure out how much data we are supposed to send.
1217  * If we are sending a body and we don't have a content-length,
1218  * then we must wait for the object to become STORE_OK.
1219  */
1220  if (curReply->content_length < 0)
1221  return 0;
1222 
1223  uint64_t expectedLength = curReply->content_length + http->out.headers_sz;
1224 
1225  if (http->out.size < expectedLength)
1226  return 0;
1227  else {
1228  debugs(88,3,HERE << "storeNotOKTransferDone " <<
1229  " out.size=" << http->out.size <<
1230  " expectedLength=" << expectedLength);
1231  return 1;
1232  }
1233 }
1234 
1235 /* A write has completed, what is the next status based on the
1236  * canonical request data?
1237  * 1 something is wrong
1238  * 0 nothing is wrong.
1239  *
1240  */
1241 int
1243 {
1244 #if SIZEOF_INT64_T == 4
1245  if (http->out.size > 0x7FFF0000) {
1246  debugs(88, DBG_IMPORTANT, "WARNING: closing FD " << fd << " to prevent out.size counter overflow");
1247  if (http->getConn())
1248  debugs(88, DBG_IMPORTANT, "\tclient " << http->getConn()->peer);
1249  debugs(88, DBG_IMPORTANT, "\treceived " << http->out.size << " bytes");
1250  debugs(88, DBG_IMPORTANT, "\tURI " << http->log_uri);
1251  return 1;
1252  }
1253 
1254  if (http->out.offset > 0x7FFF0000) {
1255  debugs(88, DBG_IMPORTANT, "WARNING: closing FD " << fd < " to prevent out.offset counter overflow");
1256  if (http->getConn())
1257  debugs(88, DBG_IMPORTANT, "\tclient " << http->getConn()->peer);
1258  debugs(88, DBG_IMPORTANT, "\treceived " << http->out.size << " bytes, offset " << http->out.offset);
1259  debugs(88, DBG_IMPORTANT, "\tURI " << http->log_uri);
1260  return 1;
1261  }
1262 
1263 #endif
1264  return 0;
1265 }
1266 
1267 /* Preconditions:
1268  * *http is a valid structure.
1269  * fd is either -1, or an open fd.
1270  *
1271  * TODO: enumify this
1272  *
1273  * This function is used by any http request sink, to determine the status
1274  * of the object.
1275  */
1278 {
1279  clientReplyContext *context = dynamic_cast<clientReplyContext *>(aNode->data.getRaw());
1280  assert (context);
1281  assert (context->http == http);
1282  return context->replyStatus();
1283 }
1284 
1287 {
1288  int done;
1289  /* Here because lower nodes don't need it */
1290 
1291  if (http->storeEntry() == NULL) {
1292  debugs(88, 5, "clientReplyStatus: no storeEntry");
1293  return STREAM_FAILED; /* yuck, but what can we do? */
1294  }
1295 
1297  /* TODO: Could upstream read errors (result.flags.error) be
1298  * lost, and result in undersize requests being considered
1299  * complete. Should we tcp reset such connections ?
1300  */
1301  debugs(88, 5, "clientReplyStatus: aborted storeEntry");
1302  return STREAM_FAILED;
1303  }
1304 
1305  if ((done = checkTransferDone()) != 0 || flags.complete) {
1306  debugs(88, 5, "clientReplyStatus: transfer is DONE: " << done << flags.complete);
1307  /* Ok we're finished, but how? */
1308 
1310  debugs(88, 5, "clientReplyStatus: truncated response body");
1312  }
1313 
1314  if (!done) {
1315  debugs(88, 5, "clientReplyStatus: closing, !done, but read 0 bytes");
1316  return STREAM_FAILED;
1317  }
1318 
1319  const int64_t expectedBodySize =
1321  if (expectedBodySize >= 0 && !http->gotEnough()) {
1322  debugs(88, 5, "clientReplyStatus: client didn't get all it expected");
1324  }
1325 
1326  debugs(88, 5, "clientReplyStatus: stream complete; keepalive=" <<
1328  return STREAM_COMPLETE;
1329  }
1330 
1331  // XXX: Should this be checked earlier? We could return above w/o checking.
1332  if (reply->receivedBodyTooLarge(*http->request, http->out.offset - 4096)) {
1333  /* 4096 is a margin for the HTTP headers included in out.offset */
1334  debugs(88, 5, "clientReplyStatus: client reply body is too large");
1335  return STREAM_FAILED;
1336  }
1337 
1338  return STREAM_NONE;
1339 }
1340 
1341 /* Responses with no body will not have a content-type header,
1342  * which breaks the rep_mime_type acl, which
1343  * coincidentally, is the most common acl for reply access lists.
1344  * A better long term fix for this is to allow acl matchs on the various
1345  * status codes, and then supply a default ruleset that puts these
1346  * codes before any user defines access entries. That way the user
1347  * can choose to block these responses where appropriate, but won't get
1348  * mysterious breakages.
1349  */
1350 bool
1352 {
1353  bool result;
1354 
1355  switch (sline) {
1356 
1357  case Http::scContinue:
1358 
1360 
1361  case Http::scProcessing:
1362 
1363  case Http::scNoContent:
1364 
1365  case Http::scNotModified:
1366  result = true;
1367  break;
1368 
1369  default:
1370  result = false;
1371  }
1372 
1373  return result;
1374 }
1375 
1383 void
1385 {
1386  HttpHeader *hdr = &reply->header;
1387  const bool is_hit = http->logType.isTcpHit();
1389 #if DONT_FILTER_THESE
1390  /* but you might want to if you run Squid as an HTTP accelerator */
1391  /* hdr->delById(HDR_ACCEPT_RANGES); */
1392  hdr->delById(HDR_ETAG);
1393 #endif
1394 
1395  if (is_hit || collapsedRevalidation == crSlave)
1397  // TODO: RFC 2965 : Must honour Cache-Control: no-cache="set-cookie2" and remove header.
1398 
1399  // if there is not configured a peer proxy with login=PASS or login=PASSTHRU option enabled
1400  // remove the Proxy-Authenticate header
1401  if ( !request->peer_login || (strcmp(request->peer_login,"PASS") != 0 && strcmp(request->peer_login,"PASSTHRU") != 0)) {
1402 #if USE_ADAPTATION
1403  // but allow adaptation services to authenticate clients
1404  // via request satisfaction
1405  if (!http->requestSatisfactionMode())
1406 #endif
1408  }
1409 
1411  // paranoid: ContentLengthInterpreter has cleaned non-generated replies
1413 
1414  // if (request->range)
1415  // clientBuildRangeHeader(http, reply);
1416 
1417  /*
1418  * Add a estimated Age header on cache hits.
1419  */
1420  if (is_hit) {
1421  /*
1422  * Remove any existing Age header sent by upstream caches
1423  * (note that the existing header is passed along unmodified
1424  * on cache misses)
1425  */
1427  /*
1428  * This adds the calculated object age. Note that the details of the
1429  * age calculation is performed by adjusting the timestamp in
1430  * StoreEntry::timestampsSet(), not here.
1431  */
1435  } else if (http->getConn() && http->getConn()->port->actAsOrigin) {
1436  // Swap the Date: header to current time if we are simulating an origin
1438  if (h)
1439  hdr->putExt("X-Origin-Date", h->value.termedBuf());
1443  if (h && http->storeEntry()->expires >= 0) {
1444  hdr->putExt("X-Origin-Expires", h->value.termedBuf());
1447  }
1448  if (http->storeEntry()->timestamp <= squid_curtime) {
1449  // put X-Cache-Age: instead of Age:
1450  char age[64];
1451  snprintf(age, sizeof(age), "%" PRId64, static_cast<int64_t>(squid_curtime - http->storeEntry()->timestamp));
1452  hdr->putExt("X-Cache-Age", age);
1453  }
1454  } else if (http->storeEntry()->timestamp <= squid_curtime) {
1457  /* Signal old objects. NB: rfc 2616 is not clear,
1458  * by implication, on whether we should do this to all
1459  * responses, or only cache hits.
1460  * 14.46 states it ONLY applys for heuristically caclulated
1461  * freshness values, 13.2.4 doesn't specify the same limitation.
1462  * We interpret RFC 2616 under the combination.
1463  */
1464  /* TODO: if maxage or s-maxage is present, don't do this */
1465 
1466  if (squid_curtime - http->storeEntry()->timestamp >= 86400)
1467  hdr->putWarning(113, "This cache hit is still fresh and more than 1 day old");
1468  }
1469  }
1470 
1471  /* RFC 2616: Section 14.18
1472  *
1473  * Add a Date: header if missing.
1474  * We have access to a clock therefore are required to amend any shortcoming in servers.
1475  *
1476  * NP: done after Age: to prevent ENTRY_SPECIAL double-handling this header.
1477  */
1478  if ( !hdr->has(Http::HdrType::DATE) ) {
1479  if (!http->storeEntry())
1481  else if (http->storeEntry()->timestamp > 0)
1483  else {
1484  debugs(88,DBG_IMPORTANT,"BUG 3279: HTTP reply without Date:");
1485  /* dump something useful about the problem */
1487  }
1488  }
1489 
1490  // add Warnings required by RFC 2616 if serving a stale hit
1492  hdr->putWarning(110, "Response is stale");
1494  hdr->putWarning(111, "Revalidation failed");
1495  }
1496 
1497  /* Filter unproxyable authentication types */
1498  if (http->logType.oldType != LOG_TCP_DENIED &&
1501  HttpHeaderEntry *e;
1502 
1503  int connection_auth_blocked = 0;
1504  while ((e = hdr->getEntry(&pos))) {
1505  if (e->id == Http::HdrType::WWW_AUTHENTICATE) {
1506  const char *value = e->value.rawBuf();
1507 
1508  if ((strncasecmp(value, "NTLM", 4) == 0 &&
1509  (value[4] == '\0' || value[4] == ' '))
1510  ||
1511  (strncasecmp(value, "Negotiate", 9) == 0 &&
1512  (value[9] == '\0' || value[9] == ' '))
1513  ||
1514  (strncasecmp(value, "Kerberos", 8) == 0 &&
1515  (value[8] == '\0' || value[8] == ' '))) {
1516  if (request->flags.connectionAuthDisabled) {
1517  hdr->delAt(pos, connection_auth_blocked);
1518  continue;
1519  }
1520  request->flags.mustKeepalive = true;
1521  if (!request->flags.accelerated && !request->flags.intercepted) {
1522  httpHeaderPutStrf(hdr, Http::HdrType::PROXY_SUPPORT, "Session-Based-Authentication");
1523  /*
1524  We send "Connection: Proxy-Support" header to mark
1525  Proxy-Support as a hop-by-hop header for intermediaries that do not
1526  understand the semantics of this header. The RFC should have included
1527  this recommendation.
1528  */
1529  httpHeaderPutStrf(hdr, Http::HdrType::CONNECTION, "Proxy-support");
1530  }
1531  break;
1532  }
1533  }
1534  }
1535 
1536  if (connection_auth_blocked)
1537  hdr->refreshMask();
1538  }
1539 
1540 #if USE_AUTH
1541  /* Handle authentication headers */
1542  if (http->logType.oldType == LOG_TCP_DENIED &&
1545  ) {
1546  /* Add authentication header */
1553  } else if (request->auth_user_request != NULL)
1555 #endif
1556 
1557  /* Append X-Cache */
1558  httpHeaderPutStrf(hdr, Http::HdrType::X_CACHE, "%s from %s",
1559  is_hit ? "HIT" : "MISS", getMyHostname());
1560 
1561 #if USE_CACHE_DIGESTS
1562  /* Append X-Cache-Lookup: -- temporary hack, to be removed @?@ @?@ */
1563  httpHeaderPutStrf(hdr, Http::HdrType::X_CACHE_LOOKUP, "%s from %s:%d",
1564  lookup_type ? lookup_type : "NONE",
1565  getMyHostname(), getMyPort());
1566 
1567 #endif
1568 
1569  const bool maySendChunkedReply = !request->multipartRangeRequest() &&
1570  reply->sline.protocol == AnyP::PROTO_HTTP && // response is HTTP
1571  (request->http_ver >= Http::ProtocolVersion(1,1));
1572 
1573  /* Check whether we should send keep-alive */
1574  if (!Config.onoff.error_pconns && reply->sline.status() >= 400 && !request->flags.mustKeepalive) {
1575  debugs(33, 3, "clientBuildReplyHeader: Error, don't keep-alive");
1576  request->flags.proxyKeepalive = false;
1577  } else if (!Config.onoff.client_pconns && !request->flags.mustKeepalive) {
1578  debugs(33, 2, "clientBuildReplyHeader: Connection Keep-Alive not requested by admin or client");
1579  request->flags.proxyKeepalive = false;
1580  } else if (request->flags.proxyKeepalive && shutting_down) {
1581  debugs(88, 3, "clientBuildReplyHeader: Shutting down, don't keep-alive.");
1582  request->flags.proxyKeepalive = false;
1583  } else if (request->flags.connectionAuth && !reply->keep_alive) {
1584  debugs(33, 2, "clientBuildReplyHeader: Connection oriented auth but server side non-persistent");
1585  request->flags.proxyKeepalive = false;
1586  } else if (reply->bodySize(request->method) < 0 && !maySendChunkedReply) {
1587  debugs(88, 3, "clientBuildReplyHeader: can't keep-alive, unknown body size" );
1588  request->flags.proxyKeepalive = false;
1589  } else if (fdUsageHigh()&& !request->flags.mustKeepalive) {
1590  debugs(88, 3, "clientBuildReplyHeader: Not many unused FDs, can't keep-alive");
1591  request->flags.proxyKeepalive = false;
1592  } else if (request->flags.sslBumped && !reply->persistent()) {
1593  // We do not really have to close, but we pretend we are a tunnel.
1594  debugs(88, 3, "clientBuildReplyHeader: bumped reply forces close");
1595  request->flags.proxyKeepalive = false;
1596  } else if (request->pinnedConnection() && !reply->persistent()) {
1597  // The peer wants to close the pinned connection
1598  debugs(88, 3, "pinned reply forces close");
1599  request->flags.proxyKeepalive = false;
1600  } else if (http->getConn()) {
1601  ConnStateData * conn = http->getConn();
1602  if (!Comm::IsConnOpen(conn->port->listenConn)) {
1603  // The listening port closed because of a reconfigure
1604  debugs(88, 3, "listening port closed");
1605  request->flags.proxyKeepalive = false;
1606  }
1607  }
1608 
1609  // Decide if we send chunked reply
1610  if (maySendChunkedReply && reply->bodySize(request->method) < 0) {
1611  debugs(88, 3, "clientBuildReplyHeader: chunked reply");
1612  request->flags.chunkedReply = true;
1613  hdr->putStr(Http::HdrType::TRANSFER_ENCODING, "chunked");
1614  }
1615 
1616  hdr->addVia(reply->sline.version);
1617 
1618  /* Signal keep-alive or close explicitly */
1619  hdr->putStr(Http::HdrType::CONNECTION, request->flags.proxyKeepalive ? "keep-alive" : "close");
1620 
1621 #if ADD_X_REQUEST_URI
1622  /*
1623  * Knowing the URI of the request is useful when debugging persistent
1624  * connections in a client; we cannot guarantee the order of http headers,
1625  * but X-Request-URI is likely to be the very last header to ease use from a
1626  * debugger [hdr->entries.count-1].
1627  */
1629  http->memOjbect()->url ? http->memObject()->url : http->uri);
1630 
1631 #endif
1632 
1633  /* Surrogate-Control requires Surrogate-Capability from upstream to pass on */
1634  if ( hdr->has(Http::HdrType::SURROGATE_CONTROL) ) {
1637  }
1638  /* TODO: else case: drop any controls intended specifically for our surrogate ID */
1639  }
1640 
1641  httpHdrMangleList(hdr, request, http->al, ROR_REPLY);
1642 }
1643 
1644 void
1646 {
1647  assert(reply == NULL);
1648 
1649  reply = http->storeEntry()->getReply()->clone();
1650  HTTPMSGLOCK(reply);
1651 
1652  http->al->reply = reply;
1653 
1655  /* RFC 2616 requires us to advertise our version (but only on real HTTP traffic) */
1657  }
1658 
1659  /* do header conversions */
1660  buildReplyHeader();
1661 }
1662 
1666 void
1668 {
1669  StoreEntry *e = http->storeEntry();
1670  assert(e); // or we are not dealing with a hit
1671  // We probably have not locked the entry earlier, unfortunately. We lock it
1672  // now so that we can unlock two lines later (and trigger cleanup).
1673  // Ideally, ClientHttpRequest::storeEntry() should lock/unlock, but it is
1674  // used so inconsistently that simply adding locking there leads to bugs.
1675  e->lock("clientReplyContext::forgetHit");
1676  http->storeEntry(NULL);
1677  e->unlock("clientReplyContext::forgetHit"); // may delete e
1678 }
1679 
1680 void
1682 {
1683  HttpRequest *r = http->request;
1684 
1685  // client sent CC:no-cache or some other condition has been
1686  // encountered which prevents delivering a public/cached object.
1687  if (!r->flags.noCache || r->flags.internal) {
1688  lookingforstore = 5;
1690  } else {
1691  identifyFoundObject(nullptr);
1692  }
1693 }
1694 
1699 void
1701 {
1702  HttpRequest *r = http->request;
1703  http->storeEntry(newEntry);
1704  const auto e = http->storeEntry();
1705 
1706  /* Release IP-cache entries on reload */
1710  if (r->flags.noCache || r->flags.noCacheHack())
1712 
1713 #if USE_CACHE_DIGESTS
1714  lookup_type = e ? "HIT" : "MISS";
1715 #endif
1716 
1717  if (!e) {
1719  debugs(85, 3, "StoreEntry is NULL - MISS");
1721  doGetMoreData();
1722  return;
1723  }
1724 
1725  if (Config.onoff.offline) {
1727  debugs(85, 3, "offline HIT " << *e);
1729  doGetMoreData();
1730  return;
1731  }
1732 
1733  if (http->redirect.status) {
1735  debugs(85, 3, "REDIRECT status forced StoreEntry to NULL (no body on 3XX responses) " << *e);
1736  forgetHit();
1738  doGetMoreData();
1739  return;
1740  }
1741 
1742  if (!e->validToSend()) {
1743  debugs(85, 3, "!storeEntryValidToSend MISS " << *e);
1744  forgetHit();
1746  doGetMoreData();
1747  return;
1748  }
1749 
1750  if (EBIT_TEST(e->flags, ENTRY_SPECIAL)) {
1751  /* \li Special entries are always hits, no matter what the client says */
1752  debugs(85, 3, "ENTRY_SPECIAL HIT " << *e);
1754  doGetMoreData();
1755  return;
1756  }
1757 
1758  if (r->flags.noCache) {
1759  debugs(85, 3, "no-cache REFRESH MISS " << *e);
1760  forgetHit();
1762  doGetMoreData();
1763  return;
1764  }
1765 
1766  if (e->hittingRequiresCollapsing() && !startCollapsingOn(*e, false)) {
1767  debugs(85, 3, "prohibited CF MISS " << *e);
1768  forgetHit();
1770  doGetMoreData();
1771  return;
1772  }
1773 
1774  debugs(85, 3, "default HIT " << *e);
1776  doGetMoreData();
1777 }
1778 
1788 void
1790 {
1791  /* Test preconditions */
1792  assert(aNode != NULL);
1793  assert(cbdataReferenceValid(aNode));
1794  assert(aNode->node.prev == NULL);
1795  assert(aNode->node.next != NULL);
1796  clientReplyContext *context = dynamic_cast<clientReplyContext *>(aNode->data.getRaw());
1797  assert (context);
1798  assert(context->http == http);
1799 
1801 
1802  if (!context->ourNode)
1803  context->ourNode = aNode;
1804 
1805  /* no cbdatareference, this is only used once, and safely */
1806  if (context->flags.storelogiccomplete) {
1808  tempBuffer.offset = next->readBuffer.offset + context->headers_sz;
1809  tempBuffer.length = next->readBuffer.length;
1810  tempBuffer.data = next->readBuffer.data;
1811 
1812  storeClientCopy(context->sc, http->storeEntry(),
1814  return;
1815  }
1816 
1817  if (context->http->request->method == Http::METHOD_PURGE) {
1818  context->purgeRequest();
1819  return;
1820  }
1821 
1822  // OPTIONS with Max-Forwards:0 handled in clientProcessRequest()
1823 
1824  if (context->http->request->method == Http::METHOD_TRACE) {
1825  if (context->http->request->header.getInt64(Http::HdrType::MAX_FORWARDS) == 0) {
1826  context->traceReply(aNode);
1827  return;
1828  }
1829 
1830  /* continue forwarding, not finished yet. */
1831  http->logType.update(LOG_TCP_MISS);
1832 
1833  context->doGetMoreData();
1834  } else
1835  context->identifyStoreObject();
1836 }
1837 
1838 void
1840 {
1841  /* We still have to do store logic processing - vary, cache hit etc */
1842  if (http->storeEntry() != NULL) {
1843  /* someone found the object in the cache for us */
1844  StoreIOBuffer localTempBuffer;
1845 
1846  http->storeEntry()->lock("clientReplyContext::doGetMoreData");
1847 
1849 
1850  sc = storeClientListAdd(http->storeEntry(), this);
1851 #if USE_DELAY_POOLS
1853 #endif
1854 
1856  reqofs = 0;
1857  /* guarantee nothing has been sent yet! */
1858  assert(http->out.size == 0);
1859  assert(http->out.offset == 0);
1860 
1861  if (ConnStateData *conn = http->getConn()) {
1862  if (Ip::Qos::TheConfig.isHitTosActive()) {
1863  Ip::Qos::doTosLocalHit(conn->clientConnection);
1864  }
1865 
1866  if (Ip::Qos::TheConfig.isHitNfmarkActive()) {
1867  Ip::Qos::doNfmarkLocalHit(conn->clientConnection);
1868  }
1869  }
1870 
1871  localTempBuffer.offset = reqofs;
1872  localTempBuffer.length = getNextNode()->readBuffer.length;
1873  localTempBuffer.data = getNextNode()->readBuffer.data;
1874  storeClientCopy(sc, http->storeEntry(), localTempBuffer, CacheHit, this);
1875  } else {
1876  /* MISS CASE, http->logType is already set! */
1877  processMiss();
1878  }
1879 }
1880 
1882 void
1884 {
1886  clientStreamDetach(node, http);
1887 }
1888 
1893 void
1895 {
1896  clientReplyContext *context = static_cast<clientReplyContext *>(data);
1897  context->sendMoreData (result);
1898 }
1899 
1900 void
1902 {
1903  /* At least, I think thats what this does */
1906 }
1907 
1908 bool
1909 clientReplyContext::errorInStream(StoreIOBuffer const &result, size_t const &sizeToProcess)const
1910 {
1911  return /* aborted request */
1913  /* Upstream read error */ (result.flags.error) ||
1914  /* Upstream EOF */ (sizeToProcess == 0);
1915 }
1916 
1917 void
1919 {
1925  debugs(88, 5, "A stream error has occurred, marking as complete and sending no data.");
1926  StoreIOBuffer localTempBuffer;
1927  flags.complete = 1;
1928  http->request->flags.streamError = true;
1929  localTempBuffer.flags.error = result.flags.error;
1931  localTempBuffer);
1932 }
1933 
1934 void
1936 {
1937  StoreIOBuffer localTempBuffer;
1938 
1939  if (result.length == 0) {
1940  debugs(88, 5, "clientReplyContext::pushStreamData: marking request as complete due to 0 length store result");
1941  flags.complete = 1;
1942  }
1943 
1944  assert(result.offset - headers_sz == next()->readBuffer.offset);
1945  localTempBuffer.offset = result.offset - headers_sz;
1946  localTempBuffer.length = result.length;
1947 
1948  if (localTempBuffer.length)
1949  localTempBuffer.data = source;
1950 
1952  localTempBuffer);
1953 }
1954 
1957 {
1959  return getNextNode();
1960 }
1961 
1962 void
1964 {
1965  Ip::Address tmp_noaddr;
1966  tmp_noaddr.setNoAddr(); // TODO: make a global const
1969  http->getConn() != NULL ? http->getConn()->clientConnection->remote : tmp_noaddr,
1970  http->request, http->al);
1973  startError(err);
1974 
1975 }
1976 
1978 void
1980 {
1982  Ip::Address tmp_noaddr;
1983  tmp_noaddr.setNoAddr();
1984  ErrorState *const err =
1986  NULL, http->getConn() ? http->getConn()->clientConnection->remote : tmp_noaddr, http->request, http->al);
1989  startError(err);
1990 }
1991 
1993 void
1995 {
1996  StoreEntry *e = http->storeEntry();
1997  const time_t timestamp = e->timestamp;
1998  HttpReply *const temprep = e->getReply()->make304();
1999  // log as TCP_INM_HIT if code 304 generated for
2000  // If-None-Match request
2001  if (!http->request->flags.ims)
2003  else
2007  e = http->storeEntry();
2008  // Copy timestamp from the original entry so the 304
2009  // reply has a meaningful Age: header.
2010  e->timestampsSet();
2011  e->timestamp = timestamp;
2012  e->replaceHttpReply(temprep);
2013  e->complete();
2014  /*
2015  * TODO: why put this in the store and then serialise it and
2016  * then parse it again. Simply mark the request complete in
2017  * our context and write the reply struct to the client side.
2018  */
2020 }
2021 
2024 void
2026 {
2027  if (http->request->method == Http::METHOD_GET ||
2029  sendNotModified();
2030  else
2032 }
2033 
2034 void
2036 {
2037  /* NP: this should probably soft-fail to a zero-sized-reply error ?? */
2038  assert(reply);
2039 
2041  if (http->logType.oldType == LOG_TCP_DENIED ||
2044  headers_sz = reply->hdr_sz;
2046  return;
2047  }
2048 
2052  return;
2053  }
2054 
2055  headers_sz = reply->hdr_sz;
2056 
2058  if (!Config.accessList.reply) {
2060  return;
2061  }
2062 
2064  ACLFilledChecklist *replyChecklist =
2066  replyChecklist->reply = reply;
2067  HTTPMSGLOCK(replyChecklist->reply);
2068  replyChecklist->nonBlockingCheck(ProcessReplyAccessResult, this);
2069 }
2070 
2071 void
2073 {
2074  clientReplyContext *me = static_cast<clientReplyContext *>(voidMe);
2075  me->processReplyAccessResult(rv);
2076 }
2077 
2078 void
2080 {
2081  debugs(88, 2, "The reply for " << http->request->method
2082  << ' ' << http->uri << " is " << accessAllowed << ", because it matched "
2083  << (AclMatchedName ? AclMatchedName : "NO ACL's"));
2084 
2085  if (!accessAllowed.allowed()) {
2086  ErrorState *err;
2087  err_type page_id;
2088  page_id = aclGetDenyInfoPage(&Config.denyInfoList, AclMatchedName, 1);
2089 
2091 
2092  if (page_id == ERR_NONE)
2093  page_id = ERR_ACCESS_DENIED;
2094 
2095  Ip::Address tmp_noaddr;
2096  tmp_noaddr.setNoAddr();
2097  err = clientBuildError(page_id, Http::scForbidden, NULL,
2098  http->getConn() != NULL ? http->getConn()->clientConnection->remote : tmp_noaddr,
2099  http->request, http->al);
2100 
2102 
2104 
2105  startError(err);
2106 
2107  return;
2108  }
2109 
2110  /* Ok, the reply is allowed, */
2112 
2113  ssize_t body_size = reqofs - reply->hdr_sz;
2114  if (body_size < 0) {
2115  reqofs = reply->hdr_sz;
2116  body_size = 0;
2117  }
2118 
2119  debugs(88, 3, "clientReplyContext::sendMoreData: Appending " <<
2120  (int) body_size << " bytes after " << reply->hdr_sz <<
2121  " bytes of headers");
2122 
2123 #if USE_SQUID_ESI
2124 
2128  debugs(88, 2, "Enabling ESI processing for " << http->uri);
2131  }
2132 
2133 #endif
2134 
2135  if (http->request->method == Http::METHOD_HEAD) {
2136  /* do not forward body for HEAD replies */
2137  body_size = 0;
2138  http->flags.done_copying = true;
2139  flags.complete = 1;
2140  }
2141 
2143  flags.headersSent = true;
2144 
2145  StoreIOBuffer localTempBuffer;
2146  char *buf = next()->readBuffer.data;
2147  char *body_buf = buf + reply->hdr_sz;
2148 
2149  //Server side may disable ranges under some circumstances.
2150 
2151  if ((!http->request->range))
2152  next()->readBuffer.offset = 0;
2153 
2154  body_buf -= next()->readBuffer.offset;
2155 
2156  if (next()->readBuffer.offset != 0) {
2157  if (next()->readBuffer.offset > body_size) {
2158  /* Can't use any of the body we received. send nothing */
2159  localTempBuffer.length = 0;
2160  localTempBuffer.data = NULL;
2161  } else {
2162  localTempBuffer.length = body_size - next()->readBuffer.offset;
2163  localTempBuffer.data = body_buf + next()->readBuffer.offset;
2164  }
2165  } else {
2166  localTempBuffer.length = body_size;
2167  localTempBuffer.data = body_buf;
2168  }
2169 
2170  /* TODO??: move the data in the buffer back by the request header size */
2172  http, reply, localTempBuffer);
2173 
2174  return;
2175 }
2176 
2177 void
2179 {
2180  if (deleting)
2181  return;
2182 
2183  StoreEntry *entry = http->storeEntry();
2184 
2185  if (ConnStateData * conn = http->getConn()) {
2186  if (!conn->isOpen()) {
2187  debugs(33,3, "not sending more data to closing connection " << conn->clientConnection);
2188  return;
2189  }
2190  if (conn->pinning.zeroReply) {
2191  debugs(33,3, "not sending more data after a pinned zero reply " << conn->clientConnection);
2192  return;
2193  }
2194 
2195  if (reqofs==0 && !http->logType.isTcpHit()) {
2196  if (Ip::Qos::TheConfig.isHitTosActive()) {
2197  Ip::Qos::doTosLocalMiss(conn->clientConnection, http->request->hier.code);
2198  }
2199  if (Ip::Qos::TheConfig.isHitNfmarkActive()) {
2200  Ip::Qos::doNfmarkLocalMiss(conn->clientConnection, http->request->hier.code);
2201  }
2202  }
2203 
2204  debugs(88, 5, conn->clientConnection <<
2205  " '" << entry->url() << "'" <<
2206  " out.offset=" << http->out.offset);
2207  }
2208 
2209  char *buf = next()->readBuffer.data;
2210 
2211  if (buf != result.data) {
2212  /* we've got to copy some data */
2213  assert(result.length <= next()->readBuffer.length);
2214  memcpy(buf, result.data, result.length);
2215  }
2216 
2217  /* We've got the final data to start pushing... */
2219 
2220  reqofs += result.length;
2221 
2223 
2224  assert(http->request != NULL);
2225 
2226  /* ESI TODO: remove this assert once everything is stable */
2229 
2230  makeThisHead();
2231 
2232  debugs(88, 5, "clientReplyContext::sendMoreData: " << http->uri << ", " <<
2233  reqofs << " bytes (" << result.length <<
2234  " new bytes)");
2235 
2236  /* update size of the request */
2237  reqsize = reqofs;
2238 
2239  if (errorInStream(result, reqofs)) {
2240  sendStreamError(result);
2241  return;
2242  }
2243 
2244  if (flags.headersSent) {
2245  pushStreamData (result, buf);
2246  return;
2247  }
2248 
2249  cloneReply();
2250 
2251 #if USE_DELAY_POOLS
2252  if (sc)
2254 #endif
2255 
2256  holdingBuffer = result;
2258  return;
2259 }
2260 
2261 void
2263 {
2264  clientAclChecklistFill(checklist, http);
2265 }
2266 
2267 /* Using this breaks the client layering just a little!
2268  */
2269 void
2271 {
2272  assert(http != NULL);
2273  /*
2274  * For erroneous requests, we might not have a h->request,
2275  * so make a fake one.
2276  */
2277 
2278  if (http->request == NULL) {
2280  // XXX: These fake URI parameters shadow the real (or error:...) URI.
2281  // TODO: Either always set the request earlier and assert here OR use
2282  // http->uri (converted to Anyp::Uri) to create this catch-all request.
2283  const_cast<HttpRequest *&>(http->request) = new HttpRequest(m, AnyP::PROTO_NONE, "http", null_string, mx);
2285  }
2286 
2287  StoreEntry *e = storeCreateEntry(storeId(), http->log_uri, reqFlags, m);
2288 
2289  // Make entry collapsable ASAP, to increase collapsing chances for others,
2290  // TODO: every must-revalidate and similar request MUST reach the origin,
2291  // but do we have to prohibit others from collapsing on that request?
2292  if (reqFlags.cachable &&
2293  !reqFlags.needValidation &&
2294  (m == Http::METHOD_GET || m == Http::METHOD_HEAD) &&
2296  // make the entry available for future requests now
2297  (void)Store::Root().allowCollapsing(e, reqFlags, m);
2298  }
2299 
2300  sc = storeClientListAdd(e, this);
2301 
2302 #if USE_DELAY_POOLS
2304 #endif
2305 
2306  reqofs = 0;
2307 
2308  reqsize = 0;
2309 
2310  /* I don't think this is actually needed! -- adrian */
2311  /* http->reqbuf = http->norm_reqbuf; */
2312  // assert(http->reqbuf == http->norm_reqbuf);
2313  /* The next line is illegal because we don't know if the client stream
2314  * buffers have been set up
2315  */
2316  // storeClientCopy(http->sc, e, 0, HTTP_REQBUF_SZ, http->reqbuf,
2317  // SendMoreData, this);
2318  /* So, we mark the store logic as complete */
2320 
2321  /* and get the caller to request a read, from whereever they are */
2322  /* NOTE: after ANY data flows down the pipe, even one step,
2323  * this function CAN NOT be used to manage errors
2324  */
2325  http->storeEntry(e);
2326 }
2327 
2328 ErrorState *
2329 clientBuildError(err_type page_id, Http::StatusCode status, char const *url,
2330  Ip::Address &src_addr, HttpRequest * request, const AccessLogEntry::Pointer &al)
2331 {
2332  const auto err = new ErrorState(page_id, status, request, al);
2333  err->src_addr = src_addr;
2334 
2335  if (url)
2336  err->url = xstrdup(url);
2337 
2338  return err;
2339 }
2340 
int delById(Http::HdrType id)
Definition: HttpHeader.cc:678
void nonBlockingCheck(ACLCB *callback, void *callback_data)
Definition: Checklist.cc:238
HierarchyLogEntry hier
Definition: HttpRequest.h:157
char const * rawBuf() const
Definition: SquidString.h:85
AnyP::ProtocolVersion ProtocolVersion(unsigned int aMajor, unsigned int aMinor)
HTTP version label information.
int fdUsageHigh(void)
Definition: fd.cc:301
short int keep_alive
Definition: HttpReply.h:57
#define HTTP_REQBUF_SZ
Definition: defines.h:216
bool mayInitiateCollapsing() const
whether Squid configuration allows us to become a CF initiator
Definition: StoreClient.h:51
StoreEntry * loggingEntry() const
CachePeer * peer
Definition: client_side.h:144
bool startCollapsingOn(const StoreEntry &, const bool doingRevalidation)
Definition: store_client.cc:65
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
ConnStateData * pinnedConnection()
Definition: HttpRequest.cc:686
store_client * old_sc
static ACLCB ProcessReplyAccessResult
HttpHdrRange * range
Definition: HttpRequest.h:143
int error_pconns
Definition: SquidConfig.h:308
#define assert(EX)
Definition: assert.h:17
HttpReply * make304() const
Definition: HttpReply.cc:120
bool modifiedSince(const time_t ims, const int imslen=-1) const
Definition: store.cc:1899
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:1936
void sendMoreData(StoreIOBuffer result)
void cacheHit(StoreIOBuffer result)
static void getPublicByRequestMethod(StoreClient *aClient, HttpRequest *request, const HttpRequestMethod &method)
Definition: store.cc:501
#define HttpHeaderInitPos
Definition: HttpHeader.h:48
void processReplyAccessResult(const Acl::Answer &accessAllowed)
#define cbdataReferenceDone(var)
Definition: cbdata.h:350
int clientHttpRequestStatus(int fd, ClientHttpRequest const *http)
SQUIDCEXTERN CSD clientReplyDetach
void release(const bool shareable=false)
Definition: store.cc:1195
int unlock(const char *context)
Definition: store.cc:463
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
Definition: ETag.h:17
bool persistent() const
Definition: Message.cc:261
struct ClientHttpRequest::Redirect redirect
SBuf vary_headers
The variant second-stage cache key. Generated from Vary header pattern for this request.
Definition: HttpRequest.h:171
bool processConditional(StoreIOBuffer &result)
process conditional request from client
CSR esiStreamRead
bool loopDetected
Definition: RequestFlags.h:36
int hdr_sz
Definition: Message.h:82
static STCB SendMoreData
void pushStreamData(StoreIOBuffer const &result, char *source)
bool timestampsSet()
Definition: store.cc:1460
Definition: SBuf.h:86
int collapsed_forwarding
Definition: SquidConfig.h:326
const char * null_string
const char * storeId() const
Definition: MemObject.cc:54
unsigned char cache_key
Store key.
Definition: forward.h:29
HttpHeaderEntry * findEntry(Http::HdrType id) const
Definition: HttpHeader.cc:614
int64_t objectLen() const
Definition: store.cc:1661
int64_t bodySize(const HttpRequestMethod &) const
Definition: HttpReply.cc:371
HttpRequestMethod method
Definition: HttpRequest.h:114
int prefixLen() const
Definition: HttpRequest.cc:372
#define SQUIDCEXTERN
Definition: squid.h:26
struct _request * request(char *urlin)
Definition: tcp-banger2.c:291
int client_pconns
Definition: SquidConfig.h:306
acl_access * reply
Definition: SquidConfig.h:378
#define xstrdup
#define PRId64
Definition: types.h:110
void removeHopByHopEntries()
Definition: HttpHeader.cc:1710
int storeNotOKTransferDone() const
bool errorInStream(StoreIOBuffer const &result, size_t const &sizeToProcess) const
ConnStateData * getConn() const
virtual void buffer()
Definition: store.cc:1641
void purgeFoundHead(StoreEntry *newEntry)
bool expectedBodyTooLarge(HttpRequest &request)
Definition: HttpReply.cc:521
void lastModified(const time_t when)
Definition: Store.h:159
virtual void created(StoreEntry *newEntry)
#define safe_free(x)
Definition: xalloc.h:73
const char * storeKeyText(const cache_key *key)
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:1629
CSCB esiProcessStream
void putExt(const char *name, const char *value)
Definition: HttpHeader.cc:1124
void HTTPMSGLOCK(Http::Message *a)
Definition: Message.h:160
virtual LogTags * loggingTags()
bool olderThan(const HttpReply *them) const
Definition: HttpReply.cc:660
#define Must(condition)
Like assert() but throws an exception instead of aborting the process.
Definition: TextException.h:69
bool isEmpty() const
Definition: SBuf.h:420
int refreshCheckHTTP(const StoreEntry *entry, HttpRequest *request)
Definition: refresh.cc:588
HttpReply const * getReply() const
Definition: store.cc:1676
StoreEntry * storeEntry() const
store_client * storeClientListAdd(StoreEntry *e, void *data)
AnyP::ProtocolVersion http_ver
Definition: Message.h:73
HttpHeaderEntry * getEntry(HttpHeaderPos *pos) const
Definition: HttpHeader.cc:595
we initiated collapsed revalidation request
void redirect(Http::StatusCode, const char *)
Definition: HttpReply.cc:196
bool isTcpHit() const
determine if the log tag code indicates a cache HIT
Definition: LogTags.cc:91
#define DBG_CRITICAL
Definition: Debug.h:45
int conn
the current server connection FD
Definition: Transport.cc:26
void purgeDoPurgeHead(StoreEntry *entry)
time_t ims
Definition: HttpRequest.h:145
Controller & Root()
safely access controller singleton
Definition: Controller.cc:877
const char * getMyHostname(void)
Definition: tools.cc:412
struct clientReplyContext::Flags flags
time_t expires
Definition: Store.h:204
clientStreamNode * getNextNode() const
void * callback_data
Definition: errorpage.h:188
clientStreamNode * next() const
void setReplyToReply(HttpReply *reply)
creates a store entry for the reply and appends error reply to it
void clientAclChecklistFill(ACLFilledChecklist &checklist, ClientHttpRequest *http)
void sendNotModified()
send 304 (Not Modified) to client
HttpReply * clone() const
Definition: HttpReply.cc:569
void setReplyToStoreEntry(StoreEntry *e, const char *reason)
replaces current response store entry with the given one
const SBuf storeId()
Definition: HttpRequest.cc:694
StoreEntry * storeGetPublic(const char *uri, const HttpRequestMethod &method)
Definition: store.cc:522
clientStream_status_t replyStatus()
int doNfmarkLocalMiss(const Comm::ConnectionPointer &conn, const hier_code hierCode)
Definition: QosConfig.cc:235
we collapsed on the existing revalidation request
time_t squid_curtime
Definition: stub_time.cc:17
Acl::Answer const & fastCheck()
Definition: Checklist.cc:336
time_t timestamp
Definition: Store.h:202
void replaceHttpReply(HttpReply *, bool andStartWriting=true)
Definition: store.cc:1788
bool connectionAuth
Definition: RequestFlags.h:76
void setDelayId(DelayId delay_id)
void purgeFoundObject(StoreEntry *entry)
bool failOnValidationError
Definition: RequestFlags.h:48
clientReplyContext(ClientHttpRequest *)
static void getPublicByRequest(StoreClient *aClient, HttpRequest *request)
Definition: store.cc:508
bool ignored
_IGNORED: the response was not used for anything
Definition: LogTags.h:72
void complete()
Definition: store.cc:1064
char tempbuf[HTTP_REQBUF_SZ]
a temporary buffer if we need working storage
Http::HdrType id
Definition: HttpHeader.h:63
void httpHeaderPutStrf(HttpHeader *hdr, Http::HdrType id, const char *fmt,...)
void delAt(HttpHeaderPos pos, int &headers_deleted)
Definition: HttpHeader.cc:706
ACLFilledChecklist * clientAclChecklistCreate(const acl_access *acl, ClientHttpRequest *http)
const SBuf & effectiveRequestUri() const
RFC 7230 section 5.5 - Effective Request URI.
Definition: HttpRequest.cc:705
void setNoAddr()
Definition: Address.cc:292
int shutting_down
void purgeFoundGet(StoreEntry *newEntry)
bool IsConnOpen(const Comm::ConnectionPointer &conn)
Definition: Connection.cc:24
void const char HLPCB void * data
Definition: stub_helper.cc:16
int64_t offset
Definition: StoreIOBuffer.h:55
LogTags logType
the processing tags associated with this request transaction.
Definition: parse.c:104
bool noCacheHack() const
Definition: RequestFlags.h:124
StatusCode
Definition: StatusCode.h:20
int64_t content_length
Definition: Message.h:84
const char * c_str() const
compute the status access.log field
Definition: LogTags.cc:56
class SquidConfig2 Config2
Definition: SquidConfig.cc:14
int getMyPort(void)
Definition: tools.cc:1003
#define debugs(SECTION, LEVEL, CONTENT)
Definition: Debug.h:124
#define cbdataReference(var)
Definition: cbdata.h:341
void setHeaders(Http::StatusCode status, const char *reason, const char *ctype, int64_t clen, time_t lmt, time_t expires)
Definition: HttpReply.cc:161
CSS clientReplyStatus
const char * url() const
Definition: store.cc:1606
StoreEntry * storeCreateEntry(const char *url, const char *logUrl, const RequestFlags &flags, const HttpRequestMethod &method)
Definition: store.cc:782
#define DBG_IMPORTANT
Definition: Debug.h:46
void swapOut(StoreEntry *e)
Definition: HttpRequest.cc:337
bool streamError
Definition: RequestFlags.h:92
bool allowed() const
Definition: Acl.h:143
CSS esiStreamStatus
void sendStreamError(StoreIOBuffer const &result)
int storeClientIsThisAClient(store_client *sc, void *someClient)
void update(const LogTags_ot t)
Definition: LogTags.cc:44
bool connectionAuthDisabled
Definition: RequestFlags.h:78
dlink_node node
Definition: clientStream.h:88
mem_status_t mem_status
Definition: Store.h:218
void putTime(Http::HdrType id, time_t htime)
Definition: HttpHeader.cc:1026
void ipcacheInvalidate(const char *name)
Definition: ipcache.cc:856
SQUIDCEXTERN CSR clientGetMoreData
int varyEvaluateMatch(StoreEntry *entry, HttpRequest *request)
virtual void fillChecklist(ACLFilledChecklist &) const
configure the ACL checklist with the current transaction state
bool chunkedReply
Definition: RequestFlags.h:90
Http::StatusCode purgeStatus
struct StoreIOBuffer::@147 flags
Config TheConfig
Globally available instance of Qos::Config.
Definition: QosConfig.cc:271
bool mustKeepalive
Definition: RequestFlags.h:74
AnyP::Uri url
the request URI
Definition: HttpRequest.h:115
void * addr
Definition: membanger.c:46
static bool SmpAware()
whether there are any SMP-aware storages
Definition: Controller.cc:859
CbcPointer< ConnStateData > clientConnectionManager
Definition: HttpRequest.h:233
int weak
true if it is a weak validator
Definition: ETag.h:21
struct SquidConfig::@113 accessList
Http::StatusCode httpStatus
Definition: errorpage.h:174
const char * lookup_type
bool blockedHit() const
whether squid.conf send_hit prevents us from serving this hit
void releaseRequest(const bool shareable=false)
Definition: store.cc:452
uint16_t flags
Definition: Store.h:210
void putWarning(const int code, const char *const text)
add a Warning header
Definition: HttpHeader.cc:1115
void sendNotModifiedOrPreconditionFailedError()
StoreIOBuffer holdingBuffer
ClientStreamData data
Definition: clientStream.h:94
AccessLogEntry::Pointer al
access.log entry
CSD esiStreamDetach
Http::StatusLine sline
Definition: HttpReply.h:60
const char * AclMatchedName
Definition: Acl.cc:30
class AccessLogEntry::HttpDetails http
void host(const char *src)
Definition: Uri.cc:48
bool alwaysAllowResponse(Http::StatusCode sline) const
void refreshMask()
Definition: HttpHeader.cc:734
MemObject * mem_obj
Definition: Store.h:199
void putInt(Http::HdrType id, int number)
Definition: HttpHeader.cc:1008
void identifyFoundObject(StoreEntry *entry)
clientStream_status_t
Definition: enums.h:121
AnyP::ProtocolType protocol
Definition: StatusLine.h:68
char const * termedBuf() const
Definition: SquidString.h:91
struct ClientHttpRequest::Out out
void ignoreRange(const char *reason)
forgets about the cached Range header (for a reason)
Definition: HttpRequest.cc:646
void addVia(const AnyP::ProtocolVersion &ver, const HttpHeader *from=0)
Definition: HttpHeader.cc:982
void startError(ErrorState *err)
unsigned complete
we have read all we can from upstream
void const char * buf
Definition: stub_helper.cc:16
std::ostream & HERE(std::ostream &s)
Definition: Debug.h:153
ssize_t HttpHeaderPos
Definition: HttpHeader.h:45
struct SquidConfig::@112 onoff
void removeStoreReference(store_client **scp, StoreEntry **ep)
unsigned error
Definition: StoreIOBuffer.h:52
HttpHeader header
Definition: Message.h:75
struct SquidConfig2::@127 onoff
int storeUnregister(store_client *sc, StoreEntry *e, void *data)
bool accelerated
Definition: RequestFlags.h:58
Definition: enums.h:46
AclDenyInfoList * denyInfoList
Definition: SquidConfig.h:407
void dump(int debug_lvl) const
Definition: store.cc:1539
HttpReplyPointer reply
MemObject * memObject() const
RequestFlags flags
Definition: HttpRequest.h:141
store_status_t store_status
Definition: Store.h:222
int has(Http::HdrType id) const
Definition: HttpHeader.cc:974
StoreIOBuffer tempBuffer
bool hasIfNoneMatchEtag(const HttpRequest &request) const
has ETag matching at least one of the If-None-Match etags
Definition: store.cc:1954
void neighborsHtcpClear(StoreEntry *e, const char *uri, HttpRequest *req, const HttpRequestMethod &method, htcp_clr_reason reason)
Definition: neighbors.cc:1785
void handleIMSReply(StoreIOBuffer result)
int checkNegativeHit() const
Definition: store.cc:1366
Ip::Address remote
Definition: Connection.h:138
LogTags_ot oldType
a set of client protocol, cache use, and other transaction outcome tags
Definition: LogTags.h:84
bool mayStartHitting() const
Definition: Store.h:269
void putStr(Http::HdrType id, const char *str)
Definition: HttpHeader.cc:1035
clientStreamNode * ourNode
static STCB HandleIMSReply
CollapsedRevalidation collapsedRevalidation
void purgeEntriesByUrl(HttpRequest *req, const char *url)
ErrorState * clientBuildError(err_type, Http::StatusCode, char const *, Ip::Address &, HttpRequest *, const AccessLogEntry::Pointer &)
bool intercepted
Definition: RequestFlags.h:62
bool proxyKeepalive
Definition: RequestFlags.h:38
StoreIOBuffer readBuffer
Definition: clientStream.h:95
void traceReply(clientStreamNode *node)
virtual void evictIfFound(const cache_key *) override
Definition: Controller.cc:468
int cmp(const SBuf &S, const size_type n) const
shorthand version for compare()
Definition: SBuf.h:264
void HTTPMSGUNLOCK(M *&a)
Definition: Message.h:149
#define CBDATA_CLASS_INIT(type)
Definition: cbdata.h:318
int storeOKTransferDone() const
void createStoreEntry(const HttpRequestMethod &m, RequestFlags flags)
struct ClientHttpRequest::Flags flags
C * getRaw() const
Definition: RefCount.h:74
size_t HttpReply *STUB StoreEntry const KeyScope scope const HttpRequestMethod & method
Definition: stub_store.cc:112
bool conditional() const
has at least one recognized If-* header
Definition: HttpRequest.cc:597
acl_access * sendHit
Definition: SquidConfig.h:366
int doNfmarkLocalHit(const Comm::ConnectionPointer &conn)
Definition: QosConfig.cc:263
int esiEnableProcessing(HttpReply *rep)
Definition: Esi.cc:2238
size_type find(char c, size_type startPos=0) const
Definition: SBuf.cc:594
static const size_type npos
Definition: SBuf.h:92
Comm::ConnectionPointer clientConnection
Definition: Server.h:97
Auth::UserRequest::Pointer auth_user_request
Definition: HttpRequest.h:127
class LogTags::Errors err
void errorAppendEntry(StoreEntry *entry, ErrorState *err)
Definition: errorpage.cc:711
clientStream_status_t CSS(clientStreamNode *, ClientHttpRequest *)
static void Start(const Comm::ConnectionPointer &client, StoreEntry *, HttpRequest *, const AccessLogEntryPointer &alp)
Initiates request forwarding to a peer or origin server.
Definition: FwdState.cc:329
bool receivedBodyTooLarge(HttpRequest &, int64_t receivedBodySize)
Definition: HttpReply.cc:513
Http::StatusCode status() const
retrieve the status code for this status line
Definition: StatusLine.h:45
int cbdataReferenceValid(const void *p)
Definition: cbdata.cc:412
void removeClientStoreReference(store_client **scp, ClientHttpRequest *http)
const char * str
quoted-string
Definition: ETag.h:20
bool multipartRangeRequest() const
Definition: HttpRequest.cc:437
void clearPublicKeyScope()
Definition: store.cc:633
void storeErrorResponse(HttpReply *reply)
Store a prepared error response. MemObject locks the reply object.
Definition: store.cc:1771
HttpRequest *const request
void clean()
Definition: String.cc:125
ClientHttpRequest * http
void clientStreamInsertHead(dlink_list *list, CSR *func, CSCB *callback, CSD *detach, CSS *status, ClientStreamData data)
bool requestSatisfactionMode() const
StoreEntry * storeGetPublicByRequest(HttpRequest *req, const KeyScope keyScope)
Definition: store.cc:534
AnyP::UriScheme const & getScheme() const
Definition: Uri.h:67
void CSD(clientStreamNode *, ClientHttpRequest *)
client stream detach
void clientStreamCallback(clientStreamNode *thisObject, ClientHttpRequest *http, HttpReply *rep, StoreIOBuffer replyBuffer)
AnyP::ProtocolVersion version
breakdown of protocol version label: (HTTP/ICY) and (0.9/1.0/1.1)
Definition: StatusLine.h:70
void CSR(clientStreamNode *, ClientHttpRequest *)
client stream read
void updateOnNotModified(StoreEntry *old, const StoreEntry &newer)
update old entry metadata and HTTP headers using a newer entry
Definition: Controller.cc:680
bool hasIfMatchEtag(const HttpRequest &request) const
has ETag matching at least one of the If-Match etags
Definition: store.cc:1947
void purgeDoPurgeGet(StoreEntry *entry)
void removeIrrelevantContentLength()
Some response status codes prohibit sending Content-Length (RFC 7230 section 3.3.2).
Definition: HttpReply.cc:668
int doTosLocalHit(const Comm::ConnectionPointer &conn)
Definition: QosConfig.cc:256
void clientStreamDetach(clientStreamNode *thisObject, ClientHttpRequest *http)
const cache_key * storeKeyPublic(const char *url, const HttpRequestMethod &method, const KeyScope keyScope)
char * peer_login
Definition: HttpRequest.h:164
Definition: forward.h:21
static DelayId DelayClient(ClientHttpRequest *, HttpReply *reply=nullptr)
Definition: DelayId.cc:67
void sendPreconditionFailedError()
send 412 (Precondition Failed) to client
#define EBIT_TEST(flag, bit)
Definition: defines.h:107
time_t lastmod
Definition: HttpRequest.h:168
class SquidConfig Config
Definition: SquidConfig.cc:12
String etag
A strong etag of the cached entry. Used for refreshing that entry.
Definition: HttpRequest.h:192
#define NULL
Definition: types.h:166
void httpHdrMangleList(HttpHeader *l, HttpRequest *request, const AccessLogEntryPointer &al, req_or_rep_t req_or_rep)
bool needValidation
Definition: RequestFlags.h:46
bool allowCollapsing(StoreEntry *, const RequestFlags &, const HttpRequestMethod &)
tries to make the entry available for collapsing future requests
Definition: Controller.cc:697
void ipcacheInvalidateNegative(const char *name)
Definition: ipcache.cc:873
#define false
Definition: GnuRegex.c:233
int doTosLocalMiss(const Comm::ConnectionPointer &conn, const hier_code hierCode)
Definition: QosConfig.cc:214
const char * storeId() const
err_type
Definition: err_type.h:12
err_type aclGetDenyInfoPage(AclDenyInfoList **head, const char *name, int redirect_allowed)
Definition: Gadgets.cc:41
int64_t getInt64(Http::HdrType id) const
Definition: HttpHeader.cc:1145
const HttpReplyPointer & getReply() const
Definition: MemObject.h:57
collapsed revalidation is not allowed for this context
void lock(const char *context)
Definition: store.cc:439

 

Introduction

Documentation

Support

Miscellaneous

Web Site Translations

Mirrors