client_side_reply.cc
Go to the documentation of this file.
1 /*
2  * Copyright (C) 1996-2021 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  http(cbdataReference(clientContext)),
78  headers_sz(0),
79  sc(NULL),
80  old_reqsize(0),
81  reqsize(0),
82  reqofs(0),
83  ourNode(NULL),
84  reply(NULL),
85  old_entry(NULL),
86  old_sc(NULL),
87  old_lastmod(-1),
88  deleting(false),
89  collapsedRevalidation(crNone)
90 {
91  *tempbuf = 0;
92 }
93 
99 void
101  err_type err, Http::StatusCode status, const HttpRequestMethod& method, char const *uri,
102  const ConnStateData *conn, HttpRequest *failedrequest, const char *unparsedrequest,
103 #if USE_AUTH
104  Auth::UserRequest::Pointer auth_user_request
105 #else
106  void*
107 #endif
108 )
109 {
110  auto errstate = clientBuildError(err, status, uri, conn, failedrequest, http->al);
111 
112  if (unparsedrequest)
113  errstate->request_hdrs = xstrdup(unparsedrequest);
114 
115 #if USE_AUTH
116  errstate->auth_user_request = auth_user_request;
117 #endif
118  setReplyToError(method, errstate);
119 }
120 
122 {
123  if (errstate->httpStatus == Http::scNotImplemented && http->request)
124  /* prevent confusion over whether we default to persistent or not */
125  http->request->flags.proxyKeepalive = false;
126 
127  http->al->http.code = errstate->httpStatus;
128 
129  if (http->request)
130  http->request->ignoreRange("responding with a Squid-generated error");
131 
132  createStoreEntry(method, RequestFlags());
133  assert(errstate->callback_data == NULL);
134  errorAppendEntry(http->storeEntry(), errstate);
135  /* Now the caller reads to get this */
136 }
137 
138 void
140 {
141  Must(futureReply);
142  http->al->http.code = futureReply->sline.status();
143 
144  HttpRequestMethod method;
145  if (http->request) { // nil on responses to unparsable requests
146  http->request->ignoreRange("responding with a Squid-generated reply");
147  method = http->request->method;
148  }
149 
150  createStoreEntry(method, RequestFlags());
151 
152  http->storeEntry()->storeErrorResponse(futureReply);
153  /* Now the caller reads to get futureReply */
154 }
155 
156 // Assumes that the entry contains an error response without Content-Range.
157 // To use with regular entries, make HTTP Range header removal conditional.
158 void clientReplyContext::setReplyToStoreEntry(StoreEntry *entry, const char *reason)
159 {
160  entry->lock("clientReplyContext::setReplyToStoreEntry"); // removeClientStoreReference() unlocks
161  sc = storeClientListAdd(entry, this);
162 #if USE_DELAY_POOLS
164 #endif
165  reqofs = 0;
166  reqsize = 0;
167  if (http->request)
168  http->request->ignoreRange(reason);
170  http->storeEntry(entry);
171 }
172 
173 void
175  StoreEntry ** ep)
176 {
177  StoreEntry *e;
178  store_client *sc_tmp = *scp;
179 
180  if ((e = *ep) != NULL) {
181  *ep = NULL;
182  storeUnregister(sc_tmp, e, this);
183  *scp = NULL;
184  e->unlock("clientReplyContext::removeStoreReference");
185  }
186 }
187 
188 void
190 {
191  StoreEntry *reference = aHttpRequest->storeEntry();
192  removeStoreReference(scp, &reference);
193  aHttpRequest->storeEntry(reference);
194 }
195 
196 void
198 {
199  assert(old_sc == NULL);
200  debugs(88, 3, "clientReplyContext::saveState: saving store context");
202  old_sc = sc;
207  /* Prevent accessing the now saved entries */
208  http->storeEntry(NULL);
209  sc = NULL;
210  reqsize = 0;
211  reqofs = 0;
212 }
213 
214 void
216 {
217  assert(old_sc != NULL);
218  debugs(88, 3, "clientReplyContext::restoreState: Restoring store context");
221  sc = old_sc;
226  /* Prevent accessed the old saved entries */
227  old_entry = NULL;
228  old_sc = NULL;
229  old_lastmod = -1;
230  old_etag.clean();
231  old_reqsize = 0;
232  tempBuffer.offset = 0;
233 }
234 
235 void
237 {
241 }
242 
245 {
246  return (clientStreamNode *)ourNode->node.next->data;
247 }
248 
249 /* This function is wrong - the client parameters don't include the
250  * header offset
251  */
252 void
254 {
255  /* when confident, 0 becomes reqofs, and then this factors into
256  * startSendProcess
257  */
258  assert(reqofs == 0);
259  StoreIOBuffer localTempBuffer (next()->readBuffer.length, 0, next()->readBuffer.data);
260  storeClientCopy(sc, http->storeEntry(), localTempBuffer, SendMoreData, this);
261 }
262 
263 /* there is an expired entry in the store.
264  * setup a temporary buffer area and perform an IMS to the origin
265  */
266 void
268 {
269  const char *url = storeId();
270  debugs(88, 3, "clientReplyContext::processExpired: '" << http->uri << "'");
271  const time_t lastmod = http->storeEntry()->lastModified();
272  assert(lastmod >= 0);
273  /*
274  * check if we are allowed to contact other servers
275  * @?@: Instead of a 504 (Gateway Timeout) reply, we may want to return
276  * a stale entry *if* it matches client requirements
277  */
278 
279  if (http->onlyIfCached()) {
281  return;
282  }
283 
285  http->request->flags.refresh = true;
286 #if STORE_CLIENT_LIST_DEBUG
287  /* Prevent a race with the store client memory free routines
288  */
290 #endif
291  /* Prepare to make a new temporary request */
292  saveState();
293 
294  // TODO: Consider also allowing regular (non-collapsed) revalidation hits.
295  // TODO: support collapsed revalidation for Vary-controlled entries
296  bool collapsingAllowed = Config.onoff.collapsed_forwarding &&
299 
300  StoreEntry *entry = nullptr;
301  if (collapsingAllowed) {
302  if (const auto e = storeGetPublicByRequest(http->request, ksRevalidation)) {
303  if (e->hittingRequiresCollapsing() && startCollapsingOn(*e, true)) {
304  entry = e;
305  entry->lock("clientReplyContext::processExpired#alreadyRevalidating");
306  } else {
307  e->abandon(__FUNCTION__);
308  // assume mayInitiateCollapsing() would fail too
309  collapsingAllowed = false;
310  }
311  }
312  }
313 
314  if (entry) {
315  entry->ensureMemObject(url, http->log_uri, http->request->method);
316  debugs(88, 5, "collapsed on existing revalidation entry: " << *entry);
318  } else {
319  entry = storeCreateEntry(url,
321  /* NOTE, don't call StoreEntry->lock(), storeCreateEntry() does it */
322 
323  if (collapsingAllowed && mayInitiateCollapsing() &&
324  Store::Root().allowCollapsing(entry, http->request->flags, http->request->method)) {
325  debugs(88, 5, "allow other revalidation requests to collapse on " << *entry);
327  } else {
329  }
330  }
331 
332  sc = storeClientListAdd(entry, this);
333 #if USE_DELAY_POOLS
334  /* delay_id is already set on original store client */
336 #endif
337 
338  http->request->lastmod = lastmod;
339 
341  ETag etag = {NULL, -1}; // TODO: make that a default ETag constructor
342  if (old_entry->hasEtag(etag) && !etag.weak)
343  http->request->etag = etag.str;
344  }
345 
346  debugs(88, 5, "lastmod " << entry->lastModified());
347  http->storeEntry(entry);
348  assert(http->out.offset == 0);
350 
352  /*
353  * A refcounted pointer so that FwdState stays around as long as
354  * this clientReplyContext does
355  */
358  }
359  /* Register with storage manager to receive updates when data comes in. */
360 
361  if (EBIT_TEST(entry->flags, ENTRY_ABORTED))
362  debugs(88, DBG_CRITICAL, "clientReplyContext::processExpired: Found ENTRY_ABORTED object");
363 
364  {
365  /* start counting the length from 0 */
366  StoreIOBuffer localTempBuffer(HTTP_REQBUF_SZ, 0, tempbuf);
367  storeClientCopy(sc, entry, localTempBuffer, HandleIMSReply, this);
368  }
369 }
370 
371 void
373 {
374  StoreIOBuffer tempresult;
376 
379 
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 {
396  clientReplyContext *context = (clientReplyContext *)data;
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  return;
451  }
452 
453  const auto oldStatus = old_entry->mem().freshestReply().sline.status();
454  const auto &new_rep = http->storeEntry()->mem().freshestReply();
455  const auto status = new_rep.sline.status();
456 
457  // XXX: Disregard stale incomplete (i.e. still being written) borrowed (i.e.
458  // not caused by our request) IMS responses. That new_rep may be very old!
459 
460  // origin replied 304
461  if (status == Http::scNotModified) {
463  http->request->flags.staleIfHit = false; // old_entry is no longer stale
464 
465  // TODO: The update may not be instantaneous. Should we wait for its
466  // completion to avoid spawning too much client-disassociated work?
468 
469  // if client sent IMS
471  // forward the 304 from origin
472  debugs(88, 3, "origin replied 304, revalidated existing entry and forwarding 304 to client");
474  return;
475  }
476 
477  // send existing entry, it's still valid
478  debugs(88, 3, "origin replied 304, revalidated existing entry and sending " << oldStatus << " to client");
480  return;
481  }
482 
483  // origin replied with a non-error code
484  if (status > Http::scNone && status < Http::scInternalServerError) {
485  // RFC 7234 section 4: a cache MUST use the most recent response
486  // (as determined by the Date header field)
487  if (new_rep.olderThan(&old_entry->mem().freshestReply())) {
488  http->al->cache.code.err.ignored = true;
489  debugs(88, 3, "origin replied " << status << " but with an older date header, sending old entry (" << oldStatus << ") to client");
491  return;
492  }
493 
495  debugs(88, 3, "origin replied " << status << ", forwarding to client");
497  return;
498  }
499 
500  // origin replied with an error
503  debugs(88, 3, "origin replied with error " << status << ", forwarding to client due to fail_on_validation_err");
505  return;
506  }
507 
508  // ignore and let client have old entry
510  debugs(88, 3, "origin replied with error " << status << ", sending old entry (" << oldStatus << ") to client");
512 }
513 
516 
524 void
526 {
527  clientReplyContext *context = (clientReplyContext *)data;
528  context->cacheHit(result);
529 }
530 
534 void
536 {
538  if (deleting) {
539  debugs(88, 3, "HIT object being deleted. Ignore the HIT.");
540  return;
541  }
542 
543  StoreEntry *e = http->storeEntry();
544 
545  HttpRequest *r = http->request;
546 
547  debugs(88, 3, "clientCacheHit: " << http->uri << ", " << result.length << " bytes");
548 
549  if (http->storeEntry() == NULL) {
550  debugs(88, 3, "clientCacheHit: request aborted");
551  return;
552  } else if (result.flags.error) {
553  /* swap in failure */
554  debugs(88, 3, "clientCacheHit: swapin failure for " << http->uri);
557  processMiss();
558  return;
559  }
560 
561  // The previously identified hit suddenly became unshareable!
562  // This is common for collapsed forwarding slaves but might also
563  // happen to regular hits because we are called asynchronously.
564  if (!e->mayStartHitting()) {
565  debugs(88, 3, "unshareable " << *e << ". MISS");
567  processMiss();
568  return;
569  }
570 
571  if (result.length == 0) {
572  debugs(88, 5, "store IO buffer has no content. MISS");
573  /* the store couldn't get enough data from the file for us to id the
574  * object
575  */
576  /* treat as a miss */
578  processMiss();
579  return;
580  }
581 
583  /* update size of the request */
584  reqsize = result.length + reqofs;
585 
586  /*
587  * Got the headers, now grok them
588  */
590 
591  if (http->request->storeId().cmp(e->mem_obj->storeId()) != 0) {
592  debugs(33, DBG_IMPORTANT, "clientProcessHit: URL mismatch, '" << e->mem_obj->storeId() << "' != '" << http->request->storeId() << "'");
593  http->updateLoggingTags(LOG_TCP_MISS); // we lack a more precise LOG_*_MISS code
594  processMiss();
595  return;
596  }
597 
598  switch (varyEvaluateMatch(e, r)) {
599 
600  case VARY_NONE:
601  /* No variance detected. Continue as normal */
602  break;
603 
604  case VARY_MATCH:
605  /* This is the correct entity for this request. Continue */
606  debugs(88, 2, "clientProcessHit: Vary MATCH!");
607  break;
608 
609  case VARY_OTHER:
610  /* This is not the correct entity for this request. We need
611  * to requery the cache.
612  */
614  e = NULL;
615  /* Note: varyEvalyateMatch updates the request with vary information
616  * so we only get here once. (it also takes care of cancelling loops)
617  */
618  debugs(88, 2, "clientProcessHit: Vary detected!");
620  return;
621 
622  case VARY_CANCEL:
623  /* varyEvaluateMatch found a object loop. Process as miss */
624  debugs(88, DBG_IMPORTANT, "clientProcessHit: Vary object loop!");
625  http->updateLoggingTags(LOG_TCP_MISS); // we lack a more precise LOG_*_MISS code
626  processMiss();
627  return;
628  }
629 
630  if (r->method == Http::METHOD_PURGE) {
631  debugs(88, 5, "PURGE gets a HIT");
633  e = NULL;
634  purgeRequest();
635  return;
636  }
637 
638  if (e->checkNegativeHit() && !r->flags.noCacheHack()) {
639  debugs(88, 5, "negative-HIT");
641  sendMoreData(result);
642  return;
643  } else if (blockedHit()) {
644  debugs(88, 5, "send_hit forces a MISS");
646  processMiss();
647  return;
648  } else if (!http->flags.internal && refreshCheckHTTP(e, r)) {
649  debugs(88, 5, "clientCacheHit: in refreshCheck() block");
650  /*
651  * We hold a stale copy; it needs to be validated
652  */
653  /*
654  * The 'needValidation' flag is used to prevent forwarding
655  * loops between siblings. If our copy of the object is stale,
656  * then we should probably only use parents for the validation
657  * request. Otherwise two siblings could generate a loop if
658  * both have a stale version of the object.
659  */
660  r->flags.needValidation = true;
661 
662  if (e->lastModified() < 0) {
663  debugs(88, 3, "validate HIT object? NO. Can't calculate entry modification time. Do MISS.");
664  /*
665  * We cannot revalidate entries without knowing their
666  * modification time.
667  * XXX: BUG 1890 objects without Date do not get one added.
668  */
670  processMiss();
671  } else if (r->flags.noCache) {
672  debugs(88, 3, "validate HIT object? NO. Client sent CC:no-cache. Do CLIENT_REFRESH_MISS");
673  /*
674  * This did not match a refresh pattern that overrides no-cache
675  * we should honour the client no-cache header.
676  */
678  processMiss();
679  } else if (r->url.getScheme() == AnyP::PROTO_HTTP || r->url.getScheme() == AnyP::PROTO_HTTPS) {
680  debugs(88, 3, "validate HIT object? YES.");
681  /*
682  * Object needs to be revalidated
683  * XXX This could apply to FTP as well, if Last-Modified is known.
684  */
685  processExpired();
686  } else {
687  debugs(88, 3, "validate HIT object? NO. Client protocol non-HTTP. Do MISS.");
688  /*
689  * We don't know how to re-validate other protocols. Handle
690  * them as if the object has expired.
691  */
693  processMiss();
694  }
695  return;
696  } else if (r->conditional()) {
697  debugs(88, 5, "conditional HIT");
698  if (processConditional())
699  return;
700  }
701 
702  /*
703  * plain ol' cache hit
704  */
705  debugs(88, 5, "plain old HIT");
706 
707 #if USE_DELAY_POOLS
708  if (e->store_status != STORE_OK)
710  else
711 #endif
712  if (e->mem_status == IN_MEMORY)
714  else if (Config.onoff.offline)
716 
717  sendMoreData(result);
718 }
719 
723 void
725 {
726  char *url = http->uri;
727  HttpRequest *r = http->request;
728  ErrorState *err = NULL;
729  debugs(88, 4, r->method << ' ' << url);
730 
735  if (http->storeEntry()) {
737  debugs(88, DBG_CRITICAL, "clientProcessMiss: miss on a special object (" << url << ").");
738  debugs(88, DBG_CRITICAL, "\tlog_type = " << http->loggingTags().c_str());
739  http->storeEntry()->dump(1);
740  }
741 
743  }
744 
746  if (r->method == Http::METHOD_PURGE) {
747  purgeRequest();
748  return;
749  }
750 
752  if (r->method == Http::METHOD_OTHER) {
753  purgeAllCached();
754  }
755 
757  if (http->onlyIfCached()) {
759  return;
760  }
761 
763  if (r->flags.loopDetected) {
764  http->al->http.code = Http::scForbidden;
769  return;
770  } else {
771  assert(http->out.offset == 0);
772  createStoreEntry(r->method, r->flags);
774 
775  if (http->redirect.status) {
776  const HttpReplyPointer rep(new HttpReply);
781  http->storeEntry()->complete();
782  return;
783  }
784 
786 
787  Comm::ConnectionPointer conn = http->getConn() != nullptr ? http->getConn()->clientConnection : nullptr;
790  }
791 }
792 
799 void
801 {
802  debugs(88, 4, http->request->method << ' ' << http->uri);
803  http->al->http.code = Http::scGatewayTimeout;
805  http->getConn(), http->request, http->al);
807  startError(err);
808 }
809 
811 bool
813 {
814  StoreEntry *const e = http->storeEntry();
815 
816  const auto replyStatusCode = e->mem().baseReply().sline.status();
817  if (replyStatusCode != Http::scOkay) {
818  debugs(88, 4, "miss because " << replyStatusCode << " != 200");
820  processMiss();
821  return true;
822  }
823 
824  HttpRequest &r = *http->request;
825 
827  // RFC 2616: reply with 412 Precondition Failed if If-Match did not match
829  return true;
830  }
831 
833  // RFC 7232: If-None-Match recipient MUST ignore IMS
834  r.flags.ims = false;
835  r.ims = -1;
836  r.imslen = 0;
838 
839  if (e->hasIfNoneMatchEtag(r)) {
841  return true;
842  }
843 
844  // None-Match is true (no ETag matched); treat as an unconditional hit
845  return false;
846  }
847 
848  if (r.flags.ims) {
849  // handle If-Modified-Since requests from the client
850  if (e->modifiedSince(r.ims, r.imslen)) {
851  // Modified-Since is true; treat as an unconditional hit
852  return false;
853 
854  } else {
855  // otherwise reply with 304 Not Modified
856  sendNotModified();
857  }
858  return true;
859  }
860 
861  return false;
862 }
863 
865 bool
867 {
869  return false; // hits are not blocked by default
870 
871  if (http->flags.internal)
872  return false; // internal content "hits" cannot be blocked
873 
874  const auto &rep = http->storeEntry()->mem().freshestReply();
875  {
876  std::unique_ptr<ACLFilledChecklist> chl(clientAclChecklistCreate(Config.accessList.sendHit, http));
877  chl->reply = const_cast<HttpReply*>(&rep); // ACLChecklist API bug
878  HTTPMSGLOCK(chl->reply);
879  return !chl->fastCheck().allowed(); // when in doubt, block
880  }
881 }
882 
883 // Purges all entries with a given url
884 // TODO: move to SideAgent parent, when we have one
885 /*
886  * We probably cannot purge Vary-affected responses because their MD5
887  * keys depend on vary headers.
888  */
889 void
890 purgeEntriesByUrl(HttpRequest * req, const char *url)
891 {
893  if (m.respMaybeCacheable()) {
894  const cache_key *key = storeKeyPublic(url, m);
895  debugs(88, 5, m << ' ' << url << ' ' << storeKeyText(key));
896 #if USE_HTCP
897  neighborsHtcpClear(nullptr, req, m, HTCP_CLR_INVALIDATION);
898 #else
899  (void)req;
900 #endif
901  Store::Root().evictIfFound(key);
902  }
903  }
904 }
905 
906 void
908 {
909  // XXX: performance regression, c_str() reallocates
912 }
913 
914 LogTags *
916 {
917  // XXX: clientReplyContext code assumes that http cbdata is always valid.
918  // TODO: Either add cbdataReferenceValid(http) checks in all the relevant
919  // places, like this one, or remove cbdata protection of the http member.
920  return &http->al->cache.code;
921 }
922 
923 void
925 {
926  debugs(88, 3, "Config2.onoff.enable_purge = " <<
928 
929  if (!Config2.onoff.enable_purge) {
932  http->getConn(), http->request, http->al);
933  startError(err);
934  return;
935  }
936 
937  /* Release both IP cache */
939 
940  // TODO: can we use purgeAllCached() here instead?
941  purgeDoPurge();
942 }
943 
944 void
946 {
947  auto firstFound = false;
948  if (const auto entry = storeGetPublicByRequestMethod(http->request, Http::METHOD_GET)) {
949  // special entries are only METHOD_GET entries without variance
950  if (EBIT_TEST(entry->flags, ENTRY_SPECIAL)) {
952  const auto err = clientBuildError(ERR_ACCESS_DENIED, Http::scForbidden, nullptr,
953  http->getConn(), http->request, http->al);
954  startError(err);
955  entry->abandon(__FUNCTION__);
956  return;
957  }
958  firstFound = true;
959  if (!purgeEntry(*entry, Http::METHOD_GET))
960  return;
961  }
962 
964 
965  if (const auto entry = storeGetPublicByRequestMethod(http->request, Http::METHOD_HEAD)) {
966  if (!purgeEntry(*entry, Http::METHOD_HEAD))
967  return;
968  }
969 
970  /* And for Vary, release the base URI if none of the headers was included in the request */
972  && http->request->vary_headers.find('=') != SBuf::npos) {
973  // XXX: performance regression, c_str() reallocates
975 
976  if (const auto entry = storeGetPublic(tmp.c_str(), Http::METHOD_GET)) {
977  if (!purgeEntry(*entry, Http::METHOD_GET, "Vary "))
978  return;
979  }
980 
981  if (const auto entry = storeGetPublic(tmp.c_str(), Http::METHOD_HEAD)) {
982  if (!purgeEntry(*entry, Http::METHOD_HEAD, "Vary "))
983  return;
984  }
985  }
986 
987  if (purgeStatus == Http::scNone)
989 
990  /*
991  * Make a new entry to hold the reply to be written
992  * to the client.
993  */
994  /* TODO: This doesn't need to go through the store. Simply
995  * push down the client chain
996  */
998 
1000 
1001  const HttpReplyPointer rep(new HttpReply);
1002  rep->setHeaders(purgeStatus, NULL, NULL, 0, 0, -1);
1003  http->storeEntry()->replaceHttpReply(rep);
1004  http->storeEntry()->complete();
1005 }
1006 
1007 bool
1008 clientReplyContext::purgeEntry(StoreEntry &entry, const Http::MethodType methodType, const char *descriptionPrefix)
1009 {
1010  debugs(88, 4, descriptionPrefix << Http::MethodStr(methodType) << " '" << entry.url() << "'" );
1011 #if USE_HTCP
1013 #endif
1014  entry.release(true);
1016  return true;
1017 }
1018 
1019 void
1021 {
1022  clientStreamNode *nextNode = (clientStreamNode *)node->node.next->data;
1023  StoreIOBuffer localTempBuffer;
1025  localTempBuffer.offset = nextNode->readBuffer.offset + headers_sz;
1026  localTempBuffer.length = nextNode->readBuffer.length;
1027  localTempBuffer.data = nextNode->readBuffer.data;
1029  localTempBuffer, SendMoreData, this);
1031  http->storeEntry()->buffer();
1032  const HttpReplyPointer rep(new HttpReply);
1033  rep->setHeaders(Http::scOkay, NULL, "text/plain", http->request->prefixLen(), 0, squid_curtime);
1034  http->storeEntry()->replaceHttpReply(rep);
1036  http->storeEntry()->complete();
1037 }
1038 
1039 #define SENDING_BODY 0
1040 #define SENDING_HDRSONLY 1
1041 int
1043 {
1044  StoreEntry *entry = http->storeEntry();
1045 
1046  if (entry == NULL)
1047  return 0;
1048 
1049  /*
1050  * For now, 'done_copying' is used for special cases like
1051  * Range and HEAD requests.
1052  */
1053  if (http->flags.done_copying)
1054  return 1;
1055 
1057  // last-chunk was not sent
1058  return 0;
1059  }
1060 
1061  /*
1062  * Handle STORE_OK objects.
1063  * objectLen(entry) will be set proprely.
1064  * RC: Does objectLen(entry) include the Headers?
1065  * RC: Yes.
1066  */
1067  if (entry->store_status == STORE_OK) {
1068  return storeOKTransferDone();
1069  } else {
1070  return storeNotOKTransferDone();
1071  }
1072 }
1073 
1074 int
1076 {
1077  assert(http->storeEntry()->objectLen() >= 0);
1079  if (http->out.offset >= http->storeEntry()->objectLen() - headers_sz) {
1080  debugs(88,3,HERE << "storeOKTransferDone " <<
1081  " out.offset=" << http->out.offset <<
1082  " objectLen()=" << http->storeEntry()->objectLen() <<
1083  " headers_sz=" << headers_sz);
1084  return 1;
1085  }
1086 
1087  return 0;
1088 }
1089 
1090 int
1092 {
1093  /*
1094  * Now, handle STORE_PENDING objects
1095  */
1096  MemObject *mem = http->storeEntry()->mem_obj;
1097  assert(mem != NULL);
1098  assert(http->request != NULL);
1099 
1100  /* mem->reply was wrong because it uses the UPSTREAM header length!!! */
1101  if (headers_sz == 0)
1102  /* haven't found end of headers yet */
1103  return 0;
1104 
1105  // TODO: Use MemObject::expectedReplySize(method) after resolving XXX below.
1106  const auto expectedBodySize = mem->baseReply().content_length;
1107 
1108  // XXX: The code below talks about sending data, and checks stats about
1109  // bytes written to the client connection, but this method must determine
1110  // whether we are done _receiving_ data from Store. This code should work OK
1111  // when expectedBodySize is unknown or matches written data, but it may
1112  // malfunction when we are writing ranges while receiving a full response.
1113 
1114  /*
1115  * Figure out how much data we are supposed to send.
1116  * If we are sending a body and we don't have a content-length,
1117  * then we must wait for the object to become STORE_OK.
1118  */
1119  if (expectedBodySize < 0)
1120  return 0;
1121 
1122  const uint64_t expectedLength = expectedBodySize + http->out.headers_sz;
1123 
1124  if (http->out.size < expectedLength)
1125  return 0;
1126  else {
1127  debugs(88,3,HERE << "storeNotOKTransferDone " <<
1128  " out.size=" << http->out.size <<
1129  " expectedLength=" << expectedLength);
1130  return 1;
1131  }
1132 }
1133 
1134 /* Preconditions:
1135  * *http is a valid structure.
1136  * fd is either -1, or an open fd.
1137  *
1138  * TODO: enumify this
1139  *
1140  * This function is used by any http request sink, to determine the status
1141  * of the object.
1142  */
1145 {
1146  clientReplyContext *context = dynamic_cast<clientReplyContext *>(aNode->data.getRaw());
1147  assert (context);
1148  assert (context->http == http);
1149  return context->replyStatus();
1150 }
1151 
1154 {
1155  int done;
1156  /* Here because lower nodes don't need it */
1157 
1158  if (http->storeEntry() == NULL) {
1159  debugs(88, 5, "clientReplyStatus: no storeEntry");
1160  return STREAM_FAILED; /* yuck, but what can we do? */
1161  }
1162 
1164  /* TODO: Could upstream read errors (result.flags.error) be
1165  * lost, and result in undersize requests being considered
1166  * complete. Should we tcp reset such connections ?
1167  */
1168  debugs(88, 5, "clientReplyStatus: aborted storeEntry");
1169  return STREAM_FAILED;
1170  }
1171 
1172  if ((done = checkTransferDone()) != 0 || flags.complete) {
1173  debugs(88, 5, "clientReplyStatus: transfer is DONE: " << done << flags.complete);
1174  /* Ok we're finished, but how? */
1175 
1177  debugs(88, 5, "clientReplyStatus: truncated response body");
1179  }
1180 
1181  if (!done) {
1182  debugs(88, 5, "clientReplyStatus: closing, !done, but read 0 bytes");
1183  return STREAM_FAILED;
1184  }
1185 
1186  // TODO: See also (and unify with) storeNotOKTransferDone() checks.
1187  const int64_t expectedBodySize =
1189  if (expectedBodySize >= 0 && !http->gotEnough()) {
1190  debugs(88, 5, "clientReplyStatus: client didn't get all it expected");
1192  }
1193 
1194  debugs(88, 5, "clientReplyStatus: stream complete; keepalive=" <<
1196  return STREAM_COMPLETE;
1197  }
1198 
1199  // XXX: Should this be checked earlier? We could return above w/o checking.
1200  if (reply->receivedBodyTooLarge(*http->request, http->out.offset - 4096)) {
1201  /* 4096 is a margin for the HTTP headers included in out.offset */
1202  debugs(88, 5, "clientReplyStatus: client reply body is too large");
1203  return STREAM_FAILED;
1204  }
1205 
1206  return STREAM_NONE;
1207 }
1208 
1209 /* Responses with no body will not have a content-type header,
1210  * which breaks the rep_mime_type acl, which
1211  * coincidentally, is the most common acl for reply access lists.
1212  * A better long term fix for this is to allow acl matches on the various
1213  * status codes, and then supply a default ruleset that puts these
1214  * codes before any user defines access entries. That way the user
1215  * can choose to block these responses where appropriate, but won't get
1216  * mysterious breakages.
1217  */
1218 bool
1220 {
1221  bool result;
1222 
1223  switch (sline) {
1224 
1225  case Http::scContinue:
1226 
1228 
1229  case Http::scProcessing:
1230 
1231  case Http::scNoContent:
1232 
1233  case Http::scNotModified:
1234  result = true;
1235  break;
1236 
1237  default:
1238  result = false;
1239  }
1240 
1241  return result;
1242 }
1243 
1251 void
1253 {
1254  HttpHeader *hdr = &reply->header;
1255  const bool is_hit = http->loggingTags().isTcpHit();
1257 
1258  if (is_hit || collapsedRevalidation == crSlave)
1260  // TODO: RFC 2965 : Must honour Cache-Control: no-cache="set-cookie2" and remove header.
1261 
1262  // if there is not configured a peer proxy with login=PASS or login=PASSTHRU option enabled
1263  // remove the Proxy-Authenticate header
1264  if ( !request->peer_login || (strcmp(request->peer_login,"PASS") != 0 && strcmp(request->peer_login,"PASSTHRU") != 0)) {
1265 #if USE_ADAPTATION
1266  // but allow adaptation services to authenticate clients
1267  // via request satisfaction
1268  if (!http->requestSatisfactionMode())
1269 #endif
1271  }
1272 
1274  // paranoid: ContentLengthInterpreter has cleaned non-generated replies
1276 
1277  // if (request->range)
1278  // clientBuildRangeHeader(http, reply);
1279 
1280  /*
1281  * Add a estimated Age header on cache hits.
1282  */
1283  if (is_hit) {
1284  /*
1285  * Remove any existing Age header sent by upstream caches
1286  * (note that the existing header is passed along unmodified
1287  * on cache misses)
1288  */
1290  /*
1291  * This adds the calculated object age. Note that the details of the
1292  * age calculation is performed by adjusting the timestamp in
1293  * StoreEntry::timestampsSet(), not here.
1294  */
1298  } else if (http->getConn() && http->getConn()->port->actAsOrigin) {
1299  // Swap the Date: header to current time if we are simulating an origin
1301  if (h)
1302  hdr->putExt("X-Origin-Date", h->value.termedBuf());
1306  if (h && http->storeEntry()->expires >= 0) {
1307  hdr->putExt("X-Origin-Expires", h->value.termedBuf());
1310  }
1311  if (http->storeEntry()->timestamp <= squid_curtime) {
1312  // put X-Cache-Age: instead of Age:
1313  char age[64];
1314  snprintf(age, sizeof(age), "%" PRId64, static_cast<int64_t>(squid_curtime - http->storeEntry()->timestamp));
1315  hdr->putExt("X-Cache-Age", age);
1316  }
1317  } else if (http->storeEntry()->timestamp <= squid_curtime) {
1320  /* Signal old objects. NB: rfc 2616 is not clear,
1321  * by implication, on whether we should do this to all
1322  * responses, or only cache hits.
1323  * 14.46 states it ONLY applies for heuristically calculated
1324  * freshness values, 13.2.4 doesn't specify the same limitation.
1325  * We interpret RFC 2616 under the combination.
1326  */
1327  /* TODO: if maxage or s-maxage is present, don't do this */
1328 
1329  if (squid_curtime - http->storeEntry()->timestamp >= 86400)
1330  hdr->putWarning(113, "This cache hit is still fresh and more than 1 day old");
1331  }
1332  }
1333 
1334  /* RFC 2616: Section 14.18
1335  *
1336  * Add a Date: header if missing.
1337  * We have access to a clock therefore are required to amend any shortcoming in servers.
1338  *
1339  * NP: done after Age: to prevent ENTRY_SPECIAL double-handling this header.
1340  */
1341  if ( !hdr->has(Http::HdrType::DATE) ) {
1342  if (!http->storeEntry())
1344  else if (http->storeEntry()->timestamp > 0)
1346  else {
1347  debugs(88,DBG_IMPORTANT,"BUG 3279: HTTP reply without Date:");
1348  /* dump something useful about the problem */
1350  }
1351  }
1352 
1353  // add Warnings required by RFC 2616 if serving a stale hit
1355  hdr->putWarning(110, "Response is stale");
1357  hdr->putWarning(111, "Revalidation failed");
1358  }
1359 
1360  /* Filter unproxyable authentication types */
1361  if (http->loggingTags().oldType != LOG_TCP_DENIED &&
1364  HttpHeaderEntry *e;
1365 
1366  int connection_auth_blocked = 0;
1367  while ((e = hdr->getEntry(&pos))) {
1368  if (e->id == Http::HdrType::WWW_AUTHENTICATE) {
1369  const char *value = e->value.rawBuf();
1370 
1371  if ((strncasecmp(value, "NTLM", 4) == 0 &&
1372  (value[4] == '\0' || value[4] == ' '))
1373  ||
1374  (strncasecmp(value, "Negotiate", 9) == 0 &&
1375  (value[9] == '\0' || value[9] == ' '))
1376  ||
1377  (strncasecmp(value, "Kerberos", 8) == 0 &&
1378  (value[8] == '\0' || value[8] == ' '))) {
1379  if (request->flags.connectionAuthDisabled) {
1380  hdr->delAt(pos, connection_auth_blocked);
1381  continue;
1382  }
1383  request->flags.mustKeepalive = true;
1384  if (!request->flags.accelerated && !request->flags.intercepted) {
1385  httpHeaderPutStrf(hdr, Http::HdrType::PROXY_SUPPORT, "Session-Based-Authentication");
1386  /*
1387  We send "Connection: Proxy-Support" header to mark
1388  Proxy-Support as a hop-by-hop header for intermediaries that do not
1389  understand the semantics of this header. The RFC should have included
1390  this recommendation.
1391  */
1392  httpHeaderPutStrf(hdr, Http::HdrType::CONNECTION, "Proxy-support");
1393  }
1394  break;
1395  }
1396  }
1397  }
1398 
1399  if (connection_auth_blocked)
1400  hdr->refreshMask();
1401  }
1402 
1403 #if USE_AUTH
1404  /* Handle authentication headers */
1405  if (http->loggingTags().oldType == LOG_TCP_DENIED &&
1408  ) {
1409  /* Add authentication header */
1410  /* TODO: alter errorstate to be accel on|off aware. The 0 on the next line
1411  * depends on authenticate behaviour: all schemes to date send no extra
1412  * data on 407/401 responses, and do not check the accel state on 401/407
1413  * responses
1414  */
1415  Auth::UserRequest::AddReplyAuthHeader(reply, request->auth_user_request, request, 0, 1);
1416  } else if (request->auth_user_request != NULL)
1418 #endif
1419 
1420  SBuf cacheStatus(uniqueHostname());
1421  if (const auto hitOrFwd = http->loggingTags().cacheStatusSource())
1422  cacheStatus.append(hitOrFwd);
1423  if (firstStoreLookup_) {
1424  cacheStatus.append(";detail=");
1425  cacheStatus.append(firstStoreLookup_);
1426  }
1427  // TODO: Remove c_str() after converting HttpHeaderEntry::value to SBuf
1428  hdr->putStr(Http::HdrType::CACHE_STATUS, cacheStatus.c_str());
1429 
1430  const bool maySendChunkedReply = !request->multipartRangeRequest() &&
1431  reply->sline.version.protocol == AnyP::PROTO_HTTP && // response is HTTP
1432  (request->http_ver >= Http::ProtocolVersion(1,1));
1433 
1434  /* Check whether we should send keep-alive */
1435  if (!Config.onoff.error_pconns && reply->sline.status() >= 400 && !request->flags.mustKeepalive) {
1436  debugs(33, 3, "clientBuildReplyHeader: Error, don't keep-alive");
1437  request->flags.proxyKeepalive = false;
1438  } else if (!Config.onoff.client_pconns && !request->flags.mustKeepalive) {
1439  debugs(33, 2, "clientBuildReplyHeader: Connection Keep-Alive not requested by admin or client");
1440  request->flags.proxyKeepalive = false;
1441  } else if (request->flags.proxyKeepalive && shutting_down) {
1442  debugs(88, 3, "clientBuildReplyHeader: Shutting down, don't keep-alive.");
1443  request->flags.proxyKeepalive = false;
1444  } else if (request->flags.connectionAuth && !reply->keep_alive) {
1445  debugs(33, 2, "clientBuildReplyHeader: Connection oriented auth but server side non-persistent");
1446  request->flags.proxyKeepalive = false;
1447  } else if (reply->bodySize(request->method) < 0 && !maySendChunkedReply) {
1448  debugs(88, 3, "clientBuildReplyHeader: can't keep-alive, unknown body size" );
1449  request->flags.proxyKeepalive = false;
1450  } else if (fdUsageHigh()&& !request->flags.mustKeepalive) {
1451  debugs(88, 3, "clientBuildReplyHeader: Not many unused FDs, can't keep-alive");
1452  request->flags.proxyKeepalive = false;
1453  } else if (request->flags.sslBumped && !reply->persistent()) {
1454  // We do not really have to close, but we pretend we are a tunnel.
1455  debugs(88, 3, "clientBuildReplyHeader: bumped reply forces close");
1456  request->flags.proxyKeepalive = false;
1457  } else if (request->pinnedConnection() && !reply->persistent()) {
1458  // The peer wants to close the pinned connection
1459  debugs(88, 3, "pinned reply forces close");
1460  request->flags.proxyKeepalive = false;
1461  } else if (http->getConn()) {
1462  ConnStateData * conn = http->getConn();
1463  if (!Comm::IsConnOpen(conn->port->listenConn)) {
1464  // The listening port closed because of a reconfigure
1465  debugs(88, 3, "listening port closed");
1466  request->flags.proxyKeepalive = false;
1467  }
1468  }
1469 
1470  // Decide if we send chunked reply
1471  if (maySendChunkedReply && reply->bodySize(request->method) < 0) {
1472  debugs(88, 3, "clientBuildReplyHeader: chunked reply");
1473  request->flags.chunkedReply = true;
1474  hdr->putStr(Http::HdrType::TRANSFER_ENCODING, "chunked");
1475  }
1476 
1477  hdr->addVia(reply->sline.version);
1478 
1479  /* Signal keep-alive or close explicitly */
1480  hdr->putStr(Http::HdrType::CONNECTION, request->flags.proxyKeepalive ? "keep-alive" : "close");
1481 
1482 #if ADD_X_REQUEST_URI
1483  /*
1484  * Knowing the URI of the request is useful when debugging persistent
1485  * connections in a client; we cannot guarantee the order of http headers,
1486  * but X-Request-URI is likely to be the very last header to ease use from a
1487  * debugger [hdr->entries.count-1].
1488  */
1490  http->memOjbect()->url ? http->memObject()->url : http->uri);
1491 
1492 #endif
1493 
1494  /* Surrogate-Control requires Surrogate-Capability from upstream to pass on */
1495  if ( hdr->has(Http::HdrType::SURROGATE_CONTROL) ) {
1496  if (!request->header.has(Http::HdrType::SURROGATE_CAPABILITY)) {
1498  }
1499  /* TODO: else case: drop any controls intended specifically for our surrogate ID */
1500  }
1501 
1503 }
1504 
1505 void
1507 {
1508  assert(reply == NULL);
1509 
1511  HTTPMSGLOCK(reply);
1512 
1513  http->al->reply = reply;
1514 
1516  /* RFC 2616 requires us to advertise our version (but only on real HTTP traffic) */
1518  }
1519 
1520  /* do header conversions */
1521  buildReplyHeader();
1522 }
1523 
1527 void
1529 {
1530  StoreEntry *e = http->storeEntry();
1531  assert(e); // or we are not dealing with a hit
1532  // We probably have not locked the entry earlier, unfortunately. We lock it
1533  // now so that we can unlock two lines later (and trigger cleanup).
1534  // Ideally, ClientHttpRequest::storeEntry() should lock/unlock, but it is
1535  // used so inconsistently that simply adding locking there leads to bugs.
1536  e->lock("clientReplyContext::forgetHit");
1537  http->storeEntry(NULL);
1538  e->unlock("clientReplyContext::forgetHit"); // may delete e
1539 }
1540 
1541 void
1543 {
1544  HttpRequest *r = http->request;
1545 
1546  // client sent CC:no-cache or some other condition has been
1547  // encountered which prevents delivering a public/cached object.
1548  if (!r->flags.noCache || r->flags.internal) {
1549  const auto e = storeGetPublicByRequest(r);
1551  } else {
1552  // "external" no-cache requests skip Store lookups
1553  identifyFoundObject(nullptr, "no-cache");
1554  }
1555 }
1556 
1561 void
1563 {
1564  detailStoreLookup(detail);
1565 
1566  HttpRequest *r = http->request;
1567  http->storeEntry(newEntry);
1568  const auto e = http->storeEntry();
1569 
1570  /* Release IP-cache entries on reload */
1574  if (r->flags.noCache || r->flags.noCacheHack())
1576 
1577  if (!e) {
1579  debugs(85, 3, "StoreEntry is NULL - MISS");
1581  doGetMoreData();
1582  return;
1583  }
1584 
1585  if (Config.onoff.offline) {
1587  debugs(85, 3, "offline HIT " << *e);
1589  doGetMoreData();
1590  return;
1591  }
1592 
1593  if (http->redirect.status) {
1595  debugs(85, 3, "REDIRECT status forced StoreEntry to NULL (no body on 3XX responses) " << *e);
1596  forgetHit();
1598  doGetMoreData();
1599  return;
1600  }
1601 
1602  if (!e->validToSend()) {
1603  debugs(85, 3, "!storeEntryValidToSend MISS " << *e);
1604  forgetHit();
1606  doGetMoreData();
1607  return;
1608  }
1609 
1610  if (EBIT_TEST(e->flags, ENTRY_SPECIAL)) {
1611  /* \li Special entries are always hits, no matter what the client says */
1612  debugs(85, 3, "ENTRY_SPECIAL HIT " << *e);
1614  doGetMoreData();
1615  return;
1616  }
1617 
1618  if (r->flags.noCache) {
1619  debugs(85, 3, "no-cache REFRESH MISS " << *e);
1620  forgetHit();
1622  doGetMoreData();
1623  return;
1624  }
1625 
1626  if (e->hittingRequiresCollapsing() && !startCollapsingOn(*e, false)) {
1627  debugs(85, 3, "prohibited CF MISS " << *e);
1628  forgetHit();
1630  doGetMoreData();
1631  return;
1632  }
1633 
1634  debugs(85, 3, "default HIT " << *e);
1636  doGetMoreData();
1637 }
1638 
1640 void
1642 {
1643  if (!firstStoreLookup_) {
1644  debugs(85, 7, detail);
1645  firstStoreLookup_ = detail;
1646  } else {
1647  debugs(85, 7, "ignores " << detail << " after " << firstStoreLookup_);
1648  }
1649 }
1650 
1660 void
1662 {
1663  /* Test preconditions */
1664  assert(aNode != NULL);
1665  assert(cbdataReferenceValid(aNode));
1666  assert(aNode->node.prev == NULL);
1667  assert(aNode->node.next != NULL);
1668  clientReplyContext *context = dynamic_cast<clientReplyContext *>(aNode->data.getRaw());
1669  assert (context);
1670  assert(context->http == http);
1671 
1672  clientStreamNode *next = ( clientStreamNode *)aNode->node.next->data;
1673 
1674  if (!context->ourNode)
1675  context->ourNode = aNode;
1676 
1677  /* no cbdatareference, this is only used once, and safely */
1678  if (context->flags.storelogiccomplete) {
1679  StoreIOBuffer tempBuffer;
1680  tempBuffer.offset = next->readBuffer.offset + context->headers_sz;
1681  tempBuffer.length = next->readBuffer.length;
1682  tempBuffer.data = next->readBuffer.data;
1683 
1684  storeClientCopy(context->sc, http->storeEntry(),
1685  tempBuffer, clientReplyContext::SendMoreData, context);
1686  return;
1687  }
1688 
1689  if (context->http->request->method == Http::METHOD_PURGE) {
1690  context->purgeRequest();
1691  return;
1692  }
1693 
1694  // OPTIONS with Max-Forwards:0 handled in clientProcessRequest()
1695 
1696  if (context->http->request->method == Http::METHOD_TRACE) {
1697  if (context->http->request->header.getInt64(Http::HdrType::MAX_FORWARDS) == 0) {
1698  context->traceReply(aNode);
1699  return;
1700  }
1701 
1702  /* continue forwarding, not finished yet. */
1704 
1705  context->doGetMoreData();
1706  } else
1707  context->identifyStoreObject();
1708 }
1709 
1710 void
1712 {
1713  /* We still have to do store logic processing - vary, cache hit etc */
1714  if (http->storeEntry() != NULL) {
1715  /* someone found the object in the cache for us */
1716  StoreIOBuffer localTempBuffer;
1717 
1718  http->storeEntry()->lock("clientReplyContext::doGetMoreData");
1719 
1721 
1722  sc = storeClientListAdd(http->storeEntry(), this);
1723 #if USE_DELAY_POOLS
1725 #endif
1726 
1728  reqofs = 0;
1729  /* guarantee nothing has been sent yet! */
1730  assert(http->out.size == 0);
1731  assert(http->out.offset == 0);
1732 
1733  if (ConnStateData *conn = http->getConn()) {
1734  if (Ip::Qos::TheConfig.isHitTosActive()) {
1735  Ip::Qos::doTosLocalHit(conn->clientConnection);
1736  }
1737 
1738  if (Ip::Qos::TheConfig.isHitNfmarkActive()) {
1739  Ip::Qos::doNfmarkLocalHit(conn->clientConnection);
1740  }
1741  }
1742 
1743  localTempBuffer.offset = reqofs;
1744  localTempBuffer.length = getNextNode()->readBuffer.length;
1745  localTempBuffer.data = getNextNode()->readBuffer.data;
1746  storeClientCopy(sc, http->storeEntry(), localTempBuffer, CacheHit, this);
1747  } else {
1748  /* MISS CASE, http->loggingTags() are already set! */
1749  processMiss();
1750  }
1751 }
1752 
1754 void
1756 {
1758  clientStreamDetach(node, http);
1759 }
1760 
1765 void
1767 {
1768  clientReplyContext *context = static_cast<clientReplyContext *>(data);
1769  context->sendMoreData (result);
1770 }
1771 
1772 void
1774 {
1775  /* At least, I think that's what this does */
1778 }
1779 
1780 bool
1781 clientReplyContext::errorInStream(StoreIOBuffer const &result, size_t const &sizeToProcess)const
1782 {
1783  return /* aborted request */
1785  /* Upstream read error */ (result.flags.error) ||
1786  /* Upstream EOF */ (sizeToProcess == 0);
1787 }
1788 
1789 void
1791 {
1797  debugs(88, 5, "A stream error has occurred, marking as complete and sending no data.");
1798  StoreIOBuffer localTempBuffer;
1799  flags.complete = 1;
1800  http->request->flags.streamError = true;
1801  localTempBuffer.flags.error = result.flags.error;
1803  localTempBuffer);
1804 }
1805 
1806 void
1808 {
1809  StoreIOBuffer localTempBuffer;
1810 
1811  if (result.length == 0) {
1812  debugs(88, 5, "clientReplyContext::pushStreamData: marking request as complete due to 0 length store result");
1813  flags.complete = 1;
1814  }
1815 
1816  assert(result.offset - headers_sz == next()->readBuffer.offset);
1817  localTempBuffer.offset = result.offset - headers_sz;
1818  localTempBuffer.length = result.length;
1819 
1820  if (localTempBuffer.length)
1821  localTempBuffer.data = source;
1822 
1824  localTempBuffer);
1825 }
1826 
1829 {
1831  return getNextNode();
1832 }
1833 
1834 void
1836 {
1839  http->getConn(), http->request, http->al);
1842  startError(err);
1843 
1844 }
1845 
1847 void
1849 {
1851  ErrorState *const err =
1853  nullptr, http->getConn(), http->request, http->al);
1856  startError(err);
1857 }
1858 
1860 void
1862 {
1863  StoreEntry *e = http->storeEntry();
1864  const time_t timestamp = e->timestamp;
1865  const auto temprep = e->mem().freshestReply().make304();
1866  // log as TCP_INM_HIT if code 304 generated for
1867  // If-None-Match request
1868  if (!http->request->flags.ims)
1870  else
1874  e = http->storeEntry();
1875  // Copy timestamp from the original entry so the 304
1876  // reply has a meaningful Age: header.
1877  e->timestampsSet();
1878  e->timestamp = timestamp;
1879  e->replaceHttpReply(temprep);
1880  e->complete();
1881  /*
1882  * TODO: why put this in the store and then serialise it and
1883  * then parse it again. Simply mark the request complete in
1884  * our context and write the reply struct to the client side.
1885  */
1887 }
1888 
1891 void
1893 {
1894  if (http->request->method == Http::METHOD_GET ||
1896  sendNotModified();
1897  else
1899 }
1900 
1901 void
1903 {
1904  /* NP: this should probably soft-fail to a zero-sized-reply error ?? */
1905  assert(reply);
1906 
1908  if (http->loggingTags().oldType == LOG_TCP_DENIED ||
1911  headers_sz = reply->hdr_sz;
1913  return;
1914  }
1915 
1919  return;
1920  }
1921 
1922  headers_sz = reply->hdr_sz;
1923 
1925  if (!Config.accessList.reply) {
1927  return;
1928  }
1929 
1931  ACLFilledChecklist *replyChecklist =
1933  replyChecklist->reply = reply;
1934  HTTPMSGLOCK(replyChecklist->reply);
1935  replyChecklist->nonBlockingCheck(ProcessReplyAccessResult, this);
1936 }
1937 
1938 void
1940 {
1941  clientReplyContext *me = static_cast<clientReplyContext *>(voidMe);
1942  me->processReplyAccessResult(rv);
1943 }
1944 
1945 void
1947 {
1948  debugs(88, 2, "The reply for " << http->request->method
1949  << ' ' << http->uri << " is " << accessAllowed << ", because it matched "
1950  << (AclMatchedName ? AclMatchedName : "NO ACL's"));
1951 
1952  if (!accessAllowed.allowed()) {
1953  ErrorState *err;
1954  err_type page_id;
1956 
1958 
1959  if (page_id == ERR_NONE)
1960  page_id = ERR_ACCESS_DENIED;
1961 
1962  err = clientBuildError(page_id, Http::scForbidden, NULL,
1963  http->getConn(), http->request, http->al);
1964 
1966 
1968 
1969  startError(err);
1970 
1971  return;
1972  }
1973 
1974  /* Ok, the reply is allowed, */
1976 
1977  ssize_t body_size = reqofs - reply->hdr_sz;
1978  if (body_size < 0) {
1979  reqofs = reply->hdr_sz;
1980  body_size = 0;
1981  }
1982 
1983  debugs(88, 3, "clientReplyContext::sendMoreData: Appending " <<
1984  (int) body_size << " bytes after " << reply->hdr_sz <<
1985  " bytes of headers");
1986 
1987 #if USE_SQUID_ESI
1988 
1992  debugs(88, 2, "Enabling ESI processing for " << http->uri);
1995  }
1996 
1997 #endif
1998 
1999  if (http->request->method == Http::METHOD_HEAD) {
2000  /* do not forward body for HEAD replies */
2001  body_size = 0;
2002  http->flags.done_copying = true;
2003  flags.complete = 1;
2004  }
2005 
2007  flags.headersSent = true;
2008 
2009  StoreIOBuffer localTempBuffer;
2010  char *buf = next()->readBuffer.data;
2011  char *body_buf = buf + reply->hdr_sz;
2012 
2013  //Server side may disable ranges under some circumstances.
2014 
2015  if ((!http->request->range))
2016  next()->readBuffer.offset = 0;
2017 
2018  body_buf -= next()->readBuffer.offset;
2019 
2020  if (next()->readBuffer.offset != 0) {
2021  if (next()->readBuffer.offset > body_size) {
2022  /* Can't use any of the body we received. send nothing */
2023  localTempBuffer.length = 0;
2024  localTempBuffer.data = NULL;
2025  } else {
2026  localTempBuffer.length = body_size - next()->readBuffer.offset;
2027  localTempBuffer.data = body_buf + next()->readBuffer.offset;
2028  }
2029  } else {
2030  localTempBuffer.length = body_size;
2031  localTempBuffer.data = body_buf;
2032  }
2033 
2034  /* TODO??: move the data in the buffer back by the request header size */
2036  http, reply, localTempBuffer);
2037 
2038  return;
2039 }
2040 
2041 void
2043 {
2044  if (deleting)
2045  return;
2046 
2047  StoreEntry *entry = http->storeEntry();
2048 
2049  if (ConnStateData * conn = http->getConn()) {
2050  if (!conn->isOpen()) {
2051  debugs(33,3, "not sending more data to closing connection " << conn->clientConnection);
2052  return;
2053  }
2054  if (conn->pinning.zeroReply) {
2055  debugs(33,3, "not sending more data after a pinned zero reply " << conn->clientConnection);
2056  return;
2057  }
2058 
2059  if (reqofs==0 && !http->loggingTags().isTcpHit()) {
2060  if (Ip::Qos::TheConfig.isHitTosActive()) {
2061  Ip::Qos::doTosLocalMiss(conn->clientConnection, http->request->hier.code);
2062  }
2063  if (Ip::Qos::TheConfig.isHitNfmarkActive()) {
2064  Ip::Qos::doNfmarkLocalMiss(conn->clientConnection, http->request->hier.code);
2065  }
2066  }
2067 
2068  debugs(88, 5, conn->clientConnection <<
2069  " '" << entry->url() << "'" <<
2070  " out.offset=" << http->out.offset);
2071  }
2072 
2073  char *buf = next()->readBuffer.data;
2074 
2075  if (buf != result.data) {
2076  /* we've got to copy some data */
2077  assert(result.length <= next()->readBuffer.length);
2078  memcpy(buf, result.data, result.length);
2079  }
2080 
2081  /* We've got the final data to start pushing... */
2083 
2084  reqofs += result.length;
2085 
2087 
2088  assert(http->request != NULL);
2089 
2090  /* ESI TODO: remove this assert once everything is stable */
2093 
2094  makeThisHead();
2095 
2096  debugs(88, 5, "clientReplyContext::sendMoreData: " << http->uri << ", " <<
2097  reqofs << " bytes (" << result.length <<
2098  " new bytes)");
2099 
2100  /* update size of the request */
2101  reqsize = reqofs;
2102 
2103  if (errorInStream(result, reqofs)) {
2104  sendStreamError(result);
2105  return;
2106  }
2107 
2108  if (flags.headersSent) {
2109  pushStreamData (result, buf);
2110  return;
2111  }
2112 
2113  cloneReply();
2114 
2115 #if USE_DELAY_POOLS
2116  if (sc)
2118 #endif
2119 
2120  holdingBuffer = result;
2122  return;
2123 }
2124 
2125 void
2127 {
2128  clientAclChecklistFill(checklist, http);
2129 }
2130 
2131 /* Using this breaks the client layering just a little!
2132  */
2133 void
2135 {
2136  assert(http != NULL);
2137  /*
2138  * For erroneous requests, we might not have a h->request,
2139  * so make a fake one.
2140  */
2141 
2142  if (http->request == NULL) {
2144  // XXX: These fake URI parameters shadow the real (or error:...) URI.
2145  // TODO: Either always set the request earlier and assert here OR use
2146  // http->uri (converted to Anyp::Uri) to create this catch-all request.
2147  const_cast<HttpRequest *&>(http->request) = new HttpRequest(m, AnyP::PROTO_NONE, "http", null_string, mx);
2149  }
2150 
2151  StoreEntry *e = storeCreateEntry(storeId(), http->log_uri, reqFlags, m);
2152 
2153  // Make entry collapsible ASAP, to increase collapsing chances for others,
2154  // TODO: every must-revalidate and similar request MUST reach the origin,
2155  // but do we have to prohibit others from collapsing on that request?
2156  if (reqFlags.cachable &&
2157  !reqFlags.needValidation &&
2158  (m == Http::METHOD_GET || m == Http::METHOD_HEAD) &&
2160  // make the entry available for future requests now
2161  (void)Store::Root().allowCollapsing(e, reqFlags, m);
2162  }
2163 
2164  sc = storeClientListAdd(e, this);
2165 
2166 #if USE_DELAY_POOLS
2168 #endif
2169 
2170  reqofs = 0;
2171 
2172  reqsize = 0;
2173 
2174  /* I don't think this is actually needed! -- adrian */
2175  /* http->reqbuf = http->norm_reqbuf; */
2176  // assert(http->reqbuf == http->norm_reqbuf);
2177  /* The next line is illegal because we don't know if the client stream
2178  * buffers have been set up
2179  */
2180  // storeClientCopy(http->sc, e, 0, HTTP_REQBUF_SZ, http->reqbuf,
2181  // SendMoreData, this);
2182  /* So, we mark the store logic as complete */
2184 
2185  /* and get the caller to request a read, from wherever they are */
2186  /* NOTE: after ANY data flows down the pipe, even one step,
2187  * this function CAN NOT be used to manage errors
2188  */
2189  http->storeEntry(e);
2190 }
2191 
2192 ErrorState *
2193 clientBuildError(err_type page_id, Http::StatusCode status, char const *url,
2195 {
2196  const auto err = new ErrorState(page_id, status, request, al);
2197  err->src_addr = conn && conn->clientConnection ? conn->clientConnection->remote : Ip::Address::NoAddr();
2198 
2199  if (url)
2200  err->url = xstrdup(url);
2201 
2202  return err;
2203 }
2204 
@ 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:47
char method[16]
Definition: tcp-banger2.c:115
void refreshMask()
Definition: HttpHeader.cc:750
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:93
virtual void buffer()
Definition: store.cc:1618
size_type find(char c, size_type startPos=0) const
Definition: SBuf.cc:584
void removeClientStoreReference(store_client **scp, ClientHttpRequest *http)
bool expectedBodyTooLarge(HttpRequest &request)
Definition: HttpReply.cc:525
time_t timestamp
Definition: Store.h:225
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:629
@ scUnauthorized
Definition: StatusCode.h:45
@ METHOD_HEAD
Definition: MethodType.h:28
StoreIOBuffer tempBuffer
dlink_node node
Definition: clientStream.h:87
const char * uniqueHostname(void)
Definition: tools.cc:494
AnyP::Uri url
the request URI
Definition: HttpRequest.h:115
Definition: ETag.h:18
@ scProcessing
Definition: StatusCode.h:24
@ VARY_NONE
Definition: enums.h:193
ClientStreamData data
Definition: clientStream.h:93
int esiEnableProcessing(HttpReply *rep)
Definition: Esi.cc:2239
ClientHttpRequest * http
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:1606
const char * storeId() const
Definition: MemObject.cc:53
CSS clientReplyStatus
void releaseRequest(const bool shareable=false)
Definition: store.cc:472
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:94
void removeHopByHopEntries()
Definition: HttpHeader.cc:1738
HttpHeader header
Definition: Message.h:75
void ipcacheInvalidate(const char *name)
Definition: ipcache.cc:856
void errorAppendEntry(StoreEntry *entry, ErrorState *err)
Definition: errorpage.cc:720
bool isEmpty() const
Definition: SBuf.h:424
void purgeDoPurge()
releases both cached GET and HEAD entries
MemObject * mem_obj
Definition: Store.h:222
RequestFlags flags
Definition: HttpRequest.h:141
void sendNotModifiedOrPreconditionFailedError()
int varyEvaluateMatch(StoreEntry *entry, HttpRequest *request)
int fdUsageHigh(void)
Definition: fd.cc:272
ssize_t HttpHeaderPos
Definition: HttpHeader.h:45
const cache_key * storeKeyPublic(const char *url, const HttpRequestMethod &method, const KeyScope keyScope)
const char * cacheStatusSource() const
Definition: LogTags.cc:115
void clearPublicKeyScope()
Definition: store.cc:623
bool isTcpHit() const
determine if the log tag code indicates a cache HIT
Definition: LogTags.cc:101
struct node * next
Definition: parse.c:105
const char * url() const
Definition: store.cc:1583
ConnStateData * getConn() const
@ PROTO_NONE
Definition: ProtocolType.h:24
void createStoreEntry(const HttpRequestMethod &m, RequestFlags flags)
@ STREAM_NONE
Definition: enums.h:126
virtual void fillChecklist(ACLFilledChecklist &) const
configure the given checklist (to reflect the current transaction state)
@ ksRevalidation
Definition: store_key_md5.h:20
static bool SmpAware()
whether there are any SMP-aware storages
Definition: Controller.cc:916
MemObject & mem()
Definition: Store.h:52
#define HttpHeaderInitPos
Definition: HttpHeader.h:48
void lock(const char *context)
Definition: store.cc:459
void ipcacheInvalidateNegative(const char *name)
Definition: ipcache.cc:873
bool loopDetected
Definition: RequestFlags.h:36
int doTosLocalMiss(const Comm::ConnectionPointer &conn, const hier_code hierCode)
Definition: QosConfig.cc:225
void httpHdrMangleList(HttpHeader *l, HttpRequest *request, const AccessLogEntryPointer &al, req_or_rep_t req_or_rep)
int64_t bodySize(const HttpRequestMethod &) const
Definition: HttpReply.cc:375
int64_t offset
Definition: StoreIOBuffer.h:55
Definition: SBuf.h:87
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 updateLoggingTags(const LogTags_ot code)
update the code in the transaction processing tags
void sendStreamError(StoreIOBuffer const &result)
void removeStoreReference(store_client **scp, StoreEntry **ep)
void setReplyToError(err_type, Http::StatusCode, const HttpRequestMethod &, char const *, const ConnStateData *, HttpRequest *, const char *, Auth::UserRequest::Pointer)
builds error using clientBuildError() and calls setReplyToError() below
struct ClientHttpRequest::Flags flags
@ LOG_TCP_CLIENT_REFRESH_MISS
Definition: LogTags.h:46
clientStream_status_t CSS(clientStreamNode *, ClientHttpRequest *)
struct ClientHttpRequest::Out out
C * getRaw() const
Definition: RefCount.h:80
uint16_t flags
Definition: Store.h:233
int cbdataReferenceValid(const void *p)
Definition: cbdata.cc:398
Acl::Answer const & fastCheck()
Definition: Checklist.cc:332
bool IsConnOpen(const Comm::ConnectionPointer &conn)
Definition: Connection.cc:27
Http::StatusLine sline
Definition: HttpReply.h:56
time_t expires
Definition: Store.h:227
void HTTPMSGUNLOCK(M *&a)
Definition: Message.h:150
struct StoreIOBuffer::@147 flags
int64_t objectLen() const
Definition: Store.h:258
@ ERR_NONE
Definition: forward.h:15
void replaceHttpReply(const HttpReplyPointer &, const bool andStartWriting=true)
Definition: store.cc:1722
#define DBG_CRITICAL
Definition: Debug.h:40
@ STREAM_COMPLETE
Definition: enums.h:127
StatusCode
Definition: StatusCode.h:20
err_type
Definition: forward.h:14
Definition: forward.h:22
CSS esiStreamStatus
#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:362
@ VARY_CANCEL
Definition: enums.h:196
@ LOG_TCP_HIT
Definition: LogTags.h:39
@ IF_MODIFIED_SINCE
#define DBG_IMPORTANT
Definition: Debug.h:41
bool conditional() const
has at least one recognized If-* header
Definition: HttpRequest.cc:580
void httpHeaderPutStrf(HttpHeader *hdr, Http::HdrType id, const char *fmt,...)
StoreEntry * storeGetPublicByRequest(HttpRequest *req, const KeyScope keyScope)
Definition: store.cc:530
AclDenyInfoList * denyInfoList
Definition: SquidConfig.h:415
ProtocolType protocol
which protocol this version is for
@ LOG_TCP_MISS
Definition: LogTags.h:40
int refreshCheckHTTP(const StoreEntry *entry, HttpRequest *request)
Definition: refresh.cc:585
StoreIOBuffer holdingBuffer
bool allowCollapsing(StoreEntry *, const RequestFlags &, const HttpRequestMethod &)
tries to make the entry available for collapsing future requests
Definition: Controller.cc:754
CollapsedRevalidation collapsedRevalidation
StoreEntry * storeGetPublicByRequestMethod(HttpRequest *req, const HttpRequestMethod &method, const KeyScope keyScope)
Definition: store.cc:524
@ STREAM_FAILED
Definition: enums.h:137
void sendPreconditionFailedError()
send 412 (Precondition Failed) to client
@ LOG_TCP_REFRESH_FAIL_OLD
Definition: LogTags.h:42
AnyP::UriScheme const & getScheme() const
Definition: Uri.h:67
const char * c_str() const
compute the status access.log field
Definition: LogTags.cc:66
bool noCacheHack() const
Definition: RequestFlags.h:124
void clientStreamDetach(clientStreamNode *thisObject, ClientHttpRequest *http)
void identifyFoundObject(StoreEntry *entry, const char *detail)
HttpReply * clone() const
Definition: HttpReply.cc:573
@ ENTRY_ABORTED
Definition: enums.h:115
@ ERR_ACCESS_DENIED
Definition: forward.h:18
@ scGatewayTimeout
Definition: StatusCode.h:75
@ WWW_AUTHENTICATE
class SquidConfig2 Config2
Definition: SquidConfig.cc:14
@ ENTRY_BAD_LENGTH
Definition: enums.h:114
bool persistent() const
Definition: Message.cc:247
time_t lastmod
Definition: HttpRequest.h:167
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:243
const char * AclMatchedName
Definition: Acl.cc:29
@ LOG_TCP_DENIED_REPLY
Definition: LogTags.h:53
String etag
A strong etag of the cached entry. Used for refreshing that entry.
Definition: HttpRequest.h:191
@ VARY_MATCH
Definition: enums.h:194
acl_access * sendHit
Definition: SquidConfig.h:374
@ crSlave
we collapsed on the existing revalidation request
#define NULL
Definition: types.h:166
bool mayStartHitting() const
Definition: Store.h:289
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:43
bool hasIfNoneMatchEtag(const HttpRequest &request) const
has ETag matching at least one of the If-None-Match etags
Definition: store.cc:1881
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:42
bool errorInStream(StoreIOBuffer const &result, size_t const &sizeToProcess) const
#define debugs(SECTION, LEVEL, CONTENT)
Definition: Debug.h:123
@ IN_MEMORY
Definition: enums.h:36
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:59
@ LOG_TCP_REFRESH_MODIFIED
Definition: LogTags.h:44
@ HTCP_CLR_PURGE
Definition: enums.h:242
bool mayInitiateCollapsing() const
whether Squid configuration allows us to become a CF initiator
Definition: StoreClient.h:44
void pushStreamData(StoreIOBuffer const &result, char *source)
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:274
#define SQUIDCEXTERN
Definition: squid.h:21
void putWarning(const int code, const char *const text)
add a Warning header
Definition: HttpHeader.cc:1131
unsigned error
Definition: StoreIOBuffer.h:52
void setReplyToStoreEntry(StoreEntry *e, const char *reason)
replaces current response store entry with the given one
@ STREAM_UNPLANNED_COMPLETE
Definition: enums.h:132
void detailStoreLookup(const char *detail)
remembers the very first Store lookup classification, ignoring the rest
#define EBIT_TEST(flag, bit)
Definition: defines.h:69
int collapsed_forwarding
Definition: SquidConfig.h:330
bool failOnValidationError
Definition: RequestFlags.h:48
int error_pconns
Definition: SquidConfig.h:313
std::ostream & HERE(std::ostream &s)
Definition: Debug.h:152
void handleIMSReply(StoreIOBuffer result)
virtual void evictIfFound(const cache_key *) override
Definition: Controller.cc:506
clientStream_status_t replyStatus()
ErrorState * clientBuildError(err_type, Http::StatusCode, char const *, const ConnStateData *, HttpRequest *, const AccessLogEntry::Pointer &)
int delById(Http::HdrType id)
Definition: HttpHeader.cc:694
Http::HdrType id
Definition: HttpHeader.h:63
struct SquidConfig2::@126 onoff
struct clientReplyContext::Flags flags
static const Address & NoAddr()
Definition: Address.h:302
void putExt(const char *name, const char *value)
Definition: HttpHeader.cc:1140
int unlock(const char *context)
Definition: store.cc:483
void purgeEntriesByUrl(HttpRequest *req, const char *url)
int64_t getInt64(Http::HdrType id) const
Definition: HttpHeader.cc:1161
#define safe_free(x)
Definition: xalloc.h:73
@ LOG_TCP_REFRESH_UNMODIFIED
Definition: LogTags.h:41
store_status_t store_status
Definition: Store.h:245
int weak
true if it is a weak validator
Definition: ETag.h:21
void putTime(Http::HdrType id, time_t htime)
Definition: HttpHeader.cc:1042
struct SquidConfig::@112 accessList
int conn
the current server connection FD
Definition: Transport.cc:26
#define assert(EX)
Definition: assert.h:19
char const * termedBuf() const
Definition: SquidString.h:92
CSR esiStreamRead
@ scContinue
Definition: StatusCode.h:22
clientReplyContext(ClientHttpRequest *)
int storeOKTransferDone() const
HierarchyLogEntry hier
Definition: HttpRequest.h:157
int checkNegativeHit() const
Definition: store.cc:1313
void HTTPMSGLOCK(Http::Message *a)
Definition: Message.h:161
void neighborsHtcpClear(StoreEntry *e, HttpRequest *req, const HttpRequestMethod &method, htcp_clr_reason reason)
Definition: neighbors.cc:1816
@ TRANSFER_ENCODING
SBuf vary_headers
The variant second-stage cache key. Generated from Vary header pattern for this request.
Definition: HttpRequest.h:170
@ 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
@ ENTRY_SPECIAL
Definition: enums.h:84
@ scInternalServerError
Definition: StatusCode.h:71
HttpHdrRange * range
Definition: HttpRequest.h:143
SQUIDCEXTERN CSD clientReplyDetach
mem_status_t mem_status
Definition: Store.h:241
static int sc[16]
Definition: smbdes.c:121
const char * null_string
const char * c_str()
Definition: SBuf.cc:516
@ LOG_TCP_REFRESH
Definition: LogTags.h:45
#define CBDATA_CLASS_INIT(type)
Definition: cbdata.h:318
int prefixLen() const
Definition: HttpRequest.cc:370
void dump(int debug_lvl) const
Definition: store.cc:1516
@ STORE_OK
Definition: enums.h:50
time_t squid_curtime
Definition: stub_time.cc:17
Comm::ConnectionPointer clientConnection
Definition: Server.h:98
@ 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:48
StoreEntry * storeCreateEntry(const char *url, const char *logUrl, const RequestFlags &flags, const HttpRequestMethod &method)
Definition: store.cc:773
SBuf & append(const SBuf &S)
Definition: SBuf.cc:185
int64_t content_length
Definition: Message.h:84
int client_pconns
Definition: SquidConfig.h:311
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
@ VARY_OTHER
Definition: enums.h:195
clientStreamNode * getNextNode() const
const LogTags & loggingTags() const
the processing tags associated with this request transaction.
enum Http::_method_t MethodType
void clientStreamInsertHead(dlink_list *list, CSR *func, CSCB *callback, CSD *detach, CSS *status, ClientStreamData data)
@ METHOD_PURGE
Definition: MethodType.h:92
bool proxyKeepalive
Definition: RequestFlags.h:38
bool startCollapsingOn(const StoreEntry &, const bool doingRevalidation) const
Definition: store_client.cc:65
void complete()
Definition: store.cc:1045
@ PROTO_HTTPS
Definition: ProtocolType.h:27
void putInt(Http::HdrType id, int number)
Definition: HttpHeader.cc:1024
HttpRequestMethod method
Definition: HttpRequest.h:114
Config TheConfig
Globally available instance of Qos::Config.
Definition: QosConfig.cc:282
@ scNotFound
Definition: StatusCode.h:48
acl_access * reply
Definition: SquidConfig.h:386
HttpHeaderEntry * findEntry(Http::HdrType id) const
Definition: HttpHeader.cc:630
bool blockedHit() const
whether squid.conf send_hit prevents us from serving this hit
@ PROTO_HTTP
Definition: ProtocolType.h:25
@ LOG_TCP_DENIED
Definition: LogTags.h:52
int doNfmarkLocalMiss(const Comm::ConnectionPointer &conn, const hier_code hierCode)
Definition: QosConfig.cc:246
bool allowed() const
Definition: Acl.h:149
const char * storeId() const
struct SquidConfig::@111 onoff
int cmp(const SBuf &S, const size_type n) const
shorthand version for compare()
Definition: SBuf.h:268
AnyP::ProtocolVersion version
breakdown of protocol version label: (HTTP/ICY) and (0.9/1.0/1.1)
Definition: StatusLine.h:62
@ ERR_ONLY_IF_CACHED_MISS
Definition: forward.h:39
void updateOnNotModified(StoreEntry *old, StoreEntry &e304)
using a 304 response, update the old entry (metadata and reply headers)
Definition: Controller.cc:721
bool timestampsSet()
Definition: store.cc:1410
@ LOG_TCP_OFFLINE_HIT
Definition: LogTags.h:54
@ scNoContent
Definition: StatusCode.h:30
@ PROXY_AUTHENTICATE
@ ERR_TOO_BIG
Definition: forward.h:40
bool processConditional()
process conditional request from client
int has(Http::HdrType id) const
Definition: HttpHeader.cc:990
const SBuf storeId()
Definition: HttpRequest.cc:741
virtual LogTags * loggingTags() const
int storeNotOKTransferDone() const
void putStr(Http::HdrType id, const char *str)
Definition: HttpHeader.cc:1051
@ METHOD_NONE
Definition: MethodType.h:22
@ crNone
collapsed revalidation is not allowed for this context
clientStream_status_t
Definition: enums.h:125
#define Must(condition)
Like assert() but throws an exception instead of aborting the process.
Definition: TextException.h:73
bool alwaysAllowResponse(Http::StatusCode sline) const
@ SURROGATE_CAPABILITY
@ ACCESS_ALLOWED
Definition: Acl.h:110
const char * storeLookupString(bool found) const
@ 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:93
time_t ims
Definition: HttpRequest.h:145
StoreEntry * storeGetPublic(const char *uri, const HttpRequestMethod &method)
Definition: store.cc:518
const AccessLogEntry::Pointer al
access.log entry
void release(const bool shareable=false)
Definition: store.cc:1161
#define PRId64
Definition: types.h:110
bool purgeEntry(StoreEntry &, const Http::MethodType, const char *descriptionPrefix="")
const HttpReply & freshestReply() const
Definition: MemObject.h:67
#define HTTP_REQBUF_SZ
Definition: forward.h:14
int shutting_down
const char * firstStoreLookup_
@ LOG_TCP_REDIRECT
Definition: LogTags.h:55
store_client * old_sc
int doTosLocalHit(const Comm::ConnectionPointer &conn)
Definition: QosConfig.cc:267
clientStreamNode * next() const
void lastModified(const time_t when)
Definition: Store.h:177
void clientStreamCallback(clientStreamNode *thisObject, ClientHttpRequest *http, HttpReply *rep, StoreIOBuffer replyBuffer)
int port
port of pinned connection
Definition: client_side.h:146
StoreIOBuffer readBuffer
Definition: clientStream.h:94
void delAt(HttpHeaderPos pos, int &headers_deleted)
Definition: HttpHeader.cc:722
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)
StoreEntry * loggingEntry() const
@ scOkay
Definition: StatusCode.h:26
clientStreamNode * ourNode
void swapOut(StoreEntry *e)
Definition: HttpRequest.cc:335
HttpHeaderEntry * getEntry(HttpHeaderPos *pos) const
Definition: HttpHeader.cc:611
@ METHOD_GET
Definition: MethodType.h:25
void setDelayId(DelayId delay_id)
const SBuf & MethodStr(const MethodType m)
Definition: MethodType.h:100
void * callback_data
Definition: errorpage.h:185
bool modifiedSince(const time_t ims, const int imslen=-1) const
Definition: store.cc:1837
MemObject * memObject() const
static STCB SendMoreData
@ LOG_TCP_MEM_HIT
Definition: LogTags.h:51
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:752
unsigned complete
we have read all we can from upstream
void addVia(const AnyP::ProtocolVersion &ver, const HttpHeader *from=0)
Definition: HttpHeader.cc:998
bool hasIfMatchEtag(const HttpRequest &request) const
has ETag matching at least one of the If-Match etags
Definition: store.cc:1874
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:1863
void host(const char *src)
Definition: Uri.cc:98
struct _request * request(char *urlin)
Definition: tcp-banger2.c:291
static STCB HandleIMSReply
short int keep_alive
Definition: HttpReply.h:53
void nonBlockingCheck(ACLCB *callback, void *callback_data)
Definition: Checklist.cc:237
char const * rawBuf() const
Definition: SquidString.h:86
@ LOG_TCP_SWAPFAIL_MISS
Definition: LogTags.h:49
Http::StatusCode httpStatus
Definition: errorpage.h:171
void storeErrorResponse(HttpReply *reply)
Store a prepared error response. MemObject locks the reply object.
Definition: store.cc:1705
@ ERR_PRECONDITION_FAILED
Definition: forward.h:47
@ LOG_TCP_NEGATIVE_HIT
Definition: LogTags.h:50
CbcPointer< ConnStateData > clientConnectionManager
Definition: HttpRequest.h:232
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:120
AnyP::ProtocolVersion ProtocolVersion(unsigned int aMajor, unsigned int aMinor)
HTTP version label information.
Controller & Root()
safely access controller singleton
Definition: Controller.cc:934

 

Introduction

Documentation

Support

Miscellaneous

Web Site Translations

Mirrors