client_side_reply.cc
Go to the documentation of this file.
1/*
2 * Copyright (C) 1996-2023 The Squid Software Foundation and contributors
3 *
4 * Squid software is distributed under GPLv2+ license and includes
5 * contributions from numerous individuals and organizations.
6 * Please see the COPYING and CONTRIBUTORS files for details.
7 */
8
9/* DEBUG: section 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 "Store.h"
37#include "StrList.h"
38#include "tools.h"
39#if USE_AUTH
40#include "auth/UserRequest.h"
41#endif
42#if USE_DELAY_POOLS
43#include "DelayPools.h"
44#endif
45#if USE_SQUID_ESI
46#include "esi/Esi.h"
47#endif
48
49#include <memory>
50
52
53/* Local functions */
56
57/* privates */
58
60{
61 deleting = true;
62 /* This may trigger a callback back into SendMoreData as the cbdata
63 * is still valid
64 */
66 /* old_entry might still be set if we didn't yet get the reply
67 * code in HandleIMSReply() */
71}
72
74 purgeStatus(Http::scNone),
75 http(cbdataReference(clientContext)),
76 headers_sz(0),
77 sc(nullptr),
78 reqsize(0),
79 reqofs(0),
80 ourNode(nullptr),
81 reply(nullptr),
82 old_entry(nullptr),
83 old_sc(nullptr),
84 old_lastmod(-1),
85 old_reqofs(0),
86 old_reqsize(0),
87 deleting(false),
88 collapsedRevalidation(crNone)
89{
90 *tempbuf = 0;
91}
92
98void
100 err_type err, Http::StatusCode status, char const *uri,
101 const ConnStateData *conn, HttpRequest *failedrequest, const char *unparsedrequest,
102#if USE_AUTH
103 Auth::UserRequest::Pointer auth_user_request
104#else
105 void*
106#endif
107)
108{
109 auto errstate = clientBuildError(err, status, uri, conn, failedrequest, http->al);
110
111 if (unparsedrequest)
112 errstate->request_hdrs = xstrdup(unparsedrequest);
113
114#if USE_AUTH
115 errstate->auth_user_request = auth_user_request;
116#endif
117 setReplyToError(failedrequest ? failedrequest->method : HttpRequestMethod(Http::METHOD_NONE), errstate);
118}
119
121{
122 if (errstate->httpStatus == Http::scNotImplemented && http->request)
123 /* prevent confusion over whether we default to persistent or not */
125
126 http->al->http.code = errstate->httpStatus;
127
128 if (http->request)
129 http->request->ignoreRange("responding with a Squid-generated error");
130
132 assert(errstate->callback_data == nullptr);
133 errorAppendEntry(http->storeEntry(), errstate);
134 /* Now the caller reads to get this */
135}
136
137void
139{
140 Must(futureReply);
141 http->al->http.code = futureReply->sline.status();
142
143 HttpRequestMethod method;
144 if (http->request) { // nil on responses to unparsable requests
145 http->request->ignoreRange("responding with a Squid-generated reply");
146 method = http->request->method;
147 }
148
150
151 http->storeEntry()->storeErrorResponse(futureReply);
152 /* Now the caller reads to get futureReply */
153}
154
155// Assumes that the entry contains an error response without Content-Range.
156// To use with regular entries, make HTTP Range header removal conditional.
158{
159 entry->lock("clientReplyContext::setReplyToStoreEntry"); // removeClientStoreReference() unlocks
160 sc = storeClientListAdd(entry, this);
161#if USE_DELAY_POOLS
163#endif
164 reqofs = 0;
165 reqsize = 0;
166 if (http->request)
167 http->request->ignoreRange(reason);
169 http->storeEntry(entry);
170}
171
172void
174 StoreEntry ** ep)
175{
176 StoreEntry *e;
177 store_client *sc_tmp = *scp;
178
179 if ((e = *ep) != nullptr) {
180 *ep = nullptr;
181 storeUnregister(sc_tmp, e, this);
182 *scp = nullptr;
183 e->unlock("clientReplyContext::removeStoreReference");
184 }
185}
186
187void
189{
190 StoreEntry *reference = aHttpRequest->storeEntry();
191 removeStoreReference(scp, &reference);
192 aHttpRequest->storeEntry(reference);
193}
194
195void
197{
198 assert(old_sc == nullptr);
199 debugs(88, 3, "clientReplyContext::saveState: saving store context");
201 old_sc = sc;
206 /* Prevent accessing the now saved entries */
207 http->storeEntry(nullptr);
208 sc = nullptr;
209 reqsize = 0;
210 reqofs = 0;
211}
212
213void
215{
216 assert(old_sc != nullptr);
217 debugs(88, 3, "clientReplyContext::restoreState: Restoring store context");
220 sc = old_sc;
225 /* Prevent accessed the old saved entries */
226 old_entry = nullptr;
227 old_sc = nullptr;
228 old_lastmod = -1;
229 old_etag.clean();
230 old_reqsize = 0;
231 old_reqofs = 0;
232}
233
234void
236{
240}
241
244{
246}
247
248/* This function is wrong - the client parameters don't include the
249 * header offset
250 */
251void
253{
254 /* when confident, 0 becomes reqofs, and then this factors into
255 * startSendProcess
256 */
257 assert(reqofs == 0);
258 StoreIOBuffer localTempBuffer (next()->readBuffer.length, 0, next()->readBuffer.data);
259 storeClientCopy(sc, http->storeEntry(), localTempBuffer, SendMoreData, this);
260}
261
262/* there is an expired entry in the store.
263 * setup a temporary buffer area and perform an IMS to the origin
264 */
265void
267{
268 const char *url = storeId();
269 debugs(88, 3, "clientReplyContext::processExpired: '" << http->uri << "'");
270 const time_t lastmod = http->storeEntry()->lastModified();
271 assert(lastmod >= 0);
272 /*
273 * check if we are allowed to contact other servers
274 * @?@: Instead of a 504 (Gateway Timeout) reply, we may want to return
275 * a stale entry *if* it matches client requirements
276 */
277
278 if (http->onlyIfCached()) {
280 return;
281 }
282
284 http->request->flags.refresh = true;
285#if STORE_CLIENT_LIST_DEBUG
286 /* Prevent a race with the store client memory free routines
287 */
289#endif
290 /* Prepare to make a new temporary request */
291 saveState();
292
293 // TODO: Consider also allowing regular (non-collapsed) revalidation hits.
294 // TODO: support collapsed revalidation for Vary-controlled entries
295 bool collapsingAllowed = Config.onoff.collapsed_forwarding &&
298
299 StoreEntry *entry = nullptr;
300 if (collapsingAllowed) {
301 if (const auto e = storeGetPublicByRequest(http->request, ksRevalidation)) {
302 if (e->hittingRequiresCollapsing() && startCollapsingOn(*e, true)) {
303 entry = e;
304 entry->lock("clientReplyContext::processExpired#alreadyRevalidating");
305 } else {
306 e->abandon(__FUNCTION__);
307 // assume mayInitiateCollapsing() would fail too
308 collapsingAllowed = false;
309 }
310 }
311 }
312
313 if (entry) {
315 debugs(88, 5, "collapsed on existing revalidation entry: " << *entry);
317 } else {
318 entry = storeCreateEntry(url,
320 /* NOTE, don't call StoreEntry->lock(), storeCreateEntry() does it */
321
322 if (collapsingAllowed && mayInitiateCollapsing() &&
323 Store::Root().allowCollapsing(entry, http->request->flags, http->request->method)) {
324 debugs(88, 5, "allow other revalidation requests to collapse on " << *entry);
326 } else {
328 }
329 }
330
331 sc = storeClientListAdd(entry, this);
332#if USE_DELAY_POOLS
333 /* delay_id is already set on original store client */
335#endif
336
337 http->request->lastmod = lastmod;
338
340 ETag etag = {nullptr, -1}; // TODO: make that a default ETag constructor
341 if (old_entry->hasEtag(etag) && !etag.weak)
342 http->request->etag = etag.str;
343 }
344
345 debugs(88, 5, "lastmod " << entry->lastModified());
346 http->storeEntry(entry);
347 assert(http->out.offset == 0);
349
351 /*
352 * A refcounted pointer so that FwdState stays around as long as
353 * this clientReplyContext does
354 */
355 Comm::ConnectionPointer conn = http->getConn() != nullptr ? http->getConn()->clientConnection : nullptr;
357 }
358 /* Register with storage manager to receive updates when data comes in. */
359
360 if (EBIT_TEST(entry->flags, ENTRY_ABORTED))
361 debugs(88, DBG_CRITICAL, "clientReplyContext::processExpired: Found ENTRY_ABORTED object");
362
363 {
364 /* start counting the length from 0 */
365 StoreIOBuffer localTempBuffer(HTTP_REQBUF_SZ, 0, tempbuf);
366 storeClientCopy(sc, entry, localTempBuffer, HandleIMSReply, this);
367 }
368}
369
370void
372{
373 StoreIOBuffer tempresult;
375
378
379 /* here the data to send is the data we just received */
380 old_reqofs = 0;
381 old_reqsize = 0;
382 /* sendMoreData tracks the offset as well.
383 * Force it back to zero */
384 reqofs = 0;
386 /* TODO: provide sendMoreData with the ready parsed reply */
387 tempresult.length = reqsize;
388 tempresult.data = tempbuf;
389 sendMoreData(tempresult);
390}
391
392void
394{
395 clientReplyContext *context = (clientReplyContext *)data;
396 context->handleIMSReply(result);
397}
398
399void
401{
402 /* Get the old request back */
403 restoreState();
404 /* here the data to send is in the next nodes buffers already */
406 /* sendMoreData tracks the offset as well.
407 * Force it back to zero */
408 reqofs = 0;
409 StoreIOBuffer tempresult (reqsize, reqofs, next()->readBuffer.data);
410 sendMoreData(tempresult);
411}
412
413/* This is the workhorse of the HandleIMSReply callback.
414 *
415 * It is called when we've got data back from the origin following our
416 * IMS request to revalidate a stale entry.
417 */
418void
420{
421 if (deleting)
422 return;
423
424 debugs(88, 3, http->storeEntry()->url() << ", " << (long unsigned) result.length << " bytes");
425
426 if (http->storeEntry() == nullptr)
427 return;
428
430 return;
431
433 debugs(88, 3, "CF slave hit private non-shareable " << *http->storeEntry() << ". MISS");
434 // restore context to meet processMiss() expectations
435 restoreState();
437 processMiss();
438 return;
439 }
440
441 /* update size of the request */
442 reqsize = result.length + reqofs;
443
444 // request to origin was aborted
446 debugs(88, 3, "request to origin aborted '" << http->storeEntry()->url() << "', sending old entry to client");
449 return;
450 }
451
452 const auto oldStatus = old_entry->mem().freshestReply().sline.status();
453 const auto &new_rep = http->storeEntry()->mem().freshestReply();
454 const auto status = new_rep.sline.status();
455
456 // XXX: Disregard stale incomplete (i.e. still being written) borrowed (i.e.
457 // not caused by our request) IMS responses. That new_rep may be very old!
458
459 // origin replied 304
460 if (status == Http::scNotModified) {
462 http->request->flags.staleIfHit = false; // old_entry is no longer stale
463
464 // TODO: The update may not be instantaneous. Should we wait for its
465 // completion to avoid spawning too much client-disassociated work?
467
468 // if client sent IMS
470 // forward the 304 from origin
471 debugs(88, 3, "origin replied 304, revalidated existing entry and forwarding 304 to client");
473 return;
474 }
475
476 // send existing entry, it's still valid
477 debugs(88, 3, "origin replied 304, revalidated existing entry and sending " << oldStatus << " to client");
479 return;
480 }
481
482 // origin replied with a non-error code
483 if (status > Http::scNone && status < Http::scInternalServerError) {
484 // RFC 9111 section 4:
485 // "When more than one suitable response is stored,
486 // a cache MUST use the most recent one
487 // (as determined by the Date header field)."
488 if (new_rep.olderThan(&old_entry->mem().freshestReply())) {
489 http->al->cache.code.err.ignored = true;
490 debugs(88, 3, "origin replied " << status << " but with an older date header, sending old entry (" << oldStatus << ") to client");
492 return;
493 }
494
496 debugs(88, 3, "origin replied " << status << ", forwarding to client");
498 return;
499 }
500
501 // origin replied with an error
504 debugs(88, 3, "origin replied with error " << status << ", forwarding to client due to fail_on_validation_err");
506 return;
507 }
508
509 // ignore and let client have old entry
511 debugs(88, 3, "origin replied with error " << status << ", sending old entry (" << oldStatus << ") to client");
513}
514
517
525void
527{
528 clientReplyContext *context = (clientReplyContext *)data;
529 context->cacheHit(result);
530}
531
535void
537{
539 if (deleting) {
540 debugs(88, 3, "HIT object being deleted. Ignore the HIT.");
541 return;
542 }
543
544 StoreEntry *e = http->storeEntry();
545
547
548 debugs(88, 3, "clientCacheHit: " << http->uri << ", " << result.length << " bytes");
549
550 if (http->storeEntry() == nullptr) {
551 debugs(88, 3, "clientCacheHit: request aborted");
552 return;
553 } else if (result.flags.error) {
554 /* swap in failure */
555 debugs(88, 3, "clientCacheHit: swapin failure for " << http->uri);
558 processMiss();
559 return;
560 }
561
562 // The previously identified hit suddenly became unshareable!
563 // This is common for collapsed forwarding slaves but might also
564 // happen to regular hits because we are called asynchronously.
565 if (!e->mayStartHitting()) {
566 debugs(88, 3, "unshareable " << *e << ". MISS");
568 processMiss();
569 return;
570 }
571
572 if (result.length == 0) {
573 debugs(88, 5, "store IO buffer has no content. MISS");
574 /* the store couldn't get enough data from the file for us to id the
575 * object
576 */
577 /* treat as a miss */
579 processMiss();
580 return;
581 }
582
584 /* update size of the request */
585 reqsize = result.length + reqofs;
586
587 /*
588 * Got the headers, now grok them
589 */
591
592 if (http->request->storeId().cmp(e->mem_obj->storeId()) != 0) {
593 debugs(33, DBG_IMPORTANT, "clientProcessHit: URL mismatch, '" << e->mem_obj->storeId() << "' != '" << http->request->storeId() << "'");
594 http->updateLoggingTags(LOG_TCP_MISS); // we lack a more precise LOG_*_MISS code
595 processMiss();
596 return;
597 }
598
599 switch (varyEvaluateMatch(e, r)) {
600
601 case VARY_NONE:
602 /* No variance detected. Continue as normal */
603 break;
604
605 case VARY_MATCH:
606 /* This is the correct entity for this request. Continue */
607 debugs(88, 2, "clientProcessHit: Vary MATCH!");
608 break;
609
610 case VARY_OTHER:
611 /* This is not the correct entity for this request. We need
612 * to requery the cache.
613 */
615 e = nullptr;
616 /* Note: varyEvalyateMatch updates the request with vary information
617 * so we only get here once. (it also takes care of cancelling loops)
618 */
619 debugs(88, 2, "clientProcessHit: Vary detected!");
621 return;
622
623 case VARY_CANCEL:
624 /* varyEvaluateMatch found a object loop. Process as miss */
625 debugs(88, DBG_IMPORTANT, "clientProcessHit: Vary object loop!");
626 http->updateLoggingTags(LOG_TCP_MISS); // we lack a more precise LOG_*_MISS code
627 processMiss();
628 return;
629 }
630
631 if (r->method == Http::METHOD_PURGE) {
632 debugs(88, 5, "PURGE gets a HIT");
634 e = nullptr;
635 purgeRequest();
636 return;
637 }
638
639 if (e->checkNegativeHit() && !r->flags.noCacheHack()) {
640 debugs(88, 5, "negative-HIT");
642 sendMoreData(result);
643 return;
644 } else if (blockedHit()) {
645 debugs(88, 5, "send_hit forces a MISS");
647 processMiss();
648 return;
649 } else if (!http->flags.internal && refreshCheckHTTP(e, r)) {
650 debugs(88, 5, "clientCacheHit: in refreshCheck() block");
651 /*
652 * We hold a stale copy; it needs to be validated
653 */
654 /*
655 * The 'needValidation' flag is used to prevent forwarding
656 * loops between siblings. If our copy of the object is stale,
657 * then we should probably only use parents for the validation
658 * request. Otherwise two siblings could generate a loop if
659 * both have a stale version of the object.
660 */
661 r->flags.needValidation = true;
662
663 if (e->lastModified() < 0) {
664 debugs(88, 3, "validate HIT object? NO. Can't calculate entry modification time. Do MISS.");
665 /*
666 * We cannot revalidate entries without knowing their
667 * modification time.
668 * XXX: BUG 1890 objects without Date do not get one added.
669 */
671 processMiss();
672 } else if (r->flags.noCache) {
673 debugs(88, 3, "validate HIT object? NO. Client sent CC:no-cache. Do CLIENT_REFRESH_MISS");
674 /*
675 * This did not match a refresh pattern that overrides no-cache
676 * we should honour the client no-cache header.
677 */
679 processMiss();
680 } else if (r->url.getScheme() == AnyP::PROTO_HTTP || r->url.getScheme() == AnyP::PROTO_HTTPS) {
681 debugs(88, 3, "validate HIT object? YES.");
682 /*
683 * Object needs to be revalidated
684 * XXX This could apply to FTP as well, if Last-Modified is known.
685 */
687 } else {
688 debugs(88, 3, "validate HIT object? NO. Client protocol non-HTTP. Do MISS.");
689 /*
690 * We don't know how to re-validate other protocols. Handle
691 * them as if the object has expired.
692 */
694 processMiss();
695 }
696 return;
697 } else if (r->conditional()) {
698 debugs(88, 5, "conditional HIT");
699 if (processConditional())
700 return;
701 }
702
703 /*
704 * plain ol' cache hit
705 */
706 debugs(88, 5, "plain old HIT");
707
708#if USE_DELAY_POOLS
709 if (e->store_status != STORE_OK)
711 else
712#endif
713 if (e->mem_status == IN_MEMORY)
715 else if (Config.onoff.offline)
717
718 sendMoreData(result);
719}
720
724void
726{
727 char *url = http->uri;
729 ErrorState *err = nullptr;
730 debugs(88, 4, r->method << ' ' << url);
731
736 if (http->storeEntry()) {
738 debugs(88, DBG_CRITICAL, "clientProcessMiss: miss on a special object (" << url << ").");
739 debugs(88, DBG_CRITICAL, "\tlog_type = " << http->loggingTags().c_str());
740 http->storeEntry()->dump(1);
741 }
742
744 }
745
747 if (r->method == Http::METHOD_PURGE) {
748 purgeRequest();
749 return;
750 }
751
753 if (r->method == Http::METHOD_OTHER) {
755 }
756
758 if (http->onlyIfCached()) {
760 return;
761 }
762
764 if (r->flags.loopDetected) {
770 return;
771 } else {
772 assert(http->out.offset == 0);
775
776 if (http->redirect.status) {
777 const HttpReplyPointer rep(new HttpReply);
783 return;
784 }
785
787
788 Comm::ConnectionPointer conn = http->getConn() != nullptr ? http->getConn()->clientConnection : nullptr;
791 }
792}
793
800void
802{
803 debugs(88, 4, http->request->method << ' ' << http->uri);
806 http->getConn(), http->request, http->al);
808 startError(err);
809}
810
812bool
814{
815 StoreEntry *const e = http->storeEntry();
816
817 const auto replyStatusCode = e->mem().baseReply().sline.status();
818 if (replyStatusCode != Http::scOkay) {
819 debugs(88, 4, "miss because " << replyStatusCode << " != 200");
821 processMiss();
822 return true;
823 }
824
825 HttpRequest &r = *http->request;
826
828 // RFC 2616: reply with 412 Precondition Failed if If-Match did not match
830 return true;
831 }
832
834 // RFC 7232: If-None-Match recipient MUST ignore IMS
835 r.flags.ims = false;
836 r.ims = -1;
837 r.imslen = 0;
839
840 if (e->hasIfNoneMatchEtag(r)) {
842 return true;
843 }
844
845 // None-Match is true (no ETag matched); treat as an unconditional hit
846 return false;
847 }
848
849 if (r.flags.ims) {
850 // handle If-Modified-Since requests from the client
851 if (e->modifiedSince(r.ims, r.imslen)) {
852 // Modified-Since is true; treat as an unconditional hit
853 return false;
854
855 } else {
856 // otherwise reply with 304 Not Modified
858 }
859 return true;
860 }
861
862 return false;
863}
864
866bool
868{
870 return false; // hits are not blocked by default
871
872 if (http->flags.internal)
873 return false; // internal content "hits" cannot be blocked
874
875 const auto &rep = http->storeEntry()->mem().freshestReply();
876 {
877 std::unique_ptr<ACLFilledChecklist> chl(clientAclChecklistCreate(Config.accessList.sendHit, http));
878 chl->reply = const_cast<HttpReply*>(&rep); // ACLChecklist API bug
879 HTTPMSGLOCK(chl->reply);
880 return !chl->fastCheck().allowed(); // when in doubt, block
881 }
882}
883
884// Purges all entries with a given url
885// TODO: move to SideAgent parent, when we have one
886/*
887 * We probably cannot purge Vary-affected responses because their MD5
888 * keys depend on vary headers.
889 */
890void
891purgeEntriesByUrl(HttpRequest * req, const char *url)
892{
894 if (m.respMaybeCacheable()) {
895 const cache_key *key = storeKeyPublic(url, m);
896 debugs(88, 5, m << ' ' << url << ' ' << storeKeyText(key));
897#if USE_HTCP
899#else
900 (void)req;
901#endif
903 }
904 }
905}
906
907void
909{
910 // XXX: performance regression, c_str() reallocates
913}
914
915LogTags *
917{
918 // XXX: clientReplyContext code assumes that http cbdata is always valid.
919 // TODO: Either add cbdataReferenceValid(http) checks in all the relevant
920 // places, like this one, or remove cbdata protection of the http member.
921 return &http->al->cache.code;
922}
923
924void
926{
927 debugs(88, 3, "Config2.onoff.enable_purge = " <<
929
933 http->getConn(), http->request, http->al);
934 startError(err);
935 return;
936 }
937
938 /* Release both IP cache */
940
941 // TODO: can we use purgeAllCached() here instead?
942 purgeDoPurge();
943}
944
945void
947{
948 auto firstFound = false;
950 // special entries are only METHOD_GET entries without variance
951 if (EBIT_TEST(entry->flags, ENTRY_SPECIAL)) {
953 const auto err = clientBuildError(ERR_ACCESS_DENIED, Http::scForbidden, nullptr,
954 http->getConn(), http->request, http->al);
955 startError(err);
956 entry->abandon(__FUNCTION__);
957 return;
958 }
959 firstFound = true;
960 if (!purgeEntry(*entry, Http::METHOD_GET))
961 return;
962 }
963
965
967 if (!purgeEntry(*entry, Http::METHOD_HEAD))
968 return;
969 }
970
971 /* And for Vary, release the base URI if none of the headers was included in the request */
973 && http->request->vary_headers.find('=') != SBuf::npos) {
974 // XXX: performance regression, c_str() reallocates
976
977 if (const auto entry = storeGetPublic(tmp.c_str(), Http::METHOD_GET)) {
978 if (!purgeEntry(*entry, Http::METHOD_GET, "Vary "))
979 return;
980 }
981
982 if (const auto entry = storeGetPublic(tmp.c_str(), Http::METHOD_HEAD)) {
983 if (!purgeEntry(*entry, Http::METHOD_HEAD, "Vary "))
984 return;
985 }
986 }
987
990
991 /*
992 * Make a new entry to hold the reply to be written
993 * to the client.
994 */
995 /* TODO: This doesn't need to go through the store. Simply
996 * push down the client chain
997 */
999
1001
1002 const HttpReplyPointer rep(new HttpReply);
1003 rep->setHeaders(purgeStatus, nullptr, nullptr, 0, 0, -1);
1005 http->storeEntry()->complete();
1006}
1007
1008bool
1009clientReplyContext::purgeEntry(StoreEntry &entry, const Http::MethodType methodType, const char *descriptionPrefix)
1010{
1011 debugs(88, 4, descriptionPrefix << Http::MethodStr(methodType) << " '" << entry.url() << "'" );
1012#if USE_HTCP
1014#endif
1015 entry.release(true);
1017 return true;
1018}
1019
1020void
1022{
1023 clientStreamNode *nextNode = (clientStreamNode *)node->node.next->data;
1024 StoreIOBuffer localTempBuffer;
1026 localTempBuffer.offset = nextNode->readBuffer.offset + headers_sz;
1027 localTempBuffer.length = nextNode->readBuffer.length;
1028 localTempBuffer.data = nextNode->readBuffer.data;
1030 localTempBuffer, SendMoreData, this);
1032 http->storeEntry()->buffer();
1033 const HttpReplyPointer rep(new HttpReply);
1034 rep->setHeaders(Http::scOkay, nullptr, "text/plain", http->request->prefixLen(), 0, squid_curtime);
1037 http->storeEntry()->complete();
1038}
1039
1040#define SENDING_BODY 0
1041#define SENDING_HDRSONLY 1
1042int
1044{
1045 StoreEntry *entry = http->storeEntry();
1046
1047 if (entry == nullptr)
1048 return 0;
1049
1050 /*
1051 * For now, 'done_copying' is used for special cases like
1052 * Range and HEAD requests.
1053 */
1054 if (http->flags.done_copying)
1055 return 1;
1056
1058 // last-chunk was not sent
1059 return 0;
1060 }
1061
1062 /*
1063 * Handle STORE_OK objects.
1064 * objectLen(entry) will be set proprely.
1065 * RC: Does objectLen(entry) include the Headers?
1066 * RC: Yes.
1067 */
1068 if (entry->store_status == STORE_OK) {
1069 return storeOKTransferDone();
1070 } else {
1071 return storeNotOKTransferDone();
1072 }
1073}
1074
1075int
1077{
1078 assert(http->storeEntry()->objectLen() >= 0);
1080 if (http->out.offset >= http->storeEntry()->objectLen() - headers_sz) {
1081 debugs(88,3, "storeOKTransferDone " <<
1082 " out.offset=" << http->out.offset <<
1083 " objectLen()=" << http->storeEntry()->objectLen() <<
1084 " headers_sz=" << headers_sz);
1085 return 1;
1086 }
1087
1088 return 0;
1089}
1090
1091int
1093{
1094 /*
1095 * Now, handle STORE_PENDING objects
1096 */
1097 MemObject *mem = http->storeEntry()->mem_obj;
1098 assert(mem != nullptr);
1099 assert(http->request != nullptr);
1100
1101 /* mem->reply was wrong because it uses the UPSTREAM header length!!! */
1102 if (headers_sz == 0)
1103 /* haven't found end of headers yet */
1104 return 0;
1105
1106 // TODO: Use MemObject::expectedReplySize(method) after resolving XXX below.
1107 const auto expectedBodySize = mem->baseReply().content_length;
1108
1109 // XXX: The code below talks about sending data, and checks stats about
1110 // bytes written to the client connection, but this method must determine
1111 // whether we are done _receiving_ data from Store. This code should work OK
1112 // when expectedBodySize is unknown or matches written data, but it may
1113 // malfunction when we are writing ranges while receiving a full response.
1114
1115 /*
1116 * Figure out how much data we are supposed to send.
1117 * If we are sending a body and we don't have a content-length,
1118 * then we must wait for the object to become STORE_OK.
1119 */
1120 if (expectedBodySize < 0)
1121 return 0;
1122
1123 const uint64_t expectedLength = expectedBodySize + http->out.headers_sz;
1124
1125 if (http->out.size < expectedLength)
1126 return 0;
1127 else {
1128 debugs(88,3, "storeNotOKTransferDone " <<
1129 " out.size=" << http->out.size <<
1130 " expectedLength=" << expectedLength);
1131 return 1;
1132 }
1133}
1134
1135/* Preconditions:
1136 * *http is a valid structure.
1137 * fd is either -1, or an open fd.
1138 *
1139 * TODO: enumify this
1140 *
1141 * This function is used by any http request sink, to determine the status
1142 * of the object.
1143 */
1146{
1147 clientReplyContext *context = dynamic_cast<clientReplyContext *>(aNode->data.getRaw());
1148 assert (context);
1149 assert (context->http == http);
1150 return context->replyStatus();
1151}
1152
1155{
1156 int done;
1157 /* Here because lower nodes don't need it */
1158
1159 if (http->storeEntry() == nullptr) {
1160 debugs(88, 5, "clientReplyStatus: no storeEntry");
1161 return STREAM_FAILED; /* yuck, but what can we do? */
1162 }
1163
1165 /* TODO: Could upstream read errors (result.flags.error) be
1166 * lost, and result in undersize requests being considered
1167 * complete. Should we tcp reset such connections ?
1168 */
1169 debugs(88, 5, "clientReplyStatus: aborted storeEntry");
1170 return STREAM_FAILED;
1171 }
1172
1173 if ((done = checkTransferDone()) != 0 || flags.complete) {
1174 debugs(88, 5, "clientReplyStatus: transfer is DONE: " << done << flags.complete);
1175 /* Ok we're finished, but how? */
1176
1178 debugs(88, 5, "clientReplyStatus: truncated response body");
1180 }
1181
1182 if (!done) {
1183 debugs(88, 5, "clientReplyStatus: closing, !done, but read 0 bytes");
1184 return STREAM_FAILED;
1185 }
1186
1187 // TODO: See also (and unify with) storeNotOKTransferDone() checks.
1188 const int64_t expectedBodySize =
1190 if (expectedBodySize >= 0 && !http->gotEnough()) {
1191 debugs(88, 5, "clientReplyStatus: client didn't get all it expected");
1193 }
1194
1195 debugs(88, 5, "clientReplyStatus: stream complete; keepalive=" <<
1197 return STREAM_COMPLETE;
1198 }
1199
1200 // XXX: Should this be checked earlier? We could return above w/o checking.
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 */
1218bool
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
1234 result = true;
1235 break;
1236
1237 default:
1238 result = false;
1239 }
1240
1241 return result;
1242}
1243
1251void
1253{
1254 HttpHeader *hdr = &reply->header;
1255 const bool is_hit = http->loggingTags().isTcpHit();
1256 HttpRequest *request = http->request;
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
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 }
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 }
1321 }
1322
1323 /* RFC 2616: Section 14.18
1324 *
1325 * Add a Date: header if missing.
1326 * We have access to a clock therefore are required to amend any shortcoming in servers.
1327 *
1328 * NP: done after Age: to prevent ENTRY_SPECIAL double-handling this header.
1329 */
1330 if ( !hdr->has(Http::HdrType::DATE) ) {
1331 if (!http->storeEntry())
1333 else if (http->storeEntry()->timestamp > 0)
1335 else {
1336 debugs(88, DBG_IMPORTANT, "ERROR: Squid BUG #3279: HTTP reply without Date:");
1337 /* dump something useful about the problem */
1339 }
1340 }
1341
1342 /* Filter unproxyable authentication types */
1346 HttpHeaderEntry *e;
1347
1348 int connection_auth_blocked = 0;
1349 while ((e = hdr->getEntry(&pos))) {
1351 const char *value = e->value.rawBuf();
1352
1353 if ((strncasecmp(value, "NTLM", 4) == 0 &&
1354 (value[4] == '\0' || value[4] == ' '))
1355 ||
1356 (strncasecmp(value, "Negotiate", 9) == 0 &&
1357 (value[9] == '\0' || value[9] == ' '))
1358 ||
1359 (strncasecmp(value, "Kerberos", 8) == 0 &&
1360 (value[8] == '\0' || value[8] == ' '))) {
1361 if (request->flags.connectionAuthDisabled) {
1362 hdr->delAt(pos, connection_auth_blocked);
1363 continue;
1364 }
1365 request->flags.mustKeepalive = true;
1366 if (!request->flags.accelerated && !request->flags.intercepted) {
1367 httpHeaderPutStrf(hdr, Http::HdrType::PROXY_SUPPORT, "Session-Based-Authentication");
1368 /*
1369 We send "Connection: Proxy-Support" header to mark
1370 Proxy-Support as a hop-by-hop header for intermediaries that do not
1371 understand the semantics of this header. The RFC should have included
1372 this recommendation.
1373 */
1374 httpHeaderPutStrf(hdr, Http::HdrType::CONNECTION, "Proxy-support");
1375 }
1376 break;
1377 }
1378 }
1379 }
1380
1381 if (connection_auth_blocked)
1382 hdr->refreshMask();
1383 }
1384
1385#if USE_AUTH
1386 /* Handle authentication headers */
1390 ) {
1391 /* Add authentication header */
1392 /* TODO: alter errorstate to be accel on|off aware. The 0 on the next line
1393 * depends on authenticate behaviour: all schemes to date send no extra
1394 * data on 407/401 responses, and do not check the accel state on 401/407
1395 * responses
1396 */
1398 } else if (request->auth_user_request != nullptr)
1400#endif
1401
1402 SBuf cacheStatus(uniqueHostname());
1403 if (const auto hitOrFwd = http->loggingTags().cacheStatusSource())
1404 cacheStatus.append(hitOrFwd);
1405 if (firstStoreLookup_) {
1406 cacheStatus.append(";detail=");
1407 cacheStatus.append(firstStoreLookup_);
1408 }
1409 // TODO: Remove c_str() after converting HttpHeaderEntry::value to SBuf
1410 hdr->putStr(Http::HdrType::CACHE_STATUS, cacheStatus.c_str());
1411
1412 const bool maySendChunkedReply = !request->multipartRangeRequest() &&
1413 reply->sline.version.protocol == AnyP::PROTO_HTTP && // response is HTTP
1414 (request->http_ver >= Http::ProtocolVersion(1,1));
1415
1416 /* Check whether we should send keep-alive */
1417 if (!Config.onoff.error_pconns && reply->sline.status() >= 400 && !request->flags.mustKeepalive) {
1418 debugs(33, 3, "clientBuildReplyHeader: Error, don't keep-alive");
1419 request->flags.proxyKeepalive = false;
1420 } else if (!Config.onoff.client_pconns && !request->flags.mustKeepalive) {
1421 debugs(33, 2, "clientBuildReplyHeader: Connection Keep-Alive not requested by admin or client");
1422 request->flags.proxyKeepalive = false;
1423 } else if (request->flags.proxyKeepalive && shutting_down) {
1424 debugs(88, 3, "clientBuildReplyHeader: Shutting down, don't keep-alive.");
1425 request->flags.proxyKeepalive = false;
1426 } else if (request->flags.connectionAuth && !reply->keep_alive) {
1427 debugs(33, 2, "clientBuildReplyHeader: Connection oriented auth but server side non-persistent");
1428 request->flags.proxyKeepalive = false;
1429 } else if (reply->bodySize(request->method) < 0 && !maySendChunkedReply) {
1430 debugs(88, 3, "clientBuildReplyHeader: can't keep-alive, unknown body size" );
1431 request->flags.proxyKeepalive = false;
1432 } else if (fdUsageHigh()&& !request->flags.mustKeepalive) {
1433 debugs(88, 3, "clientBuildReplyHeader: Not many unused FDs, can't keep-alive");
1434 request->flags.proxyKeepalive = false;
1435 } else if (request->flags.sslBumped && !reply->persistent()) {
1436 // We do not really have to close, but we pretend we are a tunnel.
1437 debugs(88, 3, "clientBuildReplyHeader: bumped reply forces close");
1438 request->flags.proxyKeepalive = false;
1439 } else if (request->pinnedConnection() && !reply->persistent()) {
1440 // The peer wants to close the pinned connection
1441 debugs(88, 3, "pinned reply forces close");
1442 request->flags.proxyKeepalive = false;
1443 } else if (http->getConn()) {
1445 if (!Comm::IsConnOpen(conn->port->listenConn)) {
1446 // The listening port closed because of a reconfigure
1447 debugs(88, 3, "listening port closed");
1448 request->flags.proxyKeepalive = false;
1449 }
1450 }
1451
1452 // Decide if we send chunked reply
1453 if (maySendChunkedReply && reply->bodySize(request->method) < 0) {
1454 debugs(88, 3, "clientBuildReplyHeader: chunked reply");
1455 request->flags.chunkedReply = true;
1457 }
1458
1459 hdr->addVia(reply->sline.version);
1460
1461 /* Signal keep-alive or close explicitly */
1462 hdr->putStr(Http::HdrType::CONNECTION, request->flags.proxyKeepalive ? "keep-alive" : "close");
1463
1464#if ADD_X_REQUEST_URI
1465 /*
1466 * Knowing the URI of the request is useful when debugging persistent
1467 * connections in a client; we cannot guarantee the order of http headers,
1468 * but X-Request-URI is likely to be the very last header to ease use from a
1469 * debugger [hdr->entries.count-1].
1470 */
1472 http->memOjbect()->url ? http->memObject()->url : http->uri);
1473
1474#endif
1475
1476 /* Surrogate-Control requires Surrogate-Capability from upstream to pass on */
1480 }
1481 /* TODO: else case: drop any controls intended specifically for our surrogate ID */
1482 }
1483
1484 httpHdrMangleList(hdr, request, http->al, ROR_REPLY);
1485}
1486
1487void
1489{
1490 assert(reply == nullptr);
1491
1494
1495 http->al->reply = reply;
1496
1498 /* RFC 2616 requires us to advertise our version (but only on real HTTP traffic) */
1500 }
1501
1502 /* do header conversions */
1504}
1505
1509void
1511{
1512 StoreEntry *e = http->storeEntry();
1513 assert(e); // or we are not dealing with a hit
1514 // We probably have not locked the entry earlier, unfortunately. We lock it
1515 // now so that we can unlock two lines later (and trigger cleanup).
1516 // Ideally, ClientHttpRequest::storeEntry() should lock/unlock, but it is
1517 // used so inconsistently that simply adding locking there leads to bugs.
1518 e->lock("clientReplyContext::forgetHit");
1519 http->storeEntry(nullptr);
1520 e->unlock("clientReplyContext::forgetHit"); // may delete e
1521}
1522
1523void
1525{
1526 HttpRequest *r = http->request;
1527
1528 // client sent CC:no-cache or some other condition has been
1529 // encountered which prevents delivering a public/cached object.
1530 if (!r->flags.noCache || r->flags.internal) {
1531 const auto e = storeGetPublicByRequest(r);
1533 } else {
1534 // "external" no-cache requests skip Store lookups
1535 identifyFoundObject(nullptr, "no-cache");
1536 }
1537}
1538
1543void
1545{
1546 detailStoreLookup(detail);
1547
1548 HttpRequest *r = http->request;
1549 http->storeEntry(newEntry);
1550 const auto e = http->storeEntry();
1551
1552 /* Release IP-cache entries on reload */
1556 if (r->flags.noCache || r->flags.noCacheHack())
1558
1559 if (!e) {
1561 debugs(85, 3, "StoreEntry is NULL - MISS");
1563 doGetMoreData();
1564 return;
1565 }
1566
1567 if (Config.onoff.offline) {
1569 debugs(85, 3, "offline HIT " << *e);
1571 doGetMoreData();
1572 return;
1573 }
1574
1575 if (http->redirect.status) {
1577 debugs(85, 3, "REDIRECT status forced StoreEntry to NULL (no body on 3XX responses) " << *e);
1578 forgetHit();
1580 doGetMoreData();
1581 return;
1582 }
1583
1584 if (!e->validToSend()) {
1585 debugs(85, 3, "!storeEntryValidToSend MISS " << *e);
1586 forgetHit();
1588 doGetMoreData();
1589 return;
1590 }
1591
1592 if (EBIT_TEST(e->flags, ENTRY_SPECIAL)) {
1593 /* \li Special entries are always hits, no matter what the client says */
1594 debugs(85, 3, "ENTRY_SPECIAL HIT " << *e);
1596 doGetMoreData();
1597 return;
1598 }
1599
1600 if (r->flags.noCache) {
1601 debugs(85, 3, "no-cache REFRESH MISS " << *e);
1602 forgetHit();
1604 doGetMoreData();
1605 return;
1606 }
1607
1608 if (e->hittingRequiresCollapsing() && !startCollapsingOn(*e, false)) {
1609 debugs(85, 3, "prohibited CF MISS " << *e);
1610 forgetHit();
1612 doGetMoreData();
1613 return;
1614 }
1615
1616 debugs(85, 3, "default HIT " << *e);
1618 doGetMoreData();
1619}
1620
1622void
1624{
1625 if (!firstStoreLookup_) {
1626 debugs(85, 7, detail);
1627 firstStoreLookup_ = detail;
1628 } else {
1629 debugs(85, 7, "ignores " << detail << " after " << firstStoreLookup_);
1630 }
1631}
1632
1642void
1644{
1645 /* Test preconditions */
1646 assert(aNode != nullptr);
1648 assert(aNode->node.prev == nullptr);
1649 assert(aNode->node.next != nullptr);
1650 clientReplyContext *context = dynamic_cast<clientReplyContext *>(aNode->data.getRaw());
1651 assert (context);
1652 assert(context->http == http);
1653
1654 clientStreamNode *next = ( clientStreamNode *)aNode->node.next->data;
1655
1656 if (!context->ourNode)
1657 context->ourNode = aNode;
1658
1659 /* no cbdatareference, this is only used once, and safely */
1660 if (context->flags.storelogiccomplete) {
1661 StoreIOBuffer tempBuffer;
1662 tempBuffer.offset = next->readBuffer.offset + context->headers_sz;
1663 tempBuffer.length = next->readBuffer.length;
1664 tempBuffer.data = next->readBuffer.data;
1665
1666 storeClientCopy(context->sc, http->storeEntry(),
1667 tempBuffer, clientReplyContext::SendMoreData, context);
1668 return;
1669 }
1670
1671 if (context->http->request->method == Http::METHOD_PURGE) {
1672 context->purgeRequest();
1673 return;
1674 }
1675
1676 // OPTIONS with Max-Forwards:0 handled in clientProcessRequest()
1677
1678 if (context->http->request->method == Http::METHOD_TRACE) {
1680 context->traceReply(aNode);
1681 return;
1682 }
1683
1684 /* continue forwarding, not finished yet. */
1686
1687 context->doGetMoreData();
1688 } else
1689 context->identifyStoreObject();
1690}
1691
1692void
1694{
1695 /* We still have to do store logic processing - vary, cache hit etc */
1696 if (http->storeEntry() != nullptr) {
1697 /* someone found the object in the cache for us */
1698 StoreIOBuffer localTempBuffer;
1699
1700 http->storeEntry()->lock("clientReplyContext::doGetMoreData");
1701
1703
1705#if USE_DELAY_POOLS
1707#endif
1708
1710 reqofs = 0;
1711 /* guarantee nothing has been sent yet! */
1712 assert(http->out.size == 0);
1713 assert(http->out.offset == 0);
1714
1715 if (ConnStateData *conn = http->getConn()) {
1716 if (Ip::Qos::TheConfig.isHitTosActive()) {
1717 Ip::Qos::doTosLocalHit(conn->clientConnection);
1718 }
1719
1720 if (Ip::Qos::TheConfig.isHitNfmarkActive()) {
1721 Ip::Qos::doNfmarkLocalHit(conn->clientConnection);
1722 }
1723 }
1724
1725 localTempBuffer.offset = reqofs;
1726 localTempBuffer.length = getNextNode()->readBuffer.length;
1727 localTempBuffer.data = getNextNode()->readBuffer.data;
1728 storeClientCopy(sc, http->storeEntry(), localTempBuffer, CacheHit, this);
1729 } else {
1730 /* MISS CASE, http->loggingTags() are already set! */
1731 processMiss();
1732 }
1733}
1734
1736void
1738{
1740 clientStreamDetach(node, http);
1741}
1742
1747void
1749{
1750 clientReplyContext *context = static_cast<clientReplyContext *>(data);
1751 context->sendMoreData (result);
1752}
1753
1754void
1756{
1757 /* At least, I think that's what this does */
1760}
1761
1762bool
1763clientReplyContext::errorInStream(StoreIOBuffer const &result, size_t const &sizeToProcess)const
1764{
1765 return /* aborted request */
1767 /* Upstream read error */ (result.flags.error) ||
1768 /* Upstream EOF */ (sizeToProcess == 0);
1769}
1770
1771void
1773{
1779 debugs(88, 5, "A stream error has occurred, marking as complete and sending no data.");
1780 StoreIOBuffer localTempBuffer;
1781 flags.complete = 1;
1782 http->request->flags.streamError = true;
1783 localTempBuffer.flags.error = result.flags.error;
1785 localTempBuffer);
1786}
1787
1788void
1790{
1791 StoreIOBuffer localTempBuffer;
1792
1793 if (result.length == 0) {
1794 debugs(88, 5, "clientReplyContext::pushStreamData: marking request as complete due to 0 length store result");
1795 flags.complete = 1;
1796 }
1797
1798 assert(result.offset - headers_sz == next()->readBuffer.offset);
1799 localTempBuffer.offset = result.offset - headers_sz;
1800 localTempBuffer.length = result.length;
1801
1802 if (localTempBuffer.length)
1803 localTempBuffer.data = source;
1804
1806 localTempBuffer);
1807}
1808
1811{
1813 return getNextNode();
1814}
1815
1816void
1818{
1821 http->getConn(), http->request, http->al);
1824 startError(err);
1825
1826}
1827
1829void
1831{
1833 ErrorState *const err =
1835 nullptr, http->getConn(), http->request, http->al);
1838 startError(err);
1839}
1840
1842void
1844{
1845 StoreEntry *e = http->storeEntry();
1846 const time_t timestamp = e->timestamp;
1847 const auto temprep = e->mem().freshestReply().make304();
1848 // log as TCP_INM_HIT if code 304 generated for
1849 // If-None-Match request
1850 if (!http->request->flags.ims)
1852 else
1856 e = http->storeEntry();
1857 // Copy timestamp from the original entry so the 304
1858 // reply has a meaningful Age: header.
1859 e->timestampsSet();
1860 e->timestamp = timestamp;
1861 e->replaceHttpReply(temprep);
1862 e->complete();
1863 /*
1864 * TODO: why put this in the store and then serialise it and
1865 * then parse it again. Simply mark the request complete in
1866 * our context and write the reply struct to the client side.
1867 */
1869}
1870
1873void
1875{
1879 else
1881}
1882
1883void
1885{
1886 /* NP: this should probably soft-fail to a zero-sized-reply error ?? */
1887 assert(reply);
1888
1895 return;
1896 }
1897
1901 return;
1902 }
1903
1905
1907 if (!Config.accessList.reply) {
1909 return;
1910 }
1911
1913 ACLFilledChecklist *replyChecklist =
1915 replyChecklist->reply = reply;
1916 HTTPMSGLOCK(replyChecklist->reply);
1917 replyChecklist->nonBlockingCheck(ProcessReplyAccessResult, this);
1918}
1919
1920void
1922{
1923 clientReplyContext *me = static_cast<clientReplyContext *>(voidMe);
1925}
1926
1927void
1929{
1930 debugs(88, 2, "The reply for " << http->request->method
1931 << ' ' << http->uri << " is " << accessAllowed << ", because it matched "
1932 << (AclMatchedName ? AclMatchedName : "NO ACL's"));
1933
1934 if (!accessAllowed.allowed()) {
1935 ErrorState *err;
1936 err_type page_id;
1938
1940
1941 if (page_id == ERR_NONE)
1942 page_id = ERR_ACCESS_DENIED;
1943
1944 err = clientBuildError(page_id, Http::scForbidden, nullptr,
1945 http->getConn(), http->request, http->al);
1946
1948
1950
1951 startError(err);
1952
1953 return;
1954 }
1955
1956 /* Ok, the reply is allowed, */
1958
1959 ssize_t body_size = reqofs - reply->hdr_sz;
1960 if (body_size < 0) {
1961 reqofs = reply->hdr_sz;
1962 body_size = 0;
1963 }
1964
1965 debugs(88, 3, "clientReplyContext::sendMoreData: Appending " <<
1966 (int) body_size << " bytes after " << reply->hdr_sz <<
1967 " bytes of headers");
1968
1969#if USE_SQUID_ESI
1970
1974 debugs(88, 2, "Enabling ESI processing for " << http->uri);
1977 }
1978
1979#endif
1980
1982 /* do not forward body for HEAD replies */
1983 body_size = 0;
1984 http->flags.done_copying = true;
1985 flags.complete = 1;
1986 }
1987
1989 flags.headersSent = true;
1990
1991 StoreIOBuffer localTempBuffer;
1992 char *buf = next()->readBuffer.data;
1993 char *body_buf = buf + reply->hdr_sz;
1994
1995 //Server side may disable ranges under some circumstances.
1996
1997 if ((!http->request->range))
1998 next()->readBuffer.offset = 0;
1999
2000 body_buf -= next()->readBuffer.offset;
2001
2002 if (next()->readBuffer.offset != 0) {
2003 if (next()->readBuffer.offset > body_size) {
2004 /* Can't use any of the body we received. send nothing */
2005 localTempBuffer.length = 0;
2006 localTempBuffer.data = nullptr;
2007 } else {
2008 localTempBuffer.length = body_size - next()->readBuffer.offset;
2009 localTempBuffer.data = body_buf + next()->readBuffer.offset;
2010 }
2011 } else {
2012 localTempBuffer.length = body_size;
2013 localTempBuffer.data = body_buf;
2014 }
2015
2016 /* TODO??: move the data in the buffer back by the request header size */
2018 http, reply, localTempBuffer);
2019
2020 return;
2021}
2022
2023void
2025{
2026 if (deleting)
2027 return;
2028
2029 StoreEntry *entry = http->storeEntry();
2030
2031 if (ConnStateData * conn = http->getConn()) {
2032 if (!conn->isOpen()) {
2033 debugs(33,3, "not sending more data to closing connection " << conn->clientConnection);
2034 return;
2035 }
2036 if (conn->pinning.zeroReply) {
2037 debugs(33,3, "not sending more data after a pinned zero reply " << conn->clientConnection);
2038 return;
2039 }
2040
2041 if (reqofs==0 && !http->loggingTags().isTcpHit()) {
2042 if (Ip::Qos::TheConfig.isHitTosActive()) {
2043 Ip::Qos::doTosLocalMiss(conn->clientConnection, http->request->hier.code);
2044 }
2045 if (Ip::Qos::TheConfig.isHitNfmarkActive()) {
2046 Ip::Qos::doNfmarkLocalMiss(conn->clientConnection, http->request->hier.code);
2047 }
2048 }
2049
2050 debugs(88, 5, conn->clientConnection <<
2051 " '" << entry->url() << "'" <<
2052 " out.offset=" << http->out.offset);
2053 }
2054
2055 char *buf = next()->readBuffer.data;
2056
2057 if (buf != result.data) {
2058 /* we've got to copy some data */
2059 assert(result.length <= next()->readBuffer.length);
2060 memcpy(buf, result.data, result.length);
2061 }
2062
2063 /* We've got the final data to start pushing... */
2065
2066 reqofs += result.length;
2067
2069
2070 assert(http->request != nullptr);
2071
2072 /* ESI TODO: remove this assert once everything is stable */
2075
2076 makeThisHead();
2077
2078 debugs(88, 5, "clientReplyContext::sendMoreData: " << http->uri << ", " <<
2079 reqofs << " bytes (" << result.length <<
2080 " new bytes)");
2081
2082 /* update size of the request */
2083 reqsize = reqofs;
2084
2085 if (errorInStream(result, reqofs)) {
2086 sendStreamError(result);
2087 return;
2088 }
2089
2090 if (flags.headersSent) {
2091 pushStreamData (result, buf);
2092 return;
2093 }
2094
2095 cloneReply();
2096
2097#if USE_DELAY_POOLS
2098 if (sc)
2100#endif
2101
2103 return;
2104}
2105
2106void
2108{
2109 clientAclChecklistFill(checklist, http);
2110}
2111
2112/* Using this breaks the client layering just a little!
2113 */
2114void
2116{
2117 assert(http != nullptr);
2118 /*
2119 * For erroneous requests, we might not have a h->request,
2120 * so make a fake one.
2121 */
2122
2123 if (http->request == nullptr) {
2124 const auto connManager = http->getConn();
2125 const auto mx = MasterXaction::MakePortful(connManager ? connManager->port : nullptr);
2126 // XXX: These fake URI parameters shadow the real (or error:...) URI.
2127 // TODO: Either always set the request earlier and assert here OR use
2128 // http->uri (converted to Anyp::Uri) to create this catch-all request.
2129 const_cast<HttpRequest *&>(http->request) = new HttpRequest(m, AnyP::PROTO_NONE, "http", null_string, mx);
2131 }
2132
2133 StoreEntry *e = storeCreateEntry(storeId(), http->log_uri, reqFlags, m);
2134
2135 // Make entry collapsible ASAP, to increase collapsing chances for others,
2136 // TODO: every must-revalidate and similar request MUST reach the origin,
2137 // but do we have to prohibit others from collapsing on that request?
2138 if (reqFlags.cachable &&
2139 !reqFlags.needValidation &&
2140 (m == Http::METHOD_GET || m == Http::METHOD_HEAD) &&
2142 // make the entry available for future requests now
2143 (void)Store::Root().allowCollapsing(e, reqFlags, m);
2144 }
2145
2146 sc = storeClientListAdd(e, this);
2147
2148#if USE_DELAY_POOLS
2150#endif
2151
2152 reqofs = 0;
2153
2154 reqsize = 0;
2155
2156 /* I don't think this is actually needed! -- adrian */
2157 /* http->reqbuf = http->norm_reqbuf; */
2158 // assert(http->reqbuf == http->norm_reqbuf);
2159 /* The next line is illegal because we don't know if the client stream
2160 * buffers have been set up
2161 */
2162 // storeClientCopy(http->sc, e, 0, HTTP_REQBUF_SZ, http->reqbuf,
2163 // SendMoreData, this);
2164 /* So, we mark the store logic as complete */
2166
2167 /* and get the caller to request a read, from wherever they are */
2168 /* NOTE: after ANY data flows down the pipe, even one step,
2169 * this function CAN NOT be used to manage errors
2170 */
2171 http->storeEntry(e);
2172}
2173
2174ErrorState *
2175clientBuildError(err_type page_id, Http::StatusCode status, char const *url,
2176 const ConnStateData *conn, HttpRequest *request, const AccessLogEntry::Pointer &al)
2177{
2178 const auto err = new ErrorState(page_id, status, request, al);
2179 err->src_addr = conn && conn->clientConnection ? conn->clientConnection->remote : Ip::Address::NoAddr();
2180
2181 if (url)
2182 err->url = xstrdup(url);
2183
2184 return err;
2185}
2186
int esiEnableProcessing(HttpReply *rep)
Definition: Esi.cc:2239
CSCB esiProcessStream
CSR esiStreamRead
CSD esiStreamDetach
CSS esiStreamStatus
void httpHeaderPutStrf(HttpHeader *hdr, Http::HdrType id, const char *fmt,...)
void httpHdrMangleList(HttpHeader *l, HttpRequest *request, const AccessLogEntryPointer &al, req_or_rep_t req_or_rep)
@ ROR_REPLY
ssize_t HttpHeaderPos
Definition: HttpHeader.h:45
#define HttpHeaderInitPos
Definition: HttpHeader.h:48
@ LOG_TCP_REFRESH_FAIL_ERR
Definition: LogTags.h:43
@ LOG_TCP_DENIED
Definition: LogTags.h:52
@ LOG_TCP_REFRESH
Definition: LogTags.h:45
@ LOG_TCP_NEGATIVE_HIT
Definition: LogTags.h:50
@ LOG_TCP_REFRESH_MODIFIED
Definition: LogTags.h:44
@ LOG_TCP_REDIRECT
Definition: LogTags.h:55
@ LOG_TCP_OFFLINE_HIT
Definition: LogTags.h:54
@ LOG_TCP_HIT
Definition: LogTags.h:39
@ LOG_TCP_REFRESH_FAIL_OLD
Definition: LogTags.h:42
@ LOG_TCP_MISS
Definition: LogTags.h:40
@ LOG_TCP_MEM_HIT
Definition: LogTags.h:51
@ LOG_TCP_IMS_HIT
Definition: LogTags.h:47
@ LOG_TCP_REFRESH_UNMODIFIED
Definition: LogTags.h:41
@ LOG_TCP_DENIED_REPLY
Definition: LogTags.h:53
@ LOG_TCP_SWAPFAIL_MISS
Definition: LogTags.h:49
@ LOG_TCP_CLIENT_REFRESH_MISS
Definition: LogTags.h:46
@ LOG_TCP_INM_HIT
Definition: LogTags.h:48
time_t squid_curtime
Definition: stub_libtime.cc:20
class SquidConfig Config
Definition: SquidConfig.cc:12
class SquidConfig2 Config2
Definition: SquidConfig.cc:14
int storeClientIsThisAClient(store_client *sc, void *someClient)
#define Must(condition)
Definition: TextException.h:71
int conn
the current server connection FD
Definition: Transport.cc:26
#define assert(EX)
Definition: assert.h:17
int cbdataReferenceValid(const void *p)
Definition: cbdata.cc:265
#define cbdataReferenceDone(var)
Definition: cbdata.h:352
#define cbdataReference(var)
Definition: cbdata.h:343
#define CBDATA_CLASS_INIT(type)
Definition: cbdata.h:320
void nonBlockingCheck(ACLCB *callback, void *callback_data)
Definition: Checklist.cc:237
HttpReplyPointer reply
class AccessLogEntry::CacheDetails cache
class AccessLogEntry::HttpDetails http
bool allowed() const
Definition: Acl.h:156
ProtocolType protocol
which protocol this version is for
AnyP::UriScheme const & getScheme() const
Definition: Uri.h:67
void host(const char *src)
Definition: Uri.cc:99
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
struct ClientHttpRequest::Out out
HttpRequest *const request
ConnStateData * getConn() const
void updateLoggingTags(const LogTags_ot code)
update the code in the transaction processing tags
MemObject * memObject() const
struct ClientHttpRequest::Flags flags
bool requestSatisfactionMode() const
StoreEntry * storeEntry() const
const LogTags & loggingTags() const
the processing tags associated with this request transaction.
const AccessLogEntry::Pointer al
access.log entry
StoreEntry * loggingEntry() const
struct ClientHttpRequest::Redirect redirect
AnyP::Port port
destination port of the request that caused serverConnection
Definition: client_side.h:146
static DelayId DelayClient(ClientHttpRequest *, HttpReply *reply=nullptr)
Definition: DelayId.cc:67
Definition: ETag.h:18
int weak
true if it is a weak validator
Definition: ETag.h:21
const char * str
quoted-string
Definition: ETag.h:20
void * callback_data
Definition: errorpage.h:186
Http::StatusCode httpStatus
Definition: errorpage.h:173
static void Start(const Comm::ConnectionPointer &client, StoreEntry *, HttpRequest *, const AccessLogEntryPointer &alp)
Initiates request forwarding to a peer or origin server.
Definition: FwdState.cc:341
Http::HdrType id
Definition: HttpHeader.h:63
void removeHopByHopEntries()
Definition: HttpHeader.cc:1743
void putStr(Http::HdrType id, const char *str)
Definition: HttpHeader.cc:1027
void delAt(HttpHeaderPos pos, int &headers_deleted)
Definition: HttpHeader.cc:701
void putInt(Http::HdrType id, int number)
Definition: HttpHeader.cc:1000
int delById(Http::HdrType id)
Definition: HttpHeader.cc:673
void refreshMask()
Definition: HttpHeader.cc:729
HttpHeaderEntry * getEntry(HttpHeaderPos *pos) const
Definition: HttpHeader.cc:590
void addVia(const AnyP::ProtocolVersion &ver, const HttpHeader *from=nullptr)
Definition: HttpHeader.cc:977
int has(Http::HdrType id) const
Definition: HttpHeader.cc:969
int64_t getInt64(Http::HdrType id) const
Definition: HttpHeader.cc:1166
HttpHeaderEntry * findEntry(Http::HdrType id) const
Definition: HttpHeader.cc:609
void putExt(const char *name, const char *value)
Definition: HttpHeader.cc:1108
void putTime(Http::HdrType id, time_t htime)
Definition: HttpHeader.cc:1018
Http::StatusLine sline
Definition: HttpReply.h:56
HttpReplyPointer make304() const
Definition: HttpReply.cc:127
void setHeaders(Http::StatusCode status, const char *reason, const char *ctype, int64_t clen, time_t lmt, time_t expires)
Definition: HttpReply.cc:167
int64_t bodySize(const HttpRequestMethod &) const
Definition: HttpReply.cc:374
void removeIrrelevantContentLength()
Some response status codes prohibit sending Content-Length (RFC 7230 section 3.3.2).
Definition: HttpReply.cc:607
bool receivedBodyTooLarge(HttpRequest &, int64_t receivedBodySize)
Definition: HttpReply.cc:516
void redirect(Http::StatusCode, const char *)
Definition: HttpReply.cc:202
bool expectedBodyTooLarge(HttpRequest &request)
Definition: HttpReply.cc:524
HttpReply * clone() const override
Definition: HttpReply.cc:572
short int keep_alive
Definition: HttpReply.h:53
bool conditional() const
has at least one recognized If-* header
Definition: HttpRequest.cc:575
HttpHdrRange * range
Definition: HttpRequest.h:143
CbcPointer< ConnStateData > clientConnectionManager
Definition: HttpRequest.h:232
HttpRequestMethod method
Definition: HttpRequest.h:114
int prefixLen() const
Definition: HttpRequest.cc:369
bool multipartRangeRequest() const
Definition: HttpRequest.cc:434
HierarchyLogEntry hier
Definition: HttpRequest.h:157
time_t ims
Definition: HttpRequest.h:145
time_t lastmod
Definition: HttpRequest.h:167
RequestFlags flags
Definition: HttpRequest.h:141
SBuf vary_headers
The variant second-stage cache key. Generated from Vary header pattern for this request.
Definition: HttpRequest.h:170
String etag
A strong etag of the cached entry. Used for refreshing that entry.
Definition: HttpRequest.h:191
ConnStateData * pinnedConnection()
Definition: HttpRequest.cc:728
void ignoreRange(const char *reason)
forgets about the cached Range header (for a reason)
Definition: HttpRequest.cc:624
char * peer_login
Definition: HttpRequest.h:163
const SBuf storeId()
Definition: HttpRequest.cc:736
void swapOut(StoreEntry *e)
Definition: HttpRequest.cc:334
Auth::UserRequest::Pointer auth_user_request
Definition: HttpRequest.h:127
AnyP::Uri url
the request URI
Definition: HttpRequest.h:115
const SBuf & effectiveRequestUri() const
RFC 7230 section 5.5 - Effective Request URI.
Definition: HttpRequest.cc:747
bool persistent() const
Definition: Message.cc:247
HttpHeader header
Definition: Message.h:74
int hdr_sz
Definition: Message.h:81
int64_t content_length
Definition: Message.h:83
AnyP::ProtocolVersion http_ver
Definition: Message.h:72
AnyP::ProtocolVersion version
breakdown of protocol version label: (HTTP/ICY) and (0.9/1.0/1.1)
Definition: StatusLine.h:62
Http::StatusCode status() const
retrieve the status code for this status line
Definition: StatusLine.h:45
static const Address & NoAddr()
Definition: Address.h:302
bool ignored
_IGNORED: the response was not used for anything
Definition: LogTags.h:24
const char * c_str() const
compute the status access.log field
Definition: LogTags.cc:66
const char * cacheStatusSource() const
Definition: LogTags.cc:115
LogTagsErrors err
various problems augmenting the primary log tag
Definition: LogTags.h:84
LogTags_ot oldType
a set of client protocol, cache use, and other transaction outcome tags
Definition: LogTags.h:93
bool isTcpHit() const
determine if the log tag code indicates a cache HIT
Definition: LogTags.cc:101
static Pointer MakePortful(const AnyP::PortCfgPointer &aPort)
Definition: MasterXaction.h:54
const HttpReply & freshestReply() const
Definition: MemObject.h:67
const char * storeId() const
Definition: MemObject.cc:53
const HttpReply & baseReply() const
Definition: MemObject.h:59
C * getRaw() const
Definition: RefCount.h:80
bool needValidation
Definition: RequestFlags.h:50
bool accelerated
Definition: RequestFlags.h:62
bool connectionAuth
Definition: RequestFlags.h:80
bool chunkedReply
Definition: RequestFlags.h:94
bool noCacheHack() const
Definition: RequestFlags.h:128
bool mustKeepalive
Definition: RequestFlags.h:78
bool streamError
Definition: RequestFlags.h:96
bool intercepted
Definition: RequestFlags.h:66
bool proxyKeepalive
Definition: RequestFlags.h:42
bool failOnValidationError
Definition: RequestFlags.h:52
bool loopDetected
Definition: RequestFlags.h:40
bool connectionAuthDisabled
Definition: RequestFlags.h:82
SupportOrVeto cachable
whether the response may be stored in the cache
Definition: RequestFlags.h:35
Definition: SBuf.h:94
static const size_type npos
Definition: SBuf.h:99
const char * c_str()
Definition: SBuf.cc:516
int cmp(const SBuf &S, const size_type n) const
shorthand version for compare()
Definition: SBuf.h:275
size_type find(char c, size_type startPos=0) const
Definition: SBuf.cc:584
bool isEmpty() const
Definition: SBuf.h:431
SBuf & append(const SBuf &S)
Definition: SBuf.cc:185
Comm::ConnectionPointer clientConnection
Definition: Server.h:98
struct SquidConfig2::@121 onoff
int error_pconns
Definition: SquidConfig.h:304
struct SquidConfig::@107 accessList
acl_access * reply
Definition: SquidConfig.h:377
struct SquidConfig::@106 onoff
AclDenyInfoList * denyInfoList
Definition: SquidConfig.h:406
int client_pconns
Definition: SquidConfig.h:302
int collapsed_forwarding
Definition: SquidConfig.h:321
acl_access * sendHit
Definition: SquidConfig.h:365
bool mayInitiateCollapsing() const
whether Squid configuration allows us to become a CF initiator
Definition: StoreClient.h:45
bool startCollapsingOn(const StoreEntry &, const bool doingRevalidation) const
Definition: store_client.cc:64
mem_status_t mem_status
Definition: Store.h:240
uint16_t flags
Definition: Store.h:232
MemObject & mem()
Definition: Store.h:51
bool hasIfMatchEtag(const HttpRequest &request) const
has ETag matching at least one of the If-Match etags
Definition: store.cc:1841
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:1557
bool hasIfNoneMatchEtag(const HttpRequest &request) const
has ETag matching at least one of the If-None-Match etags
Definition: store.cc:1848
void dump(int debug_lvl) const
Definition: store.cc:1467
int unlock(const char *context)
Definition: store.cc:443
const char * url() const
Definition: store.cc:1534
void complete()
Definition: store.cc:1005
time_t expires
Definition: Store.h:226
bool hasEtag(ETag &etag) const
whether this entry has an ETag; if yes, puts ETag value into parameter
Definition: store.cc:1830
void lastModified(const time_t when)
Definition: Store.h:176
void release(const bool shareable=false)
Definition: store.cc:1120
void lock(const char *context)
Definition: store.cc:419
time_t timestamp
Definition: Store.h:224
bool timestampsSet()
Definition: store.cc:1361
void clearPublicKeyScope()
Definition: store.cc:583
void storeErrorResponse(HttpReply *reply)
Store a prepared error response. MemObject locks the reply object.
Definition: store.cc:1656
bool mayStartHitting() const
Definition: Store.h:288
int checkNegativeHit() const
Definition: store.cc:1274
void replaceHttpReply(const HttpReplyPointer &, const bool andStartWriting=true)
Definition: store.cc:1673
MemObject * mem_obj
Definition: Store.h:221
bool modifiedSince(const time_t ims, const int imslen=-1) const
Definition: store.cc:1804
int64_t objectLen() const
Definition: Store.h:257
store_status_t store_status
Definition: Store.h:244
void buffer() override
Definition: store.cc:1569
void releaseRequest(const bool shareable=false)
Definition: store.cc:432
unsigned error
Definition: StoreIOBuffer.h:52
int64_t offset
Definition: StoreIOBuffer.h:55
struct StoreIOBuffer::@142 flags
bool allowCollapsing(StoreEntry *, const RequestFlags &, const HttpRequestMethod &)
tries to make the entry available for collapsing future requests
Definition: Controller.cc:728
static bool SmpAware()
whether there are any SMP-aware storages
Definition: Controller.cc:913
void evictIfFound(const cache_key *) override
Definition: Controller.cc:501
void updateOnNotModified(StoreEntry *old, StoreEntry &e304)
using a 304 response, update the old entry (metadata and reply headers)
Definition: Controller.cc:695
void clean()
Definition: String.cc:118
char const * rawBuf() const
Definition: SquidString.h:86
char const * termedBuf() const
Definition: SquidString.h:92
void handleIMSReply(StoreIOBuffer result)
clientStreamNode * ourNode
void sendNotModifiedOrPreconditionFailedError()
void setReplyToReply(HttpReply *reply)
creates a store entry for the reply and appends error reply to it
void traceReply(clientStreamNode *node)
static ACLCB ProcessReplyAccessResult
bool alwaysAllowResponse(Http::StatusCode sline) const
static STCB HandleIMSReply
void sendPreconditionFailedError()
send 412 (Precondition Failed) to client
store_client * old_sc
void cacheHit(StoreIOBuffer result)
void sendStreamError(StoreIOBuffer const &result)
@ crInitiator
we initiated collapsed revalidation request
@ crNone
collapsed revalidation is not allowed for this context
@ crSlave
we collapsed on the existing revalidation request
Http::StatusCode purgeStatus
void startError(ErrorState *err)
void identifyFoundObject(StoreEntry *entry, const char *detail)
void sendNotModified()
send 304 (Not Modified) to client
void createStoreEntry(const HttpRequestMethod &m, RequestFlags flags)
void setReplyToStoreEntry(StoreEntry *e, const char *reason)
replaces current response store entry with the given one
bool blockedHit() const
whether squid.conf send_hit prevents us from serving this hit
bool errorInStream(StoreIOBuffer const &result, size_t const &sizeToProcess) const
int storeNotOKTransferDone() const
void removeClientStoreReference(store_client **scp, ClientHttpRequest *http)
void pushStreamData(StoreIOBuffer const &result, char *source)
~clientReplyContext() override
struct clientReplyContext::Flags flags
void processReplyAccessResult(const Acl::Answer &accessAllowed)
const char * firstStoreLookup_
CollapsedRevalidation collapsedRevalidation
char tempbuf[HTTP_REQBUF_SZ]
a temporary buffer if we need working storage
const char * storeLookupString(bool found) const
bool purgeEntry(StoreEntry &, const Http::MethodType, const char *descriptionPrefix="")
clientStreamNode * next() const
void sendMoreData(StoreIOBuffer result)
ClientHttpRequest * http
clientStream_status_t replyStatus()
void removeStoreReference(store_client **scp, StoreEntry **ep)
LogTags * loggingTags() const override
const char * storeId() const
bool processConditional()
process conditional request from client
int storeOKTransferDone() const
clientStreamNode * getNextNode() const
void fillChecklist(ACLFilledChecklist &) const override
configure the given checklist (to reflect the current transaction state)
void setReplyToError(err_type, Http::StatusCode, char const *, const ConnStateData *, HttpRequest *, const char *, Auth::UserRequest::Pointer)
builds error using clientBuildError() and calls setReplyToError() below
void purgeDoPurge()
releases both cached GET and HEAD entries
static STCB SendMoreData
clientReplyContext(ClientHttpRequest *)
void detailStoreLookup(const char *detail)
remembers the very first Store lookup classification, ignoring the rest
StoreIOBuffer readBuffer
Definition: clientStream.h:94
ClientStreamData data
Definition: clientStream.h:93
dlink_node node
Definition: clientStream.h:87
void setDelayId(DelayId delay_id)
void CSD(clientStreamNode *, ClientHttpRequest *)
client stream detach
void CSR(clientStreamNode *, ClientHttpRequest *)
client stream read
clientStream_status_t CSS(clientStreamNode *, ClientHttpRequest *)
int varyEvaluateMatch(StoreEntry *entry, HttpRequest *request)
void clientAclChecklistFill(ACLFilledChecklist &checklist, ClientHttpRequest *http)
ACLFilledChecklist * clientAclChecklistCreate(const acl_access *acl, ClientHttpRequest *http)
CSS clientReplyStatus
ErrorState * clientBuildError(err_type, Http::StatusCode, char const *, const ConnStateData *, HttpRequest *, const AccessLogEntry::Pointer &)
SQUIDCEXTERN CSR clientGetMoreData
void purgeEntriesByUrl(HttpRequest *req, const char *url)
SQUIDCEXTERN CSD clientReplyDetach
#define DBG_IMPORTANT
Definition: Stream.h:38
#define debugs(SECTION, LEVEL, CONTENT)
Definition: Stream.h:194
#define DBG_CRITICAL
Definition: Stream.h:37
#define EBIT_TEST(flag, bit)
Definition: defines.h:69
@ VARY_OTHER
Definition: enums.h:195
@ VARY_NONE
Definition: enums.h:193
@ VARY_CANCEL
Definition: enums.h:196
@ VARY_MATCH
Definition: enums.h:194
@ IN_MEMORY
Definition: enums.h:36
@ HTCP_CLR_INVALIDATION
Definition: enums.h:243
@ HTCP_CLR_PURGE
Definition: enums.h:242
clientStream_status_t
Definition: enums.h:125
@ STREAM_COMPLETE
Definition: enums.h:127
@ STREAM_UNPLANNED_COMPLETE
Definition: enums.h:132
@ STREAM_NONE
Definition: enums.h:126
@ STREAM_FAILED
Definition: enums.h:137
@ ENTRY_BAD_LENGTH
Definition: enums.h:114
@ ENTRY_SPECIAL
Definition: enums.h:84
@ ENTRY_ABORTED
Definition: enums.h:115
@ STORE_OK
Definition: enums.h:50
err_type
Definition: forward.h:14
@ ERR_ACCESS_DENIED
Definition: forward.h:18
@ ERR_NONE
Definition: forward.h:15
@ ERR_PRECONDITION_FAILED
Definition: forward.h:47
@ ERR_TOO_BIG
Definition: forward.h:40
@ ERR_ONLY_IF_CACHED_MISS
Definition: forward.h:39
int fdUsageHigh(void)
Definition: fd.cc:271
int shutting_down
const char * null_string
err_type aclGetDenyInfoPage(AclDenyInfoList **head, const char *name, int redirect_allowed)
Definition: Gadgets.cc:42
const char * AclMatchedName
Definition: Acl.cc:29
@ ACCESS_ALLOWED
Definition: Acl.h:116
void clientStreamCallback(clientStreamNode *thisObject, ClientHttpRequest *http, HttpReply *rep, StoreIOBuffer replyBuffer)
void clientStreamInsertHead(dlink_list *list, CSR *func, CSCB *callback, CSD *detach, CSS *status, ClientStreamData data)
void clientStreamDetach(clientStreamNode *thisObject, ClientHttpRequest *http)
void errorAppendEntry(StoreEntry *entry, ErrorState *err)
Definition: errorpage.cc:718
void ipcacheInvalidateNegative(const char *name)
Definition: ipcache.cc:872
void ipcacheInvalidate(const char *name)
Definition: ipcache.cc:855
void HTTPMSGUNLOCK(M *&a)
Definition: Message.h:149
void HTTPMSGLOCK(Http::Message *a)
Definition: Message.h:160
#define HTTP_REQBUF_SZ
Definition: forward.h:14
@ PROTO_NONE
Definition: ProtocolType.h:24
@ PROTO_HTTPS
Definition: ProtocolType.h:27
@ PROTO_HTTP
Definition: ProtocolType.h:25
bool IsConnOpen(const Comm::ConnectionPointer &conn)
Definition: Connection.cc:27
Definition: forward.h:18
enum Http::_method_t MethodType
StatusCode
Definition: StatusCode.h:20
@ scProcessing
Definition: StatusCode.h:24
@ scGatewayTimeout
Definition: StatusCode.h:75
@ scForbidden
Definition: StatusCode.h:47
@ scUnauthorized
Definition: StatusCode.h:45
@ scNotImplemented
Definition: StatusCode.h:72
@ scInternalServerError
Definition: StatusCode.h:71
@ scNotFound
Definition: StatusCode.h:48
@ scProxyAuthenticationRequired
Definition: StatusCode.h:51
@ scNone
Definition: StatusCode.h:21
@ scNotModified
Definition: StatusCode.h:40
@ scOkay
Definition: StatusCode.h:26
@ scContinue
Definition: StatusCode.h:22
@ scNoContent
Definition: StatusCode.h:30
@ scSwitchingProtocols
Definition: StatusCode.h:23
@ scPreconditionFailed
Definition: StatusCode.h:56
const SBuf & MethodStr(const MethodType m)
Definition: MethodType.h:100
@ METHOD_TRACE
Definition: MethodType.h:30
@ METHOD_NONE
Definition: MethodType.h:22
@ METHOD_OTHER
Definition: MethodType.h:93
@ METHOD_ENUM_END
Definition: MethodType.h:94
@ METHOD_GET
Definition: MethodType.h:25
@ METHOD_PURGE
Definition: MethodType.h:92
@ METHOD_HEAD
Definition: MethodType.h:28
@ SURROGATE_CONTROL
@ WWW_AUTHENTICATE
@ IF_MODIFIED_SINCE
@ TRANSFER_ENCODING
@ SURROGATE_CAPABILITY
@ PROXY_AUTHENTICATE
AnyP::ProtocolVersion ProtocolVersion(unsigned int aMajor, unsigned int aMinor)
HTTP version label information.
int doNfmarkLocalHit(const Comm::ConnectionPointer &conn)
Definition: QosConfig.cc:275
Config TheConfig
Globally available instance of Qos::Config.
Definition: QosConfig.cc:283
int doTosLocalMiss(const Comm::ConnectionPointer &conn, const hier_code hierCode)
Definition: QosConfig.cc:226
int doNfmarkLocalMiss(const Comm::ConnectionPointer &conn, const hier_code hierCode)
Definition: QosConfig.cc:247
int doTosLocalHit(const Comm::ConnectionPointer &conn)
Definition: QosConfig.cc:268
Controller & Root()
safely access controller singleton
Definition: Controller.cc:931
#define xstrdup
void neighborsHtcpClear(StoreEntry *e, HttpRequest *req, const HttpRequestMethod &method, htcp_clr_reason reason)
Definition: neighbors.cc:1757
int refreshCheckHTTP(const StoreEntry *entry, HttpRequest *request)
Definition: refresh.cc:575
static int sc[16]
Definition: smbdes.c:121
#define SQUIDCEXTERN
Definition: squid.h:21
unsigned char cache_key
Store key.
Definition: forward.h:29
StoreEntry * storeGetPublicByRequestMethod(HttpRequest *req, const HttpRequestMethod &method, const KeyScope keyScope)
Definition: store.cc:484
StoreEntry * storeGetPublicByRequest(HttpRequest *req, const KeyScope keyScope)
Definition: store.cc:490
StoreEntry * storeCreateEntry(const char *url, const char *logUrl, const RequestFlags &flags, const HttpRequestMethod &method)
Definition: store.cc:733
StoreEntry * storeGetPublic(const char *uri, const HttpRequestMethod &method)
Definition: store.cc:478
int storeUnregister(store_client *sc, StoreEntry *e, void *data)
void storeClientCopy(store_client *sc, StoreEntry *e, StoreIOBuffer copyInto, STCB *callback, void *data)
store_client * storeClientListAdd(StoreEntry *e, void *data)
const cache_key * storeKeyPublic(const char *url, const HttpRequestMethod &method, const KeyScope keyScope)
const char * storeKeyText(const cache_key *key)
@ ksRevalidation
Definition: store_key_md5.h:20
uint64_t size
Response header and body bytes written to the client connection.
unsigned complete
we have read all we can from upstream
Definition: parse.c:104
struct node * next
Definition: parse.c:105
const char * uniqueHostname(void)
Definition: tools.cc:547
#define PRId64
Definition: types.h:104

 

Introduction

Documentation

Support

Miscellaneous

Web Site Translations

Mirrors