http.cc
Go to the documentation of this file.
1 /*
2  * Copyright (C) 1996-2018 The Squid Software Foundation and contributors
3  *
4  * Squid software is distributed under GPLv2+ license and includes
5  * contributions from numerous individuals and organizations.
6  * Please see the COPYING and CONTRIBUTORS files for details.
7  */
8 
9 /* DEBUG: section 11 Hypertext Transfer Protocol (HTTP) */
10 
11 /*
12  * Anonymizing patch by lutz@as-node.jena.thur.de
13  * have a look into http-anon.c to get more informations.
14  */
15 
16 #include "squid.h"
17 #include "acl/FilledChecklist.h"
18 #include "base/AsyncJobCalls.h"
19 #include "base/TextException.h"
20 #include "base64.h"
21 #include "CachePeer.h"
22 #include "client_side.h"
23 #include "comm/Connection.h"
24 #include "comm/Read.h"
25 #include "comm/Write.h"
26 #include "CommRead.h"
27 #include "err_detail_type.h"
28 #include "errorpage.h"
29 #include "fd.h"
30 #include "fde.h"
31 #include "globals.h"
32 #include "http.h"
35 #include "http/Stream.h"
36 #include "HttpControlMsg.h"
37 #include "HttpHdrCc.h"
38 #include "HttpHdrContRange.h"
39 #include "HttpHdrSc.h"
40 #include "HttpHdrScTarget.h"
41 #include "HttpHeaderTools.h"
42 #include "HttpReply.h"
43 #include "HttpRequest.h"
44 #include "log/access_log.h"
45 #include "MemBuf.h"
46 #include "MemObject.h"
47 #include "neighbors.h"
49 #include "profiler/Profiler.h"
50 #include "refresh.h"
51 #include "RefreshPattern.h"
52 #include "rfc1738.h"
53 #include "SquidConfig.h"
54 #include "SquidTime.h"
55 #include "StatCounters.h"
56 #include "Store.h"
57 #include "StrList.h"
58 #include "tools.h"
59 #include "URL.h"
60 #include "util.h"
61 
62 #if USE_AUTH
63 #include "auth/UserRequest.h"
64 #endif
65 #if USE_DELAY_POOLS
66 #include "DelayPools.h"
67 #endif
68 
69 #define SQUID_ENTER_THROWING_CODE() try {
70 #define SQUID_EXIT_THROWING_CODE(status) \
71  status = true; \
72  } \
73  catch (const std::exception &e) { \
74  debugs (11, 1, "Exception error:" << e.what()); \
75  status = false; \
76  }
77 
79 
80 static const char *const crlf = "\r\n";
81 
83 static void copyOneHeaderFromClientsideRequestToUpstreamRequest(const HttpHeaderEntry *e, const String strConnection, const HttpRequest * request,
84  HttpHeader * hdr_out, const int we_do_ranges, const Http::StateFlags &);
85 
87  AsyncJob("HttpStateData"),
88  Client(theFwdState),
89  lastChunk(0),
90  httpChunkDecoder(NULL),
91  payloadSeen(0),
92  payloadTruncated(0),
93  sawDateGoBack(false)
94 {
95  debugs(11,5,HERE << "HttpStateData " << this << " created");
96  ignoreCacheControl = false;
97  surrogateNoStore = false;
99 
100  if (fwd->serverConnection() != NULL)
101  _peer = cbdataReference(fwd->serverConnection()->getPeer()); /* might be NULL */
102 
103  if (_peer) {
104  request->flags.proxying = true;
105  /*
106  * This NEIGHBOR_PROXY_ONLY check probably shouldn't be here.
107  * We might end up getting the object from somewhere else if,
108  * for example, the request to this neighbor fails.
109  */
110  if (_peer->options.proxy_only)
111  entry->releaseRequest(true);
112 
113 #if USE_DELAY_POOLS
115 #endif
116  }
117 
118  /*
119  * register the handler to free HTTP state data when the FD closes
120  */
124 }
125 
127 {
128  /*
129  * don't forget that ~Client() gets called automatically
130  */
131 
132  if (httpChunkDecoder)
133  delete httpChunkDecoder;
134 
136 
137  debugs(11,5, HERE << "HttpStateData " << this << " destroyed; " << serverConnection);
138 }
139 
142 {
143  return serverConnection;
144 }
145 
146 void
148 {
149  debugs(11, 5, "httpStateFree: FD " << params.fd << ", httpState=" << params.data);
150  doneWithFwd = "httpStateConnClosed()"; // assume FwdState is monitoring too
151  mustStop("HttpStateData::httpStateConnClosed");
152 }
153 
154 void
156 {
157  debugs(11, 4, serverConnection << ": '" << entry->url() << "'");
158 
159  if (entry->store_status == STORE_PENDING) {
161  }
162 
163  closeServer();
164  mustStop("HttpStateData::httpTimeout");
165 }
166 
167 static StoreEntry *
169  assert(newEntry->mem_obj);
170  return newEntry->mem_obj->request ?
172  storeGetPublic(newEntry->mem_obj->storeId(), newEntry->mem_obj->method);
173 }
174 
177 static void
179 {
180  int remove = 0;
181  int forbidden = 0;
182 
183  // If the incoming response already goes into a public entry, then there is
184  // nothing to remove. This protects ready-for-collapsing entries as well.
185  if (!EBIT_TEST(e->flags, KEY_PRIVATE))
186  return;
187 
188  // If the new/incoming response cannot be stored, then it does not
189  // compete with the old stored response for the public key, and the
190  // old stored response should be left as is.
191  if (e->mem_obj->request && !e->mem_obj->request->flags.cachable)
192  return;
193 
194  switch (status) {
195 
196  case Http::scOkay:
197 
199 
201 
203 
204  case Http::scFound:
205 
206  case Http::scSeeOther:
207 
208  case Http::scGone:
209 
210  case Http::scNotFound:
211  remove = 1;
212 
213  break;
214 
215  case Http::scForbidden:
216 
218  forbidden = 1;
219 
220  break;
221 
222 #if WORK_IN_PROGRESS
223 
225  forbidden = 1;
226 
227  break;
228 
229 #endif
230 
231  default:
232 #if QUESTIONABLE
233  /*
234  * Any 2xx response should eject previously cached entities...
235  */
236 
237  if (status >= 200 && status < 300)
238  remove = 1;
239 
240 #endif
241 
242  break;
243  }
244 
245  if (!remove && !forbidden)
246  return;
247 
249 
250  if (pe != NULL) {
251  assert(e != pe);
252 #if USE_HTCP
254 #endif
255  pe->release(true);
256  }
257 
262  if (e->mem_obj->request)
264  else
266 
267  if (pe != NULL) {
268  assert(e != pe);
269 #if USE_HTCP
271 #endif
272  pe->release(true);
273  }
274 }
275 
276 void
278 {
279  if (request->flags.accelerated && reply->surrogate_control) {
281 
282  if (sctusable) {
283  if (sctusable->hasNoStore() ||
285  && sctusable->noStoreRemote())) {
286  surrogateNoStore = true;
287  // Be conservative for now and make it non-shareable because
288  // there is no enough information here to make the decision.
289  entry->makePrivate(false);
290  }
291 
292  /* The HttpHeader logic cannot tell if the header it's parsing is a reply to an
293  * accelerated request or not...
294  * Still, this is an abstraction breach. - RC
295  */
296  if (sctusable->hasMaxAge()) {
297  if (sctusable->maxAge() < sctusable->maxStale())
298  reply->expires = reply->date + sctusable->maxAge();
299  else
300  reply->expires = reply->date + sctusable->maxStale();
301 
302  /* And update the timestamps */
303  entry->timestampsSet();
304  }
305 
306  /* We ignore cache-control directives as per the Surrogate specification */
307  ignoreCacheControl = true;
308 
309  delete sctusable;
310  }
311  }
312 }
313 
316 {
317  HttpReply const *rep = finalReply();
318  HttpHeader const *hdr = &rep->header;
319  const char *v;
320 #if USE_HTTP_VIOLATIONS
321 
322  const RefreshPattern *R = NULL;
323 
324  /* This strange looking define first looks up the refresh pattern
325  * and then checks if the specified flag is set. The main purpose
326  * of this is to simplify the refresh pattern lookup and USE_HTTP_VIOLATIONS
327  * condition
328  */
329 #define REFRESH_OVERRIDE(flag) \
330  ((R = (R ? R : refreshLimits(entry->mem_obj->storeId()))) , \
331  (R && R->flags.flag))
332 #else
333 #define REFRESH_OVERRIDE(flag) 0
334 #endif
335 
337  return decision.make(ReuseDecision::doNotCacheButShare, "the entry has been released");
338 
339  // RFC 7234 section 4: a cache MUST use the most recent response
340  // (as determined by the Date header field)
341  // TODO: whether such responses could be shareable?
342  if (sawDateGoBack)
343  return decision.make(ReuseDecision::reuseNot, "the response has an older date header");
344 
345  // Check for Surrogate/1.0 protocol conditions
346  // NP: reverse-proxy traffic our parent server has instructed us never to cache
347  if (surrogateNoStore)
348  return decision.make(ReuseDecision::reuseNot, "Surrogate-Control:no-store");
349 
350  // RFC 2616: HTTP/1.1 Cache-Control conditions
351  if (!ignoreCacheControl) {
352  // XXX: check to see if the request headers alone were enough to prevent caching earlier
353  // (ie no-store request header) no need to check those all again here if so.
354  // for now we are not reliably doing that so we waste CPU re-checking request CC
355 
356  // RFC 2616 section 14.9.2 - MUST NOT cache any response with request CC:no-store
358  !REFRESH_OVERRIDE(ignore_no_store))
359  return decision.make(ReuseDecision::reuseNot,
360  "client request Cache-Control:no-store");
361 
362  // NP: request CC:no-cache only means cache READ is forbidden. STORE is permitted.
364  /* TODO: we are allowed to cache when no-cache= has parameters.
365  * Provided we strip away any of the listed headers unless they are revalidated
366  * successfully (ie, must revalidate AND these headers are prohibited on stale replies).
367  * That is a bit tricky for squid right now so we avoid caching entirely.
368  */
369  return decision.make(ReuseDecision::reuseNot,
370  "server reply Cache-Control:no-cache has parameters");
371  }
372 
373  // NP: request CC:private is undefined. We ignore.
374  // NP: other request CC flags are limiters on HIT/MISS. We don't care about here.
375 
376  // RFC 2616 section 14.9.2 - MUST NOT cache any response with CC:no-store
377  if (rep->cache_control && rep->cache_control->hasNoStore() &&
378  !REFRESH_OVERRIDE(ignore_no_store))
379  return decision.make(ReuseDecision::reuseNot,
380  "server reply Cache-Control:no-store");
381 
382  // RFC 2616 section 14.9.1 - MUST NOT cache any response with CC:private in a shared cache like Squid.
383  // CC:private overrides CC:public when both are present in a response.
384  // TODO: add a shared/private cache configuration possibility.
385  if (rep->cache_control &&
386  rep->cache_control->hasPrivate() &&
387  !REFRESH_OVERRIDE(ignore_private)) {
388  /* TODO: we are allowed to cache when private= has parameters.
389  * Provided we strip away any of the listed headers unless they are revalidated
390  * successfully (ie, must revalidate AND these headers are prohibited on stale replies).
391  * That is a bit tricky for squid right now so we avoid caching entirely.
392  */
393  return decision.make(ReuseDecision::reuseNot,
394  "server reply Cache-Control:private");
395  }
396  }
397 
398  // RFC 2068, sec 14.9.4 - MUST NOT cache any response with Authentication UNLESS certain CC controls are present
399  // allow HTTP violations to IGNORE those controls (ie re-block caching Auth)
400  if (request && (request->flags.auth || request->flags.authSent)) {
401  if (!rep->cache_control)
402  return decision.make(ReuseDecision::reuseNot,
403  "authenticated and server reply missing Cache-Control");
404 
405  if (ignoreCacheControl)
406  return decision.make(ReuseDecision::reuseNot,
407  "authenticated and ignoring Cache-Control");
408 
409  bool mayStore = false;
410  // HTTPbis pt6 section 3.2: a response CC:public is present
411  if (rep->cache_control->hasPublic()) {
412  debugs(22, 3, HERE << "Authenticated but server reply Cache-Control:public");
413  mayStore = true;
414 
415  // HTTPbis pt6 section 3.2: a response CC:must-revalidate is present
416  } else if (rep->cache_control->hasMustRevalidate()) {
417  debugs(22, 3, HERE << "Authenticated but server reply Cache-Control:must-revalidate");
418  mayStore = true;
419 
420 #if USE_HTTP_VIOLATIONS
421  // NP: given the must-revalidate exception we should also be able to exempt no-cache.
422  // HTTPbis WG verdict on this is that it is omitted from the spec due to being 'unexpected' by
423  // some. The caching+revalidate is not exactly unsafe though with Squids interpretation of no-cache
424  // (without parameters) as equivalent to must-revalidate in the reply.
425  } else if (rep->cache_control->hasNoCacheWithoutParameters()) {
426  debugs(22, 3, HERE << "Authenticated but server reply Cache-Control:no-cache (equivalent to must-revalidate)");
427  mayStore = true;
428 #endif
429 
430  // HTTPbis pt6 section 3.2: a response CC:s-maxage is present
431  } else if (rep->cache_control->hasSMaxAge()) {
432  debugs(22, 3, HERE << "Authenticated but server reply Cache-Control:s-maxage");
433  mayStore = true;
434  }
435 
436  if (!mayStore)
437  return decision.make(ReuseDecision::reuseNot, "authenticated transaction");
438 
439  // NP: response CC:no-cache is equivalent to CC:must-revalidate,max-age=0. We MAY cache, and do so.
440  // NP: other request CC flags are limiters on HIT/MISS/REFRESH. We don't care about here.
441  }
442 
443  /* HACK: The "multipart/x-mixed-replace" content type is used for
444  * continuous push replies. These are generally dynamic and
445  * probably should not be cachable
446  */
447  if ((v = hdr->getStr(Http::HdrType::CONTENT_TYPE)))
448  if (!strncasecmp(v, "multipart/x-mixed-replace", 25))
449  return decision.make(ReuseDecision::reuseNot, "Content-Type:multipart/x-mixed-replace");
450 
451  // TODO: if possible, provide more specific message for each status code
452  static const char *shareableError = "shareable error status code";
453  static const char *nonShareableError = "non-shareable error status code";
455  const char *statusReason = nonShareableError;
456 
457  switch (rep->sline.status()) {
458 
459  /* There are several situations when a non-cacheable response may be
460  * still shareable (e.g., among collapsed clients). We assume that these
461  * are 3xx and 5xx responses, indicating server problems and some of
462  * 4xx responses, common for all clients with a given cache key (e.g.,
463  * 404 Not Found or 414 URI Too Long). On the other hand, we should not
464  * share non-cacheable client-specific errors, such as 400 Bad Request
465  * or 406 Not Acceptable.
466  */
467 
468  /* Responses that are cacheable */
469 
470  case Http::scOkay:
471 
473 
475 
478 
479  case Http::scGone:
480  /*
481  * Don't cache objects that need to be refreshed on next request,
482  * unless we know how to refresh it.
483  */
484 
485  if (refreshIsCachable(entry) || REFRESH_OVERRIDE(store_stale))
486  decision.make(ReuseDecision::cachePositively, "refresh check returned cacheable");
487  else
488  decision.make(ReuseDecision::doNotCacheButShare, "refresh check returned non-cacheable");
489  break;
490 
491  /* Responses that only are cacheable if the server says so */
492 
493  case Http::scFound:
495  if (rep->date <= 0)
496  decision.make(ReuseDecision::doNotCacheButShare, "Date is missing/invalid");
497  else if (rep->expires > rep->date)
498  decision.make(ReuseDecision::cachePositively, "Expires > Date");
499  else
500  decision.make(ReuseDecision::doNotCacheButShare, "Expires <= Date");
501  break;
502 
503  /* These responses can be negatively cached. Most can also be shared. */
504  case Http::scNoContent:
505  case Http::scUseProxy:
506  case Http::scForbidden:
507  case Http::scNotFound:
509  case Http::scUriTooLong:
512  case Http::scBadGateway:
516  statusAnswer = ReuseDecision::doNotCacheButShare;
517  statusReason = shareableError;
518  // fall through to the actual decision making below
519 
520  case Http::scBadRequest: // no sharing; perhaps the server did not like something specific to this request
521 #if USE_HTTP_VIOLATIONS
522  if (Config.negativeTtl > 0)
523  decision.make(ReuseDecision::cacheNegatively, "Config.negativeTtl > 0");
524  else
525 #endif
526  decision.make(statusAnswer, statusReason);
527  break;
528 
529  /* these responses can never be cached, some
530  of them can be shared though */
531  case Http::scSeeOther:
532  case Http::scNotModified:
537  // TODO: use more specific reason for non-error status codes
538  decision.make(ReuseDecision::doNotCacheButShare, shareableError);
539  break;
540 
541  case Http::scPartialContent: /* Not yet supported. TODO: make shareable for suitable ranges */
543  case Http::scRequestTimeout: // TODO: is this shareable?
544  case Http::scConflict: // TODO: is this shareable?
550  case Http::scLocked: // TODO: is this shareable?
554  case Http::scInvalidHeader: /* Squid header parsing error */
556  decision.make(ReuseDecision::reuseNot, nonShareableError);
557  break;
558 
559  default:
560  /* RFC 2616 section 6.1.1: an unrecognized response MUST NOT be cached. */
561  decision.make(ReuseDecision::reuseNot, "unknown status code");
562  break;
563  }
564 
565  return decision.answer;
566 }
567 
569 static void
571 {
572  static const SBuf asterisk("*");
573  const char *pos = nullptr;
574  const char *item = nullptr;
575  int ilen = 0;
576 
577  while (strListGetItem(&vary, ',', &item, &ilen, &pos)) {
578  SBuf name(item, ilen);
579  if (name == asterisk) {
580  vstr = asterisk;
581  break;
582  }
583  name.toLower();
584  if (!vstr.isEmpty())
585  vstr.append(", ", 2);
586  vstr.append(name);
587  String hdr(request.header.getByName(name));
588  const char *value = hdr.termedBuf();
589  if (value) {
590  value = rfc1738_escape_part(value);
591  vstr.append("=\"", 2);
592  vstr.append(value);
593  vstr.append("\"", 1);
594  }
595 
596  hdr.clean();
597  }
598 }
599 
600 /*
601  * For Vary, store the relevant request headers as
602  * virtual headers in the reply
603  * Returns an empty SBuf if the variance cannot be stored
604  */
605 SBuf
607 {
608  SBuf vstr;
609  String vary;
610 
611  vary = reply->header.getList(Http::HdrType::VARY);
612  assembleVaryKey(vary, vstr, *request);
613 
614 #if X_ACCELERATOR_VARY
615  vary.clean();
617  assembleVaryKey(vary, vstr, *request);
618 #endif
619 
620  debugs(11, 3, vstr);
621  return vstr;
622 }
623 
624 void
626 {
627  if (flags.keepalive)
628  if (_peer)
630 
631  if (reply->keep_alive) {
632  if (_peer)
634 
636  && reply->bodySize(request->method) == -1 && !flags.chunked) {
637  debugs(11, DBG_IMPORTANT, "keepaliveAccounting: Impossible keep-alive header from '" << entry->url() << "'" );
638  // debugs(11, 2, "GOT HTTP REPLY HDR:\n---------\n" << readBuf->content() << "\n----------" );
639  flags.keepalive_broken = true;
640  }
641  }
642 }
643 
644 void
646 {
647  if (reply->date > -1 && !_peer) {
648  int skew = abs((int)(reply->date - squid_curtime));
649 
650  if (skew > 86400)
651  debugs(11, 3, "" << request->url.host() << "'s clock is skewed by " << skew << " seconds!");
652  }
653 }
654 
661 void
663 {
666  /* NP: all exit points to this function MUST call ctx_exit(ctx) */
667  Ctx ctx = ctx_enter(entry->mem_obj->urlXXX());
668 
669  debugs(11, 3, "processReplyHeader: key '" << entry->getMD5Text() << "'");
670 
672 
673  if (!inBuf.length()) {
674  ctx_exit(ctx);
675  return;
676  }
677 
678  /* Attempt to parse the first line; this will define where the protocol, status, reason-phrase and header begin */
679  {
680  if (hp == NULL)
682 
683  bool parsedOk = hp->parse(inBuf);
684 
685  // sync the buffers after parsing.
686  inBuf = hp->remaining();
687 
688  if (hp->needsMoreData()) {
689  if (eof) { // no more data coming
690  /* Bug 2879: Replies may terminate with \r\n then EOF instead of \r\n\r\n.
691  * We also may receive truncated responses.
692  * Ensure here that we have at minimum two \r\n when EOF is seen.
693  */
694  inBuf.append("\r\n\r\n", 4);
695  // retry the parse
696  parsedOk = hp->parse(inBuf);
697  // sync the buffers after parsing.
698  inBuf = hp->remaining();
699  } else {
700  debugs(33, 5, "Incomplete response, waiting for end of response headers");
701  ctx_exit(ctx);
702  return;
703  }
704  }
705 
706  if (!parsedOk) {
707  // unrecoverable parsing error
708  // TODO: Use Raw! XXX: inBuf no longer has the [beginning of the] malformed header.
709  debugs(11, 3, "Non-HTTP-compliant header:\n---------\n" << inBuf << "\n----------");
710  flags.headers_parsed = true;
711  HttpReply *newrep = new HttpReply;
712  newrep->sline.set(Http::ProtocolVersion(), hp->parseStatusCode);
713  setVirginReply(newrep);
714  ctx_exit(ctx);
715  return;
716  }
717  }
718 
719  /* We know the whole response is in parser now */
720  debugs(11, 2, "HTTP Server " << serverConnection);
721  debugs(11, 2, "HTTP Server RESPONSE:\n---------\n" <<
722  hp->messageProtocol() << " " << hp->messageStatus() << " " << hp->reasonPhrase() << "\n" <<
723  hp->mimeHeader() <<
724  "----------");
725 
726  // reset payload tracking to begin after message headers
728 
729  HttpReply *newrep = new HttpReply;
730  // XXX: RFC 7230 indicates we MAY ignore the reason phrase,
731  // and use an empty string on unknown status.
732  // We do that now to avoid performance regression from using SBuf::c_str()
733  newrep->sline.set(Http::ProtocolVersion(1,1), hp->messageStatus() /* , hp->reasonPhrase() */);
734  newrep->sline.protocol = newrep->sline.version.protocol = hp->messageProtocol().protocol;
735  newrep->sline.version.major = hp->messageProtocol().major;
736  newrep->sline.version.minor = hp->messageProtocol().minor;
737 
738  // parse headers
739  if (!newrep->parseHeader(*hp)) {
740  // XXX: when Http::ProtocolVersion is a function, remove this hack. just set with messageProtocol()
742  newrep->sline.version.protocol = hp->messageProtocol().protocol;
743  newrep->sline.version.major = hp->messageProtocol().major;
744  newrep->sline.version.minor = hp->messageProtocol().minor;
745  debugs(11, 2, "error parsing response headers mime block");
746  }
747 
748  // done with Parser, now process using the HttpReply
749  hp = NULL;
750 
752 
753  newrep->removeStaleWarnings();
754 
755  if (newrep->sline.protocol == AnyP::PROTO_HTTP && newrep->sline.status() >= 100 && newrep->sline.status() < 200) {
756  handle1xx(newrep);
757  ctx_exit(ctx);
758  return;
759  }
760 
761  flags.chunked = false;
762  if (newrep->sline.protocol == AnyP::PROTO_HTTP && newrep->header.chunked()) {
763  flags.chunked = true;
765  }
766 
769 
770  HttpReply *vrep = setVirginReply(newrep);
771  flags.headers_parsed = true;
772 
773  keepaliveAccounting(vrep);
774 
775  checkDateSkew(vrep);
776 
778 
780 
781  ctx_exit(ctx);
782 }
783 
785 void
787 {
788  HttpReply::Pointer msg(reply); // will destroy reply if unused
789 
790  // one 1xx at a time: we must not be called while waiting for previous 1xx
792  flags.handling1xx = true;
793 
795  debugs(11, 2, "ignoring 1xx because it is " << (request->forcedBodyContinuation ? "already sent" : "not supported by client"));
796  proceedAfter1xx();
797  return;
798  }
799 
800 #if USE_HTTP_VIOLATIONS
801  // check whether the 1xx response forwarding is allowed by squid.conf
802  if (Config.accessList.reply) {
804  ch.al = fwd->al;
805  ch.reply = reply;
806  ch.syncAle(originalRequest().getRaw(), nullptr);
807  HTTPMSGLOCK(ch.reply);
808  if (!ch.fastCheck().allowed()) { // TODO: support slow lookups?
809  debugs(11, 3, HERE << "ignoring denied 1xx");
810  proceedAfter1xx();
811  return;
812  }
813  }
814 #endif // USE_HTTP_VIOLATIONS
815 
816  debugs(11, 2, HERE << "forwarding 1xx to client");
817 
818  // the Sink will use this to call us back after writing 1xx to the client
819  typedef NullaryMemFunT<HttpStateData> CbDialer;
820  const AsyncCall::Pointer cb = JobCallback(11, 3, CbDialer, this,
824  // If the call is not fired, then the Sink is gone, and HttpStateData
825  // will terminate due to an aborted store entry or another similar error.
826  // If we get stuck, it is not handle1xx fault if we could get stuck
827  // for similar reasons without a 1xx response.
828 }
829 
831 void
833 {
835  debugs(11, 2, "continuing with " << payloadSeen << " bytes in buffer after 1xx");
837 }
838 
842 bool
844 {
845  if (!_peer)
846  return true;
847 
848  /*If this peer does not support connection pinning (authenticated
849  connections) return false
850  */
851  if (!_peer->connection_auth)
852  return false;
853 
854  const HttpReplyPointer rep(entry->mem_obj->getReply());
855 
856  /*The peer supports connection pinning and the http reply status
857  is not unauthorized, so the related connection can be pinned
858  */
859  if (rep->sline.status() != Http::scUnauthorized)
860  return true;
861 
862  /*The server respond with Http::scUnauthorized and the peer configured
863  with "connection-auth=on" we know that the peer supports pinned
864  connections
865  */
866  if (_peer->connection_auth == 1)
867  return true;
868 
869  /*At this point peer has configured with "connection-auth=auto"
870  parameter so we need some extra checks to decide if we are going
871  to allow pinned connections or not
872  */
873 
874  /*if the peer configured with originserver just allow connection
875  pinning (squid 2.6 behaviour)
876  */
878  return true;
879 
880  /*if the connections it is already pinned it is OK*/
881  if (request->flags.pinned)
882  return true;
883 
884  /*Allow pinned connections only if the Proxy-support header exists in
885  reply and has in its list the "Session-Based-Authentication"
886  which means that the peer supports connection pinning.
887  */
888  if (rep->header.hasListMember(Http::HdrType::PROXY_SUPPORT, "Session-Based-Authentication", ','))
889  return true;
890 
891  return false;
892 }
893 
894 // Called when we parsed (and possibly adapted) the headers but
895 // had not starting storing (a.k.a., sending) the body yet.
896 void
898 {
900 
901  Ctx ctx = ctx_enter(entry->mem_obj->urlXXX());
902  HttpReply *rep = finalReply();
903  const Http::StatusCode statusCode = rep->sline.status();
904 
905  entry->timestampsSet();
906 
907  /* Check if object is cacheable or not based on reply code */
908  debugs(11, 3, "HTTP CODE: " << statusCode);
909 
910  if (StoreEntry *oldEntry = findPreviouslyCachedEntry(entry)) {
911  oldEntry->lock("HttpStateData::haveParsedReplyHeaders");
912  sawDateGoBack = rep->olderThan(oldEntry->getReply());
913  oldEntry->unlock("HttpStateData::haveParsedReplyHeaders");
914  }
915 
917  httpMaybeRemovePublic(entry, rep->sline.status());
918 
919  bool varyFailure = false;
920  if (rep->header.has(Http::HdrType::VARY)
921 #if X_ACCELERATOR_VARY
922  || rep->header.has(Http::HdrType::HDR_X_ACCELERATOR_VARY)
923 #endif
924  ) {
925  const SBuf vary(httpMakeVaryMark(request.getRaw(), rep));
926 
927  if (vary.isEmpty()) {
928  // TODO: check whether such responses are shareable.
929  // Do not share for now.
930  entry->makePrivate(false);
931  if (!fwd->reforwardableStatus(rep->sline.status()))
933  varyFailure = true;
934  } else {
935  entry->mem_obj->vary_headers = vary;
936 
937  // RFC 7231 section 7.1.4
938  // Vary:* can be cached, but has mandatory revalidation
939  static const SBuf asterisk("*");
940  if (vary == asterisk)
942  }
943  }
944 
945  if (!varyFailure) {
946  /*
947  * If its not a reply that we will re-forward, then
948  * allow the client to get it.
949  */
950  if (!fwd->reforwardableStatus(rep->sline.status()))
952 
953  ReuseDecision decision(entry, statusCode);
954 
955  switch (reusableReply(decision)) {
956 
958  entry->makePrivate(false);
959  break;
960 
962  if (!entry->makePublic()) {
963  decision.make(ReuseDecision::doNotCacheButShare, "public key creation error");
964  entry->makePrivate(true);
965  }
966  break;
967 
969  if (!entry->cacheNegatively()) {
970  decision.make(ReuseDecision::doNotCacheButShare, "public key creation error");
971  entry->makePrivate(true);
972  }
973  break;
974 
976  entry->makePrivate(true);
977  break;
978 
979  default:
980  assert(0);
981  break;
982  }
983  debugs(11, 3, "decided: " << decision);
984  }
985 
986  if (!ignoreCacheControl) {
987  if (rep->cache_control) {
988  // We are required to revalidate on many conditions.
989  // For security reasons we do so even if storage was caused by refresh_pattern ignore-* option
990 
991  // CC:must-revalidate or CC:proxy-revalidate
992  const bool ccMustRevalidate = (rep->cache_control->hasProxyRevalidate() || rep->cache_control->hasMustRevalidate());
993 
994  // CC:no-cache (only if there are no parameters)
995  const bool ccNoCacheNoParams = rep->cache_control->hasNoCacheWithoutParameters();
996 
997  // CC:s-maxage=N
998  const bool ccSMaxAge = rep->cache_control->hasSMaxAge();
999 
1000  // CC:private (yes, these can sometimes be stored)
1001  const bool ccPrivate = rep->cache_control->hasPrivate();
1002 
1003  if (ccNoCacheNoParams || ccPrivate)
1005  else if (ccMustRevalidate || ccSMaxAge)
1007  }
1008 #if USE_HTTP_VIOLATIONS // response header Pragma::no-cache is undefined in HTTP
1009  else {
1010  // Expensive calculation. So only do it IF the CC: header is not present.
1011 
1012  /* HACK: Pragma: no-cache in _replies_ is not documented in HTTP,
1013  * but servers like "Active Imaging Webcast/2.0" sure do use it */
1014  if (rep->header.has(Http::HdrType::PRAGMA) &&
1015  rep->header.hasListMember(Http::HdrType::PRAGMA,"no-cache",','))
1017  }
1018 #endif
1019  }
1020 
1021 #if HEADERS_LOG
1022  headersLog(1, 0, request->method, rep);
1023 
1024 #endif
1025 
1026  ctx_exit(ctx);
1027 }
1028 
1031 {
1032  const HttpReply *rep = virginReply();
1036  static SBuf close("close", 5);
1037  if (httpHeaderHasConnDir(&rep->header, close))
1039 
1044  if (!flags.keepalive)
1046 
1051  if (!flags.request_sent) {
1052  debugs(11, 2, "Request not yet fully sent " << request->method << ' ' << entry->url());
1054  }
1055 
1068  if (!rep->keep_alive)
1070 
1071  return COMPLETE_PERSISTENT_MSG;
1072 }
1073 
1076 {
1077  debugs(11, 3, HERE << serverConnection << " eof=" << eof);
1078  if (eof) // already reached EOF
1080 
1081  /* If server fd is closing (but we have not been notified yet), stop Comm
1082  I/O to avoid assertions. TODO: Change Comm API to handle callers that
1083  want more I/O after async closing (usually initiated by others). */
1084  // XXX: add canReceive or s/canSend/canTalkToServer/
1087 
1093  if (lastChunk && flags.chunked)
1094  return statusIfComplete();
1095 
1096  const HttpReply *vrep = virginReply();
1097  debugs(11, 5, "persistentConnStatus: content_length=" << vrep->content_length);
1098 
1099  const int64_t clen = vrep->bodySize(request->method);
1100 
1101  debugs(11, 5, "persistentConnStatus: clen=" << clen);
1102 
1103  /* If the body size is unknown we must wait for EOF */
1104  if (clen < 0)
1105  return INCOMPLETE_MSG;
1106 
1109  if (clen > 0) {
1110  debugs(11,5, "payloadSeen=" << payloadSeen << " content_length=" << vrep->content_length);
1111 
1112  if (payloadSeen < vrep->content_length)
1113  return INCOMPLETE_MSG;
1114 
1115  if (payloadTruncated > 0) // already read more than needed
1116  return COMPLETE_NONPERSISTENT_MSG; // disable pconns
1117  }
1118 
1121  return statusIfComplete();
1122 }
1123 
1124 static void
1125 readDelayed(void *context, CommRead const &)
1126 {
1127  HttpStateData *state = static_cast<HttpStateData*>(context);
1128  state->flags.do_next_read = true;
1129  state->maybeReadVirginBody();
1130 }
1131 
1132 void
1134 {
1135  Must(!flags.do_next_read); // XXX: should have been set false by mayReadVirginBody()
1136  flags.do_next_read = false;
1137 
1138  debugs(11, 5, io.conn);
1139 
1140  // Bail out early on Comm::ERR_CLOSING - close handlers will tidy up for us
1141  if (io.flag == Comm::ERR_CLOSING) {
1142  debugs(11, 3, "http socket closing");
1143  return;
1144  }
1145 
1147  abortTransaction("store entry aborted while reading reply");
1148  return;
1149  }
1150 
1152  Must(io.conn->fd == serverConnection->fd);
1153 
1154  /*
1155  * Don't reset the timeout value here. The value should be
1156  * counting Config.Timeout.request and applies to the request
1157  * as a whole, not individual read() calls.
1158  * Plus, it breaks our lame *HalfClosed() detection
1159  */
1160 
1162  CommIoCbParams rd(this); // will be expanded with ReadNow results
1163  rd.conn = io.conn;
1165 
1166  if (rd.size <= 0) {
1167  assert(entry->mem_obj);
1168  AsyncCall::Pointer nilCall;
1169  entry->mem_obj->delayRead(DeferredRead(readDelayed, this, CommRead(io.conn, NULL, 0, nilCall)));
1170  return;
1171  }
1172 
1173  switch (Comm::ReadNow(rd, inBuf)) {
1174  case Comm::INPROGRESS:
1175  if (inBuf.isEmpty())
1176  debugs(33, 2, io.conn << ": no data to process, " << xstrerr(rd.xerrno));
1177  flags.do_next_read = true;
1179  return;
1180 
1181  case Comm::OK:
1182  {
1183  payloadSeen += rd.size;
1184 #if USE_DELAY_POOLS
1185  DelayId delayId = entry->mem_obj->mostBytesAllowed();
1186  delayId.bytesIn(rd.size);
1187 #endif
1188 
1189  statCounter.server.all.kbytes_in += rd.size;
1190  statCounter.server.http.kbytes_in += rd.size;
1191  ++ IOStats.Http.reads;
1192 
1193  int bin = 0;
1194  for (int clen = rd.size - 1; clen; ++bin)
1195  clen >>= 1;
1196 
1197  ++ IOStats.Http.read_hist[bin];
1198 
1200  }
1201 
1202  /* Continue to process previously read data */
1203  break;
1204 
1205  case Comm::ENDFILE: // close detected by 0-byte read
1206  eof = 1;
1207  flags.do_next_read = false;
1208 
1209  /* Continue to process previously read data */
1210  break;
1211 
1212  // case Comm::COMM_ERROR:
1213  default: // no other flags should ever occur
1214  debugs(11, 2, io.conn << ": read failure: " << xstrerr(rd.xerrno));
1216  err->xerrno = rd.xerrno;
1217  fwd->fail(err);
1218  flags.do_next_read = false;
1219  closeServer();
1220  mustStop("HttpStateData::readReply");
1221  return;
1222  }
1223 
1224  /* Process next response from buffer */
1225  processReply();
1226 }
1227 
1230 void
1232 {
1233 
1234  if (flags.handling1xx) { // we came back after handling a 1xx response
1235  debugs(11, 5, HERE << "done with 1xx handling");
1236  flags.handling1xx = false;
1238  }
1239 
1240  if (!flags.headers_parsed) { // have not parsed headers yet?
1241  PROF_start(HttpStateData_processReplyHeader);
1243  PROF_stop(HttpStateData_processReplyHeader);
1244 
1245  if (!continueAfterParsingHeader()) // parsing error or need more data
1246  return; // TODO: send errors to ICAP
1247 
1248  adaptOrFinalizeReply(); // may write to, abort, or "close" the entry
1249  }
1250 
1251  // kick more reads if needed and/or process the response body, if any
1252  PROF_start(HttpStateData_processReplyBody);
1253  processReplyBody(); // may call serverComplete()
1254  PROF_stop(HttpStateData_processReplyBody);
1255 }
1256 
1260 bool
1262 {
1263  if (flags.handling1xx) {
1264  debugs(11, 5, HERE << "wait for 1xx handling");
1266  return false;
1267  }
1268 
1269  if (!flags.headers_parsed && !eof) {
1270  debugs(11, 9, "needs more at " << inBuf.length());
1271  flags.do_next_read = true;
1275  maybeReadVirginBody(); // schedules all kinds of reads; TODO: rename
1276  return false;
1277  }
1278 
1282 
1283  if (flags.headers_parsed) { // parsed headers, possibly with errors
1284  // check for header parsing errors
1285  if (HttpReply *vrep = virginReply()) {
1286  const Http::StatusCode s = vrep->sline.status();
1287  const AnyP::ProtocolVersion &v = vrep->sline.version;
1288  if (s == Http::scInvalidHeader && v != Http::ProtocolVersion(0,9)) {
1289  debugs(11, DBG_IMPORTANT, "WARNING: HTTP: Invalid Response: Bad header encountered from " << entry->url() << " AKA " << request->url);
1290  error = ERR_INVALID_RESP;
1291  } else if (s == Http::scHeaderTooLarge) {
1292  fwd->dontRetry(true);
1293  error = ERR_TOO_BIG;
1294  } else if (vrep->header.conflictingContentLength()) {
1295  fwd->dontRetry(true);
1296  error = ERR_INVALID_RESP;
1297  } else {
1298  return true; // done parsing, got reply, and no error
1299  }
1300  } else {
1301  // parsed headers but got no reply
1302  debugs(11, DBG_IMPORTANT, "WARNING: HTTP: Invalid Response: No reply at all for " << entry->url() << " AKA " << request->url);
1303  error = ERR_INVALID_RESP;
1304  }
1305  } else {
1306  assert(eof);
1307  if (inBuf.length()) {
1308  error = ERR_INVALID_RESP;
1309  debugs(11, DBG_IMPORTANT, "WARNING: HTTP: Invalid Response: Headers did not parse at all for " << entry->url() << " AKA " << request->url);
1310  } else {
1311  error = ERR_ZERO_SIZE_OBJECT;
1312  debugs(11, (request->flags.accelerated?DBG_IMPORTANT:2), "WARNING: HTTP: Invalid Response: No object data received for " << entry->url() << " AKA " << request->url);
1313  }
1314  }
1315 
1316  assert(error != ERR_NONE);
1317  entry->reset();
1318  fwd->fail(new ErrorState(error, Http::scBadGateway, fwd->request));
1319  flags.do_next_read = false;
1320  closeServer();
1321  mustStop("HttpStateData::continueAfterParsingHeader");
1322  return false; // quit on error
1323 }
1324 
1327 void
1329 {
1331 
1332  HttpReply *vrep = virginReply();
1333  int64_t clen = -1;
1334  if (!vrep->expectingBody(request->method, clen) || clen < 0)
1335  return; // no body or a body of unknown size, including chunked
1336 
1337  if (payloadSeen - payloadTruncated <= clen)
1338  return; // we did not read too much or already took care of the extras
1339 
1340  if (const int64_t extras = payloadSeen - payloadTruncated - clen) {
1341  // server sent more that the advertised content length
1342  debugs(11, 5, "payloadSeen=" << payloadSeen <<
1343  " clen=" << clen << '/' << vrep->content_length <<
1344  " trucated=" << payloadTruncated << '+' << extras);
1345 
1346  inBuf.chop(0, inBuf.length() - extras);
1347  payloadTruncated += extras;
1348  }
1349 }
1350 
1355 void
1357 {
1358  truncateVirginBody(); // if needed
1359  const char *data = inBuf.rawContent();
1360  int len = inBuf.length();
1361  addVirginReplyBody(data, len);
1362  inBuf.consume(len);
1363 }
1364 
1365 bool
1367 {
1368  const char *data = NULL;
1369  int len;
1370  bool wasThereAnException = false;
1371  assert(flags.chunked);
1374  MemBuf decodedData;
1375  decodedData.init();
1376  httpChunkDecoder->setPayloadBuffer(&decodedData);
1377  const bool doneParsing = httpChunkDecoder->parse(inBuf);
1378  inBuf = httpChunkDecoder->remaining(); // sync buffers after parse
1379  len = decodedData.contentSize();
1380  data=decodedData.content();
1381  addVirginReplyBody(data, len);
1382  if (doneParsing) {
1383  lastChunk = 1;
1384  flags.do_next_read = false;
1385  }
1386  SQUID_EXIT_THROWING_CODE(wasThereAnException);
1387  return wasThereAnException;
1388 }
1389 
1397 void
1399 {
1400  if (!flags.headers_parsed) {
1401  flags.do_next_read = true;
1403  return;
1404  }
1405 
1406 #if USE_ADAPTATION
1407  debugs(11,5, HERE << "adaptationAccessCheckPending=" << adaptationAccessCheckPending);
1409  return;
1410 
1411 #endif
1412 
1413  /*
1414  * At this point the reply headers have been parsed and consumed.
1415  * That means header content has been removed from readBuf and
1416  * it contains only body data.
1417  */
1418  if (entry->isAccepting()) {
1419  if (flags.chunked) {
1420  if (!decodeAndWriteReplyBody()) {
1421  flags.do_next_read = false;
1422  serverComplete();
1423  return;
1424  }
1425  } else
1426  writeReplyBody();
1427  }
1428 
1429  // storing/sending methods like earlier adaptOrFinalizeReply() or
1430  // above writeReplyBody() may release/abort the store entry.
1432  // TODO: In some cases (e.g., 304), we should keep persistent conn open.
1433  // Detect end-of-reply (and, hence, pool our idle pconn) earlier (ASAP).
1434  abortTransaction("store entry aborted while storing reply");
1435  return;
1436  } else
1437  switch (persistentConnStatus()) {
1438  case INCOMPLETE_MSG: {
1439  debugs(11, 5, "processReplyBody: INCOMPLETE_MSG from " << serverConnection);
1440  /* Wait for more data or EOF condition */
1441  AsyncCall::Pointer nil;
1442  if (flags.keepalive_broken) {
1444  } else {
1446  }
1447 
1448  flags.do_next_read = true;
1449  }
1450  break;
1451 
1452  case COMPLETE_PERSISTENT_MSG: {
1453  debugs(11, 5, "processReplyBody: COMPLETE_PERSISTENT_MSG from " << serverConnection);
1454 
1455  // TODO: Remove serverConnectionSaved but preserve exception safety.
1456 
1458  flags.do_next_read = false;
1459 
1461  closeHandler = NULL;
1462 
1463  Ip::Address client_addr; // XXX: Remove as unused. Why was it added?
1465  client_addr = request->client_addr;
1466 
1467  auto serverConnectionSaved = serverConnection;
1469  serverConnection = nullptr;
1470 
1471  bool ispinned = false; // TODO: Rename to isOrShouldBePinned
1472  if (request->flags.pinned) {
1473  ispinned = true;
1474  } else if (request->flags.connectionAuth && request->flags.authSent) {
1475  ispinned = true;
1476  }
1477 
1478  if (ispinned) {
1481  ConnStateData,
1482  notePinnedConnectionBecameIdle,
1483  ConnStateData::PinnedIdleContext(serverConnectionSaved, request));
1484  } else {
1485  // must not pool/share ispinned connections, even orphaned ones
1486  serverConnectionSaved->close();
1487  }
1488  } else {
1489  fwd->pconnPush(serverConnectionSaved, request->url.host());
1490  }
1491 
1492  serverComplete();
1493  return;
1494  }
1495 
1497  debugs(11, 5, "processReplyBody: COMPLETE_NONPERSISTENT_MSG from " << serverConnection);
1498  serverComplete();
1499  return;
1500  }
1501 
1503 }
1504 
1505 bool
1507 {
1508  // TODO: Be more precise here. For example, if/when reading trailer, we may
1509  // not be doneWithServer() yet, but we should return false. Similarly, we
1510  // could still be writing the request body after receiving the whole reply.
1511  return !doneWithServer();
1512 }
1513 
1514 void
1516 {
1517  // too late to read
1519  return;
1520 
1521  if (!maybeMakeSpaceAvailable(false))
1522  return;
1523 
1524  // XXX: get rid of the do_next_read flag
1525  // check for the proper reasons preventing read(2)
1526  if (!flags.do_next_read)
1527  return;
1528 
1529  flags.do_next_read = false;
1530 
1531  // must not already be waiting for read(2) ...
1533 
1534  // wait for read(2) to be possible.
1536  AsyncCall::Pointer call = JobCallback(11, 5, Dialer, this, HttpStateData::readReply);
1538 }
1539 
1540 bool
1542 {
1543  // how much we are allowed to buffer
1544  const int limitBuffer = (flags.headers_parsed ? Config.readAheadGap : Config.maxReplyHeaderSize);
1545 
1546  if (limitBuffer < 0 || inBuf.length() >= (SBuf::size_type)limitBuffer) {
1547  // when buffer is at or over limit already
1548  debugs(11, 7, "will not read up to " << limitBuffer << ". buffer has (" << inBuf.length() << "/" << inBuf.spaceSize() << ") from " << serverConnection);
1549  debugs(11, DBG_DATA, "buffer has {" << inBuf << "}");
1550  // Process next response from buffer
1551  processReply();
1552  return false;
1553  }
1554 
1555  // how much we want to read
1556  const size_t read_size = calcBufferSpaceToReserve(inBuf.spaceSize(), (limitBuffer - inBuf.length()));
1557 
1558  if (!read_size) {
1559  debugs(11, 7, "will not read up to " << read_size << " into buffer (" << inBuf.length() << "/" << inBuf.spaceSize() << ") from " << serverConnection);
1560  return false;
1561  }
1562 
1563  // just report whether we could grow or not, do not actually do it
1564  if (doGrow)
1565  return (read_size >= 2);
1566 
1567  // we may need to grow the buffer
1568  inBuf.reserveSpace(read_size);
1569  debugs(11, 8, (!flags.do_next_read ? "will not" : "may") <<
1570  " read up to " << read_size << " bytes info buf(" << inBuf.length() << "/" << inBuf.spaceSize() <<
1571  ") from " << serverConnection);
1572 
1573  return (inBuf.spaceSize() >= 2); // only read if there is 1+ bytes of space available
1574 }
1575 
1577 void
1579 {
1580  debugs(11, 5, HERE << serverConnection << ": size " << io.size << ": errflag " << io.flag << ".");
1581 #if URL_CHECKSUM_DEBUG
1582 
1583  entry->mem_obj->checkUrlChecksum();
1584 #endif
1585 
1586  // XXX: Keep in sync with Client::sentRequestBody().
1587  // TODO: Extract common parts.
1588 
1589  if (io.size > 0) {
1590  fd_bytes(io.fd, io.size, FD_WRITE);
1591  statCounter.server.all.kbytes_out += io.size;
1592  statCounter.server.http.kbytes_out += io.size;
1593  }
1594 
1595  if (io.flag == Comm::ERR_CLOSING)
1596  return;
1597 
1598  // both successful and failed writes affect response times
1600 
1601  if (io.flag) {
1603  err->xerrno = io.xerrno;
1604  fwd->fail(err);
1605  closeServer();
1606  mustStop("HttpStateData::wroteLast");
1607  return;
1608  }
1609 
1610  sendComplete();
1611 }
1612 
1614 void
1616 {
1617  /*
1618  * Set the read timeout here because it hasn't been set yet.
1619  * We only set the read timeout after the request has been
1620  * fully written to the peer. If we start the timeout
1621  * after connection establishment, then we are likely to hit
1622  * the timeout for POST/PUT requests that have very large
1623  * request bodies.
1624  */
1626  AsyncCall::Pointer timeoutCall = JobCallback(11, 5,
1627  TimeoutDialer, this, HttpStateData::httpTimeout);
1628 
1630  flags.request_sent = true;
1631 }
1632 
1633 void
1635 {
1636  debugs(11,5, HERE << "closing HTTP server " << serverConnection << " this " << this);
1637 
1641  closeHandler = NULL;
1643  }
1644 }
1645 
1646 bool
1648 {
1650 }
1651 
1652 /*
1653  * Fixup authentication request headers for special cases
1654  */
1655 static void
1657 {
1659 
1660  /* Nothing to do unless we are forwarding to a peer */
1661  if (!request->flags.proxying)
1662  return;
1663 
1664  /* Needs to be explicitly enabled */
1665  if (!request->peer_login)
1666  return;
1667 
1668  /* Maybe already dealt with? */
1669  if (hdr_out->has(header))
1670  return;
1671 
1672  /* Nothing to do here for PASSTHRU */
1673  if (strcmp(request->peer_login, "PASSTHRU") == 0)
1674  return;
1675 
1676  /* PROXYPASS is a special case, single-signon to servers with the proxy password (basic only) */
1677  if (flags.originpeer && strcmp(request->peer_login, "PROXYPASS") == 0 && hdr_in->has(Http::HdrType::PROXY_AUTHORIZATION)) {
1678  const char *auth = hdr_in->getStr(Http::HdrType::PROXY_AUTHORIZATION);
1679 
1680  if (auth && strncasecmp(auth, "basic ", 6) == 0) {
1681  hdr_out->putStr(header, auth);
1682  return;
1683  }
1684  }
1685 
1686  char loginbuf[base64_encode_len(MAX_LOGIN_SZ)];
1687  size_t blen;
1688  struct base64_encode_ctx ctx;
1689  base64_encode_init(&ctx);
1690 
1691  /* Special mode to pass the username to the upstream cache */
1692  if (*request->peer_login == '*') {
1693  const char *username = "-";
1694 
1695  if (request->extacl_user.size())
1696  username = request->extacl_user.termedBuf();
1697 #if USE_AUTH
1698  else if (request->auth_user_request != NULL)
1699  username = request->auth_user_request->username();
1700 #endif
1701 
1702  blen = base64_encode_update(&ctx, loginbuf, strlen(username), reinterpret_cast<const uint8_t*>(username));
1703  blen += base64_encode_update(&ctx, loginbuf+blen, strlen(request->peer_login +1), reinterpret_cast<const uint8_t*>(request->peer_login +1));
1704  blen += base64_encode_final(&ctx, loginbuf+blen);
1705  httpHeaderPutStrf(hdr_out, header, "Basic %.*s", (int)blen, loginbuf);
1706  return;
1707  }
1708 
1709  /* external_acl provided credentials */
1710  if (request->extacl_user.size() && request->extacl_passwd.size() &&
1711  (strcmp(request->peer_login, "PASS") == 0 ||
1712  strcmp(request->peer_login, "PROXYPASS") == 0)) {
1713 
1714  blen = base64_encode_update(&ctx, loginbuf, request->extacl_user.size(), reinterpret_cast<const uint8_t*>(request->extacl_user.rawBuf()));
1715  blen += base64_encode_update(&ctx, loginbuf+blen, 1, reinterpret_cast<const uint8_t*>(":"));
1716  blen += base64_encode_update(&ctx, loginbuf+blen, request->extacl_passwd.size(), reinterpret_cast<const uint8_t*>(request->extacl_passwd.rawBuf()));
1717  blen += base64_encode_final(&ctx, loginbuf+blen);
1718  httpHeaderPutStrf(hdr_out, header, "Basic %.*s", (int)blen, loginbuf);
1719  return;
1720  }
1721  // if no external user credentials are available to fake authentication with PASS acts like PASSTHRU
1722  if (strcmp(request->peer_login, "PASS") == 0)
1723  return;
1724 
1725  /* Kerberos login to peer */
1726 #if HAVE_AUTH_MODULE_NEGOTIATE && HAVE_KRB5 && HAVE_GSSAPI
1727  if (strncmp(request->peer_login, "NEGOTIATE",strlen("NEGOTIATE")) == 0) {
1728  char *Token=NULL;
1729  char *PrincipalName=NULL,*p;
1730  int negotiate_flags = 0;
1731 
1732  if ((p=strchr(request->peer_login,':')) != NULL ) {
1733  PrincipalName=++p;
1734  }
1735  if (request->flags.auth_no_keytab) {
1736  negotiate_flags |= PEER_PROXY_NEGOTIATE_NOKEYTAB;
1737  }
1738  Token = peer_proxy_negotiate_auth(PrincipalName, request->peer_host, negotiate_flags);
1739  if (Token) {
1740  httpHeaderPutStrf(hdr_out, header, "Negotiate %s",Token);
1741  }
1742  return;
1743  }
1744 #endif /* HAVE_KRB5 && HAVE_GSSAPI */
1745 
1746  blen = base64_encode_update(&ctx, loginbuf, strlen(request->peer_login), reinterpret_cast<const uint8_t*>(request->peer_login));
1747  blen += base64_encode_final(&ctx, loginbuf+blen);
1748  httpHeaderPutStrf(hdr_out, header, "Basic %.*s", (int)blen, loginbuf);
1749  return;
1750 }
1751 
1752 /*
1753  * build request headers and append them to a given MemBuf
1754  * used by buildRequestPrefix()
1755  * note: initialised the HttpHeader, the caller is responsible for Clean()-ing
1756  */
1757 void
1759  StoreEntry * entry,
1760  const AccessLogEntryPointer &al,
1761  HttpHeader * hdr_out,
1762  const Http::StateFlags &flags)
1763 {
1764  /* building buffer for complex strings */
1765 #define BBUF_SZ (MAX_URL+32)
1766  LOCAL_ARRAY(char, bbuf, BBUF_SZ);
1767  LOCAL_ARRAY(char, ntoabuf, MAX_IPSTRLEN);
1768  const HttpHeader *hdr_in = &request->header;
1769  const HttpHeaderEntry *e = NULL;
1771  assert (hdr_out->owner == hoRequest);
1772 
1773  /* use our IMS header if the cached entry has Last-Modified time */
1774  if (request->lastmod > -1)
1775  hdr_out->putTime(Http::HdrType::IF_MODIFIED_SINCE, request->lastmod);
1776 
1777  // Add our own If-None-Match field if the cached entry has a strong ETag.
1778  // copyOneHeaderFromClientsideRequestToUpstreamRequest() adds client ones.
1779  if (request->etag.size() > 0) {
1781  request->etag.termedBuf()));
1782  }
1783 
1784  bool we_do_ranges = decideIfWeDoRanges (request);
1785 
1786  String strConnection (hdr_in->getList(Http::HdrType::CONNECTION));
1787 
1788  while ((e = hdr_in->getEntry(&pos)))
1789  copyOneHeaderFromClientsideRequestToUpstreamRequest(e, strConnection, request, hdr_out, we_do_ranges, flags);
1790 
1791  /* Abstraction break: We should interpret multipart/byterange responses
1792  * into offset-length data, and this works around our inability to do so.
1793  */
1794  if (!we_do_ranges && request->multipartRangeRequest()) {
1795  /* don't cache the result */
1796  request->flags.cachable = false;
1797  /* pretend it's not a range request */
1798  request->ignoreRange("want to request the whole object");
1799  request->flags.isRanged = false;
1800  }
1801 
1802  hdr_out->addVia(request->http_ver, hdr_in);
1803 
1804  if (request->flags.accelerated) {
1805  /* Append Surrogate-Capabilities */
1806  String strSurrogate(hdr_in->getList(Http::HdrType::SURROGATE_CAPABILITY));
1807 #if USE_SQUID_ESI
1808  snprintf(bbuf, BBUF_SZ, "%s=\"Surrogate/1.0 ESI/1.0\"", Config.Accel.surrogate_id);
1809 #else
1810  snprintf(bbuf, BBUF_SZ, "%s=\"Surrogate/1.0\"", Config.Accel.surrogate_id);
1811 #endif
1812  strListAdd(&strSurrogate, bbuf, ',');
1813  hdr_out->putStr(Http::HdrType::SURROGATE_CAPABILITY, strSurrogate.termedBuf());
1814  }
1815 
1817  if (strcmp(opt_forwarded_for, "delete") != 0) {
1818 
1819  String strFwd = hdr_in->getList(Http::HdrType::X_FORWARDED_FOR);
1820 
1821  // if we cannot double strFwd size, then it grew past 50% of the limit
1822  if (!strFwd.canGrowBy(strFwd.size())) {
1823  // There is probably a forwarding loop with Via detection disabled.
1824  // If we do nothing, String will assert on overflow soon.
1825  // TODO: Terminate all transactions with huge XFF?
1826  strFwd = "error";
1827 
1828  static int warnedCount = 0;
1829  if (warnedCount++ < 100) {
1830  const SBuf url(entry ? SBuf(entry->url()) : request->effectiveRequestUri());
1831  debugs(11, DBG_IMPORTANT, "Warning: likely forwarding loop with " << url);
1832  }
1833  }
1834 
1835  if (strcmp(opt_forwarded_for, "on") == 0) {
1837  if ( request->client_addr.isNoAddr() )
1838  strListAdd(&strFwd, "unknown", ',');
1839  else
1840  strListAdd(&strFwd, request->client_addr.toStr(ntoabuf, MAX_IPSTRLEN), ',');
1841  } else if (strcmp(opt_forwarded_for, "off") == 0) {
1843  strListAdd(&strFwd, "unknown", ',');
1844  } else if (strcmp(opt_forwarded_for, "transparent") == 0) {
1846  } else if (strcmp(opt_forwarded_for, "truncate") == 0) {
1848  if ( request->client_addr.isNoAddr() )
1849  strFwd = "unknown";
1850  else
1851  strFwd = request->client_addr.toStr(ntoabuf, MAX_IPSTRLEN);
1852  }
1853  if (strFwd.size() > 0)
1854  hdr_out->putStr(Http::HdrType::X_FORWARDED_FOR, strFwd.termedBuf());
1855  }
1858  /* append Host if not there already */
1859  if (!hdr_out->has(Http::HdrType::HOST)) {
1860  if (request->peer_domain) {
1861  hdr_out->putStr(Http::HdrType::HOST, request->peer_domain);
1862  } else {
1863  SBuf authority = request->url.authority();
1864  hdr_out->putStr(Http::HdrType::HOST, authority.c_str());
1865  }
1866  }
1867 
1868  /* append Authorization if known in URL, not in header and going direct */
1869  if (!hdr_out->has(Http::HdrType::AUTHORIZATION)) {
1870  if (!request->flags.proxying && !request->url.userInfo().isEmpty()) {
1871  static char result[base64_encode_len(MAX_URL*2)]; // should be big enough for a single URI segment
1872  struct base64_encode_ctx ctx;
1873  base64_encode_init(&ctx);
1874  size_t blen = base64_encode_update(&ctx, result, request->url.userInfo().length(), reinterpret_cast<const uint8_t*>(request->url.userInfo().rawContent()));
1875  blen += base64_encode_final(&ctx, result+blen);
1876  result[blen] = '\0';
1877  if (blen)
1878  httpHeaderPutStrf(hdr_out, Http::HdrType::AUTHORIZATION, "Basic %.*s", (int)blen, result);
1879  }
1880  }
1881 
1882  /* Fixup (Proxy-)Authorization special cases. Plain relaying dealt with above */
1883  httpFixupAuthentication(request, hdr_in, hdr_out, flags);
1884 
1885  /* append Cache-Control, add max-age if not there already */
1886  {
1887  HttpHdrCc *cc = hdr_in->getCc();
1888 
1889  if (!cc)
1890  cc = new HttpHdrCc();
1891 
1892 #if 0 /* see bug 2330 */
1893  /* Set no-cache if determined needed but not found */
1894  if (request->flags.nocache)
1896 #endif
1897 
1898  /* Add max-age only without no-cache */
1899  if (!cc->hasMaxAge() && !cc->hasNoCache()) {
1900  // XXX: performance regression. c_str() reallocates
1901  SBuf tmp(request->effectiveRequestUri());
1902  cc->maxAge(getMaxAge(entry ? entry->url() : tmp.c_str()));
1903  }
1904 
1905  /* Enforce sibling relations */
1906  if (flags.only_if_cached)
1907  cc->onlyIfCached(true);
1908 
1909  hdr_out->putCc(cc);
1910 
1911  delete cc;
1912  }
1913 
1914  /* maybe append Connection: keep-alive */
1915  if (flags.keepalive) {
1916  hdr_out->putStr(Http::HdrType::CONNECTION, "keep-alive");
1917  }
1918 
1919  /* append Front-End-Https */
1920  if (flags.front_end_https) {
1921  if (flags.front_end_https == 1 || request->url.getScheme() == AnyP::PROTO_HTTPS)
1922  hdr_out->putStr(Http::HdrType::FRONT_END_HTTPS, "On");
1923  }
1924 
1925  if (flags.chunked_request) {
1926  // Do not just copy the original value so that if the client-side
1927  // starts decode other encodings, this code may remain valid.
1928  hdr_out->putStr(Http::HdrType::TRANSFER_ENCODING, "chunked");
1929  }
1930 
1931  /* Now mangle the headers. */
1932  httpHdrMangleList(hdr_out, request, al, ROR_REQUEST);
1933 
1934  strConnection.clean();
1935 }
1936 
1941 void
1942 copyOneHeaderFromClientsideRequestToUpstreamRequest(const HttpHeaderEntry *e, const String strConnection, const HttpRequest * request, HttpHeader * hdr_out, const int we_do_ranges, const Http::StateFlags &flags)
1943 {
1944  debugs(11, 5, "httpBuildRequestHeader: " << e->name << ": " << e->value );
1945 
1946  switch (e->id) {
1947 
1955  if (!flags.originpeer && flags.proxying && request->peer_login &&
1956  (strcmp(request->peer_login, "PASS") == 0 ||
1957  strcmp(request->peer_login, "PROXYPASS") == 0 ||
1958  strcmp(request->peer_login, "PASSTHRU") == 0)) {
1959  hdr_out->addEntry(e->clone());
1960  }
1961  break;
1962 
1966  case Http::HdrType::TE:
1969  case Http::HdrType::TRAILER:
1970  case Http::HdrType::UPGRADE:
1972  break;
1973 
1980  if (!flags.originpeer) {
1981  hdr_out->addEntry(e->clone());
1982  } else {
1986  if (request->peer_login &&
1987  (strcmp(request->peer_login, "PASS") == 0 ||
1988  strcmp(request->peer_login, "PASSTHRU") == 0 ||
1989  strcmp(request->peer_login, "PROXYPASS") == 0)) {
1990  hdr_out->addEntry(e->clone());
1991  }
1992  }
1993 
1994  break;
1995 
1996  case Http::HdrType::HOST:
2003  if (request->peer_domain)
2004  hdr_out->putStr(Http::HdrType::HOST, request->peer_domain);
2005  else if (request->flags.redirected && !Config.onoff.redir_rewrites_host)
2006  hdr_out->addEntry(e->clone());
2007  else {
2008  SBuf authority = request->url.authority();
2009  hdr_out->putStr(Http::HdrType::HOST, authority.c_str());
2010  }
2011 
2012  break;
2013 
2022  // XXX: need to check and cleanup the auth case so cacheable auth requests get cached.
2023  if (hdr_out->has(Http::HdrType::IF_MODIFIED_SINCE))
2024  break;
2025  else if (Config.onoff.cache_miss_revalidate || !request->flags.cachable || request->flags.auth)
2026  hdr_out->addEntry(e->clone());
2027  break;
2028 
2037  // XXX: need to check and cleanup the auth case so cacheable auth requests get cached.
2038  if (hdr_out->hasListMember(Http::HdrType::IF_MATCH, "*", ',') || Config.onoff.cache_miss_revalidate || !request->flags.cachable || request->flags.auth)
2039  hdr_out->addEntry(e->clone());
2040  break;
2041 
2045  if (request->method == Http::METHOD_TRACE || request->method == Http::METHOD_OPTIONS) {
2046  const int64_t hops = e->getInt64();
2047 
2048  if (hops > 0)
2049  hdr_out->putInt64(Http::HdrType::MAX_FORWARDS, hops - 1);
2050  }
2051 
2052  break;
2053 
2054  case Http::HdrType::VIA:
2059  if (!Config.onoff.via)
2060  hdr_out->addEntry(e->clone());
2061 
2062  break;
2063 
2064  case Http::HdrType::RANGE:
2065 
2067 
2071  if (!we_do_ranges)
2072  hdr_out->addEntry(e->clone());
2073 
2074  break;
2075 
2076  case Http::HdrType::PROXY_CONNECTION: // SHOULD ignore. But doing so breaks things.
2077  break;
2078 
2080  // pass through unless we chunk; also, keeping this away from default
2081  // prevents request smuggling via Connection: Content-Length tricks
2082  if (!flags.chunked_request)
2083  hdr_out->addEntry(e->clone());
2084  break;
2085 
2087 
2092  break;
2093 
2097  if (!flags.front_end_https)
2098  hdr_out->addEntry(e->clone());
2099 
2100  break;
2101 
2102  default:
2106  if (strConnection.size()>0 && strListIsMember(&strConnection, e->name, ',')) {
2107  debugs(11, 2, "'" << e->name << "' header cropped by Connection: definition");
2108  return;
2109  }
2110 
2111  hdr_out->addEntry(e->clone());
2112  }
2113 }
2114 
2115 bool
2117 {
2118  bool result = true;
2119  /* decide if we want to do Ranges ourselves
2120  * and fetch the whole object now)
2121  * We want to handle Ranges ourselves iff
2122  * - we can actually parse client Range specs
2123  * - the specs are expected to be simple enough (e.g. no out-of-order ranges)
2124  * - reply will be cachable
2125  * (If the reply will be uncachable we have to throw it away after
2126  * serving this request, so it is better to forward ranges to
2127  * the server and fetch only the requested content)
2128  */
2129 
2130  int64_t roffLimit = request->getRangeOffsetLimit();
2131 
2132  if (NULL == request->range || !request->flags.cachable
2133  || request->range->offsetLimitExceeded(roffLimit) || request->flags.connectionAuth)
2134  result = false;
2135 
2136  debugs(11, 8, "decideIfWeDoRanges: range specs: " <<
2137  request->range << ", cachable: " <<
2138  request->flags.cachable << "; we_do_ranges: " << result);
2139 
2140  return result;
2141 }
2142 
2143 /* build request prefix and append it to a given MemBuf;
2144  * return the length of the prefix */
2145 mb_size_t
2147 {
2148  const int offset = mb->size;
2149  /* Uses a local httpver variable to print the HTTP label
2150  * since the HttpRequest may have an older version label.
2151  * XXX: This could create protocol bugs as the headers sent and
2152  * flow control should all be based on the HttpRequest version
2153  * not the one we are sending. Needs checking.
2154  */
2155  const AnyP::ProtocolVersion httpver = Http::ProtocolVersion();
2157  mb->appendf(SQUIDSBUFPH " " SQUIDSBUFPH " %s/%d.%d\r\n",
2159  SQUIDSBUFPRINT(url),
2161  httpver.major,httpver.minor);
2162  /* build and pack headers */
2163  {
2164  HttpHeader hdr(hoRequest);
2166 
2168  request->flags.authSent = true;
2169  else if (hdr.has(Http::HdrType::AUTHORIZATION))
2170  request->flags.authSent = true;
2171 
2172  hdr.packInto(mb);
2173  hdr.clean();
2174  }
2175  /* append header terminator */
2176  mb->append(crlf, 2);
2177  return mb->size - offset;
2178 }
2179 
2180 /* This will be called when connect completes. Write request. */
2181 bool
2183 {
2184  MemBuf mb;
2185 
2186  debugs(11, 5, HERE << serverConnection << ", request " << request << ", this " << this << ".");
2187 
2189  debugs(11,3, HERE << "cannot send request to closing " << serverConnection);
2190  assert(closeHandler != NULL);
2191  return false;
2192  }
2193 
2195  AsyncCall::Pointer timeoutCall = JobCallback(11, 5,
2196  TimeoutDialer, this, HttpStateData::httpTimeout);
2198  flags.do_next_read = true;
2200 
2201  if (request->body_pipe != NULL) {
2202  if (!startRequestBodyFlow()) // register to receive body data
2203  return false;
2205  requestSender = JobCallback(11,5,
2206  Dialer, this, HttpStateData::sentRequestBody);
2207 
2209  // use chunked encoding if we do not know the length
2210  if (request->content_length < 0)
2211  flags.chunked_request = true;
2212  } else {
2215  requestSender = JobCallback(11,5,
2216  Dialer, this, HttpStateData::wroteLast);
2217  }
2218 
2220  flags.proxying = (_peer != NULL && !flags.originpeer);
2221 
2222  /*
2223  * Is keep-alive okay for all request methods?
2224  */
2226  flags.keepalive = true;
2227  else if (request->flags.pinned)
2229  else if (!Config.onoff.server_pconns)
2230  flags.keepalive = false;
2231  else if (_peer == NULL)
2232  flags.keepalive = true;
2233  else if (_peer->stats.n_keepalives_sent < 10)
2234  flags.keepalive = true;
2235  else if ((double) _peer->stats.n_keepalives_recv /
2236  (double) _peer->stats.n_keepalives_sent > 0.50)
2237  flags.keepalive = true;
2238 
2239  if (_peer) {
2240  /*The old code here was
2241  if (neighborType(_peer, request->url) == PEER_SIBLING && ...
2242  which is equivalent to:
2243  if (neighborType(_peer, URL()) == PEER_SIBLING && ...
2244  or better:
2245  if (((_peer->type == PEER_MULTICAST && p->options.mcast_siblings) ||
2246  _peer->type == PEER_SIBLINGS ) && _peer->options.allow_miss)
2247  flags.only_if_cached = 1;
2248 
2249  But I suppose it was a bug
2250  */
2252  flags.only_if_cached = true;
2253 
2255  }
2256 
2257  mb.init();
2259  buildRequestPrefix(&mb);
2260 
2261  debugs(11, 2, "HTTP Server " << serverConnection);
2262  debugs(11, 2, "HTTP Server REQUEST:\n---------\n" << mb.buf << "\n----------");
2263 
2265  return true;
2266 }
2267 
2268 bool
2270 {
2271  // parent's implementation can handle the no-encoding case
2272  if (!flags.chunked_request)
2273  return Client::getMoreRequestBody(buf);
2274 
2275  MemBuf raw;
2276 
2278  if (!requestBodySource->getMoreData(raw))
2279  return false; // no request body bytes to chunk yet
2280 
2281  // optimization: pre-allocate buffer size that should be enough
2282  const mb_size_t rawDataSize = raw.contentSize();
2283  // we may need to send: hex-chunk-size CRLF raw-data CRLF last-chunk
2284  buf.init(16 + 2 + rawDataSize + 2 + 5, raw.max_capacity);
2285 
2286  buf.appendf("%x\r\n", static_cast<unsigned int>(rawDataSize));
2287  buf.append(raw.content(), rawDataSize);
2288  buf.append("\r\n", 2);
2289 
2290  Must(rawDataSize > 0); // we did not accidently created last-chunk above
2291 
2292  // Do not send last-chunk unless we successfully received everything
2295  flags.sentLastChunk = true;
2296  buf.append("0\r\n\r\n", 5);
2297  }
2298 
2299  return true;
2300 }
2301 
2302 void
2304 {
2305  debugs(11, 3, fwd->request->method << ' ' << fwd->entry->url());
2306  AsyncJob::Start(new HttpStateData(fwd));
2307 }
2308 
2309 void
2311 {
2312  if (!sendRequest()) {
2313  debugs(11, 3, "httpStart: aborted");
2314  mustStop("HttpStateData::start failed");
2315  return;
2316  }
2317 
2318  ++ statCounter.server.all.requests;
2319  ++ statCounter.server.http.requests;
2320 
2321  /*
2322  * We used to set the read timeout here, but not any more.
2323  * Now its set in httpSendComplete() after the full request,
2324  * including request body, has been written to the server.
2325  */
2326 }
2327 
2329 bool
2331 {
2332 #if USE_HTTP_VIOLATIONS
2333  if (!Config.accessList.brokenPosts) {
2334  debugs(11, 5, HERE << "No brokenPosts list");
2335  return false;
2336  }
2337 
2339  ch.al = fwd->al;
2340  ch.syncAle(originalRequest().getRaw(), nullptr);
2341  if (!ch.fastCheck().allowed()) {
2342  debugs(11, 5, HERE << "didn't match brokenPosts");
2343  return false;
2344  }
2345 
2347  debugs(11, 3, HERE << "ignoring broken POST for closed " << serverConnection);
2348  assert(closeHandler != NULL);
2349  return true; // prevent caller from proceeding as if nothing happened
2350  }
2351 
2352  debugs(11, 3, "finishingBrokenPost: fixing broken POST");
2354  requestSender = JobCallback(11,5,
2355  Dialer, this, HttpStateData::wroteLast);
2357  return true;
2358 #else
2359  return false;
2360 #endif /* USE_HTTP_VIOLATIONS */
2361 }
2362 
2364 bool
2366 {
2367  if (flags.sentLastChunk) {
2368  debugs(11, 5, HERE << "already sent last-chunk");
2369  return false;
2370  }
2371 
2372  Must(receivedWholeRequestBody); // or we should not be sending last-chunk
2373  flags.sentLastChunk = true;
2374 
2376  requestSender = JobCallback(11,5, Dialer, this, HttpStateData::wroteLast);
2377  Comm::Write(serverConnection, "0\r\n\r\n", 5, requestSender, NULL);
2378  return true;
2379 }
2380 
2381 void
2383 {
2385  debugs(11,5, HERE << serverConnection);
2386 
2387  // do we need to write something after the last body byte?
2389  return;
2391  return;
2392 
2393  sendComplete();
2394 }
2395 
2396 // more origin request body data is available
2397 void
2399 {
2401  // XXX: we should check this condition in other callbacks then!
2402  // TODO: Check whether this can actually happen: We should unsubscribe
2403  // as a body consumer when the above condition(s) are detected.
2404  debugs(11, DBG_IMPORTANT, HERE << "Transaction aborted while reading HTTP body");
2405  return;
2406  }
2407 
2409 
2410  if (requestBodySource->buf().hasContent()) {
2411  // XXX: why does not this trigger a debug message on every request?
2412 
2414  flags.abuse_detected = true;
2415  debugs(11, DBG_IMPORTANT, "http handleMoreRequestBodyAvailable: Likely proxy abuse detected '" << request->client_addr << "' -> '" << entry->url() << "'" );
2416 
2418  closeServer();
2419  mustStop("HttpStateData::handleMoreRequestBodyAvailable");
2420  return;
2421  }
2422  }
2423  }
2424 
2426 }
2427 
2428 // premature end of the request body
2429 void
2431 {
2433  if (entry->isEmpty()) {
2434  debugs(11, 3, "request body aborted: " << serverConnection);
2435  // We usually get here when ICAP REQMOD aborts during body processing.
2436  // We might also get here if client-side aborts, but then our response
2437  // should not matter because either client-side will provide its own or
2438  // there will be no response at all (e.g., if the the client has left).
2441  fwd->fail(err);
2442  }
2443 
2444  abortTransaction("request body producer aborted");
2445 }
2446 
2447 // called when we wrote request headers(!) or a part of the body
2448 void
2450 {
2451  if (io.size > 0)
2452  statCounter.server.http.kbytes_out += io.size;
2453 
2455 }
2456 
2457 void
2458 HttpStateData::abortAll(const char *reason)
2459 {
2460  debugs(11,5, HERE << "aborting transaction for " << reason <<
2461  "; " << serverConnection << ", this " << this);
2462  mustStop(reason);
2463 }
2464 
2466  : answer(HttpStateData::ReuseDecision::reuseNot), reason(nullptr), entry(e), statusCode(code) {}
2467 
2470 {
2471  answer = ans;
2472  reason = why;
2473  return answer;
2474 }
2475 
2476 std::ostream &operator <<(std::ostream &os, const HttpStateData::ReuseDecision &d)
2477 {
2478  static const char *ReuseMessages[] = {
2479  "do not cache and do not share", // reuseNot
2480  "cache positively and share", // cachePositively
2481  "cache negatively and share", // cacheNegatively
2482  "do not cache but share" // doNotCacheButShare
2483  };
2484 
2487  return os << ReuseMessages[d.answer] << " because " << d.reason <<
2488  "; HTTP status " << d.statusCode << " " << *(d.entry);
2489 }
2490 
#define MAX_LOGIN_SZ
Definition: defines.h:119
virtual void haveParsedReplyHeaders()
called when we have final (possibly adapted) reply headers; kids extend
Definition: http.cc:897
HierarchyLogEntry hier
Definition: HttpRequest.h:145
void maxStale(int v)
AnyP::ProtocolVersion ProtocolVersion(unsigned int aMajor, unsigned int aMinor)
HTTP version label information.
void reserveSpace(size_type minSpace)
Definition: SBuf.h:429
int has(Http::HdrType id) const
Definition: HttpHeader.cc:1002
short int keep_alive
Definition: HttpReply.h:57
assists in making and relaying entry caching/sharing decision
Definition: http.h:28
#define JobCallback(dbgSection, dbgLevel, Dialer, job, method)
Convenience macro to create a Dialer-based job callback.
Definition: AsyncJobCalls.h:68
bool continueAfterParsingHeader()
Definition: http.cc:1261
virtual bool isAccepting() const
Definition: store.cc:2050
bool hasNoStore() const
int strListGetItem(const String *str, char del, const char **item, int *ilen, const char **pos)
Definition: StrList.cc:77
#define fd_table
Definition: fde.h:157
struct StatCounters::@130::@139 all
HttpHdrRange * range
Definition: HttpRequest.h:131
StatCounters statCounter
Definition: StatCounters.cc:12
void makePrivate(const bool shareable)
Definition: store.cc:150
#define assert(EX)
Definition: assert.h:17
bool peerSupportsConnectionPinning() const
Definition: http.cc:843
bool finishingChunkedRequest()
if needed, write last-chunk to end the request body and return true
Definition: http.cc:2365
void processReply()
Definition: http.cc:1231
int neighbors_do_private_keys
#define CallJobHere(debugSection, debugLevel, job, Class, method)
Definition: AsyncJobCalls.h:57
#define HttpHeaderInitPos
Definition: HttpHeader.h:48
#define cbdataReferenceDone(var)
Definition: cbdata.h:350
virtual const Comm::ConnectionPointer & dataConnection() const
Definition: http.cc:141
virtual void append(const char *c, int sz)
Definition: MemBuf.cc:216
int cache_miss_revalidate
Definition: SquidConfig.h:319
static void assembleVaryKey(String &vary, SBuf &vstr, const HttpRequest &request)
assemble a variant key (vary-mark) from the given Vary header and HTTP request
Definition: http.cc:570
HttpHdrCc * getCc() const
Definition: HttpHeader.cc:1234
Comm::Flag ReadNow(CommIoCbParams &params, SBuf &buf)
Definition: Read.cc:80
https_port or bumped http_port tunnel; HTTPS server
Definition: Message.h:32
a representation of a refresh pattern.
HttpHdrCc * cache_control
Definition: Message.h:76
virtual void release(const bool shareable=false)
Definition: store.cc:1197
void pconnPush(Comm::ConnectionPointer &conn, const char *domain)
Definition: FwdState.cc:1209
acl_access * brokenPosts
Definition: SquidConfig.h:371
void set(const AnyP::ProtocolVersion &newVersion, Http::StatusCode newStatus, const char *newReason=NULL)
Definition: StatusLine.cc:30
bool startRequestBodyFlow()
Definition: Client.cc:216
virtual void sentRequestBody(const CommIoCbParams &io)
Definition: http.cc:2449
size_t calcBufferSpaceToReserve(const size_t space, const size_t wantSpace) const
determine how much space the buffer needs to reserve
Definition: Client.cc:1003
void adaptOrFinalizeReply()
Definition: Client.cc:945
time_t getMaxAge(const char *url)
Definition: refresh.cc:646
static void copyOneHeaderFromClientsideRequestToUpstreamRequest(const HttpHeaderEntry *e, const String strConnection, const HttpRequest *request, HttpHeader *hdr_out, const int we_do_ranges, const Http::StateFlags &)
Definition: http.cc:1942
int64_t payloadSeen
amount of message payload/body received so far.
Definition: http.h:146
static void httpFixupAuthentication(HttpRequest *request, const HttpHeader *hdr_in, HttpHeader *hdr_out, const Http::StateFlags &flags)
Definition: http.cc:1656
void mustStop(const char *aReason)
Definition: AsyncJob.cc:69
bool timestampsSet()
Definition: store.cc:1462
Definition: SBuf.h:86
virtual bool getMoreRequestBody(MemBuf &buf)
either fill buf with available [encoded] request body bytes or return false
Definition: Client.cc:415
struct SquidConfig::@113 onoff
bool canHandle1xx() const
whether the client is likely to be able to handle a 1xx reply
Definition: HttpRequest.cc:642
virtual bool mayReadVirginReplyBody() const
whether we may receive more virgin response body bytes
Definition: http.cc:1506
struct StatCounters::@130 server
const HttpReply * virginReply() const
Definition: Client.cc:111
HttpRequestMethod method
Definition: HttpRequest.h:102
bool isNoAddr() const
Definition: Address.cc:277
void serverComplete()
Definition: Client.cc:157
const MemBuf & buf() const
Definition: BodyPipe.h:137
struct _request * request(char *urlin)
Definition: tcp-banger2.c:291
void error(char *format,...)
acl_access * reply
Definition: SquidConfig.h:375
StoreEntry * entry
Definition: Client.h:164
SBuf & append(const SBuf &S)
Definition: SBuf.cc:195
Definition: Client.h:29
int n_keepalives_recv
Definition: CachePeer.h:53
struct CachePeer::@29 stats
static const char *const crlf
Definition: http.cc:80
void ctx_exit(Ctx ctx)
Definition: debug.cc:727
int64_t bodySize(const HttpRequestMethod &) const
Definition: HttpReply.cc:361
Definition: Flag.h:16
bool forcedBodyContinuation
whether we have responded with HTTP 100 or FTP 150 already
Definition: HttpRequest.h:183
AccessLogEntry::Pointer al
info for the future access.log, and external ACL
Definition: Range.h:18
SBuf & chop(size_type pos, size_type n=npos)
Definition: SBuf.cc:540
http_port or HTTP server
Definition: Message.h:38
void removeStaleWarnings()
Remove Warnings with warn-date different from Date value.
Definition: HttpReply.cc:571
void HTTPMSGLOCK(Http::Message *a)
Definition: Message.h:154
bool persistent() const
Definition: Message.cc:257
HttpRequest * request
Definition: FwdState.h:138
ReuseDecision(const StoreEntry *e, const Http::StatusCode code)
Definition: http.cc:2465
#define Must(condition)
Like assert() but throws an exception instead of aborting the process.
Definition: TextException.h:69
HttpHeaderEntry * getEntry(HttpHeaderPos *pos) const
Definition: HttpHeader.cc:589
Definition: enums.h:24
StoreEntry * storeGetPublicByRequestMethod(HttpRequest *req, const HttpRequestMethod &method, const KeyScope keyScope)
Definition: store.cc:540
void strListAdd(String *str, const char *item, char del)
Definition: StrList.cc:19
int64_t getInt64() const
Definition: HttpHeader.cc:1538
AnyP::ProtocolVersion http_ver
Definition: Message.h:72
struct StatCounters::@130::@139 http
#define REFRESH_OVERRIDE(flag)
bool isEmpty() const
Definition: SBuf.h:420
virtual void abortAll(const char *reason)
abnormal transaction termination; reason is for debugging only
Definition: http.cc:2458
char * p
Definition: membanger.c:43
int server_pconns
Definition: SquidConfig.h:303
String getByName(const SBuf &name) const
Definition: HttpHeader.cc:879
int strListIsMember(const String *list, const SBuf &m, char del)
Definition: StrList.cc:37
HttpHdrScTarget * getMergedTarget(const char *ourtarget)
Definition: HttpHdrSc.cc:334
static void httpBuildRequestHeader(HttpRequest *request, StoreEntry *entry, const AccessLogEntryPointer &al, HttpHeader *hdr_out, const Http::StateFlags &flags)
Definition: http.cc:1758
bool hasPublic() const
Definition: HttpHdrCc.h:69
size_type size() const
Definition: SquidString.h:72
bool keepalive_broken
Definition: StateFlags.h:25
StoreEntry * storeGetPublic(const char *uri, const HttpRequestMethod &method)
Definition: store.cc:534
SBuf httpMakeVaryMark(HttpRequest *request, HttpReply const *reply)
Definition: http.cc:606
time_t squid_curtime
Definition: stub_time.cc:17
void writeReplyBody()
Definition: http.cc:1356
void host(const char *src)
Definition: url.cc:47
bool canGrowBy(const size_type growthLen) const
whether appending growthLen characters is safe (i.e., unlikely to assert)
Definition: SquidString.h:123
bool connectionAuth
Definition: RequestFlags.h:78
int32_t mask
Definition: HttpHdrCc.h:173
const StoreEntry * entry
entry for debugging
Definition: http.h:39
void userInfo(const SBuf &s)
Definition: URL.h:66
CachePeer * _peer
Definition: http.h:63
void init(mb_size_t szInit, mb_size_t szMax)
Definition: MemBuf.cc:96
bool offsetLimitExceeded(const int64_t limit) const
void Read(const Comm::ConnectionPointer &conn, AsyncCall::Pointer &callback)
Definition: Read.cc:39
bool sentLastChunk
do not try to write last-chunk again
Definition: StateFlags.h:31
bool httpHeaderHasConnDir(const HttpHeader *hdr, const SBuf &directive)
void maxAge(int32_t v)
Definition: HttpHdrCc.h:123
AsyncCall::Pointer closeHandler
Definition: http.h:86
void fd_bytes(int fd, int len, unsigned int type)
Definition: fd.cc:261
Http::HdrType id
Definition: HttpHeader.h:63
void handle1xx(HttpReply *msg)
ignore or start forwarding the 1xx response (a.k.a., control message)
Definition: http.cc:786
bool chunked
reading a chunked response; TODO: rename
Definition: StateFlags.h:29
static Pointer Start(AsyncJob *job)
starts a freshly created job (i.e., makes the job asynchronous)
Definition: AsyncJob.cc:23
void httpHeaderPutStrf(HttpHeader *hdr, Http::HdrType id, const char *fmt,...)
parameters for the async notePinnedConnectionBecameIdle() call
Definition: client_side.h:167
int read_hist[histSize]
Definition: IoStats.h:21
time_t lifetime
Definition: SquidConfig.h:104
void toLower()
converts all characters to lower case;
Definition: SBuf.cc:821
virtual void maybeReadVirginBody()
read response data from the network
Definition: http.cc:1515
Comm::ConnectionPointer conn
Definition: CommCalls.h:85
const char * xstrerr(int error)
Definition: xstrerror.cc:83
bool IsConnOpen(const Comm::ConnectionPointer &conn)
Definition: Connection.cc:24
AsyncCall::Pointer requestSender
Definition: Client.h:170
bool hasMustRevalidate() const
Definition: HttpHdrCc.h:112
unsigned int major
major version number
void const char HLPCB void * data
Definition: stub_helper.cc:16
void delayRead(DeferredRead const &)
Definition: MemObject.cc:439
size_type length() const
Returns the number of bytes stored in SBuf.
Definition: SBuf.h:404
int commUnsetConnTimeout(const Comm::ConnectionPointer &conn)
Definition: comm.cc:578
StatusCode
Definition: StatusCode.h:20
int64_t readAheadGap
Definition: SquidConfig.h:88
bool hasContent() const
Definition: MemBuf.h:54
int fd
FD which the call was about. Set by the async call creator.
Definition: CommCalls.h:90
String extacl_passwd
Definition: HttpRequest.h:169
int64_t content_length
Definition: Message.h:83
Http1::TeChunkedParser * httpChunkDecoder
Definition: http.h:143
struct SquidConfig::@106 Accel
virtual bool expectingBody(const HttpRequestMethod &, int64_t &) const
Definition: HttpReply.cc:461
virtual void sendControlMsg(HttpControlMsg)
called to send the 1xx message and notify the Source
#define debugs(SECTION, LEVEL, CONTENT)
Definition: Debug.h:124
const char * storeId() const
Definition: MemObject.cc:54
#define cbdataReference(var)
Definition: cbdata.h:341
HttpRequestMethod method
Definition: MemObject.h:102
#define DBG_IMPORTANT
Definition: Debug.h:46
virtual void haveParsedReplyHeaders()
called when we have final (possibly adapted) reply headers; kids extend
Definition: Client.cc:507
char const * rawBuf() const
Definition: SquidString.h:85
FwdState::Pointer fwd
Definition: Client.h:165
int eof
Definition: http.h:64
bool hasNoCache(const String **val=nullptr) const
Definition: HttpHdrCc.h:89
void processSurrogateControl(HttpReply *)
Definition: http.cc:277
virtual bool doneWithServer() const
Definition: http.cc:1647
SBuf & authority(bool requirePort=false) const
Definition: url.cc:470
int redir_rewrites_host
Definition: SquidConfig.h:295
bool auth_no_keytab
Definition: RequestFlags.h:30
Http1::ResponseParserPointer hp
Parser being used at present to parse the HTTP/ICY server response.
Definition: http.h:142
virtual void handleRequestBodyProducerAborted()=0
Definition: Client.cc:328
bool connectionAuthDisabled
Definition: RequestFlags.h:80
void checkDateSkew(HttpReply *)
Definition: http.cc:645
int lastChunk
Definition: http.h:65
Ip::Address client_addr
Definition: HttpRequest.h:137
#define EBIT_CLR(flag, bit)
Definition: defines.h:106
virtual void sentRequestBody(const CommIoCbParams &io)=0
Definition: Client.cc:341
void putTime(Http::HdrType id, time_t htime)
Definition: HttpHeader.cc:1054
char * surrogate_id
Definition: SquidConfig.h:209
mb_size_t size
Definition: MemBuf.h:135
AnyP::UriScheme const & getScheme() const
Definition: URL.h:58
int xerrno
The last errno to occur. non-zero if flag is Comm::COMM_ERROR.
Definition: CommCalls.h:88
BodyPipe::Pointer requestBodySource
Definition: Client.h:169
virtual HttpRequestPointer originalRequest()
a hack to reach HttpStateData::orignal_request
Definition: Client.cc:536
char const * termedBuf() const
Definition: SquidString.h:91
char * peer_host
Definition: HttpRequest.h:154
bool MonitorsRead(int fd)
whether the FD socket is being monitored for read
Definition: Read.cc:28
String getList(Http::HdrType id) const
Definition: HttpHeader.cc:819
Cbc * valid() const
was set and is valid
Definition: CbcPointer.h:41
const SBuf & effectiveRequestUri() const
RFC 7230 section 5.5 - Effective Request URI.
Definition: HttpRequest.cc:673
bool mustKeepalive
Definition: RequestFlags.h:76
bundles HTTP 1xx reply and the "successfully forwarded" callback
ConnectionStatus statusIfComplete() const
Definition: http.cc:1030
http_hdr_owner_type owner
Definition: HttpHeader.h:158
CbcPointer< ConnStateData > clientConnectionManager
Definition: HttpRequest.h:218
void httpStateConnClosed(const CommCloseCbParams &params)
Definition: http.cc:147
bool allowed() const
Definition: Acl.h:141
bool allow_miss
Definition: CachePeer.h:104
size_t maxReplyHeaderSize
Definition: SquidConfig.h:127
bool ignoreCacheControl
Definition: http.h:69
void sendComplete()
successfully wrote the entire request (including body, last-chunk, etc.)
Definition: http.cc:1615
void releaseRequest(const bool shareable=false)
Definition: store.cc:448
void base64_encode_init(struct base64_encode_ctx *ctx)
Definition: base64.c:232
const char * c_str()
Definition: SBuf.cc:526
bool reforwardableStatus(const Http::StatusCode s) const
Definition: FwdState.cc:1177
uint16_t flags
Definition: Store.h:206
#define CallJobHere1(debugSection, debugLevel, job, Class, method, arg1)
Definition: AsyncJobCalls.h:62
void setNoDelay(bool const)
Definition: store.cc:251
Http::StatusLine sline
Definition: HttpReply.h:60
unsigned int front_end_https
send "Front-End-Https: On" header (off/on/auto=2)
Definition: StateFlags.h:18
static void readDelayed(void *context, CommRead const &)
Definition: http.cc:1125
MemObject * mem_obj
Definition: Store.h:195
SBuf consume(size_type n=npos)
Definition: SBuf.cc:491
time_t date
Definition: HttpReply.h:44
Ctx ctx_enter(const char *descr)
Definition: debug.cc:711
URL url
the request URI
Definition: HttpRequest.h:103
#define LOCAL_ARRAY(type, name, size)
Definition: leakcheck.h:18
DelayId mostBytesAllowed() const
Definition: MemObject.cc:460
int hasListMember(Http::HdrType id, const char *member, const char separator) const
Definition: HttpHeader.cc:1665
bool hasPrivate(const String **val=nullptr) const
Definition: HttpHdrCc.h:74
void path(const char *p)
Definition: URL.h:77
AnyP::ProtocolType protocol
Definition: StatusLine.h:68
HttpHdrSc * surrogate_control
Definition: HttpReply.h:52
int connection_auth
0 - off, 1 - on, 2 - auto
Definition: CachePeer.h:196
void addVirginReplyBody(const char *buf, ssize_t len)
Definition: Client.cc:978
void httpTimeout(const CommTimeoutCbParams &params)
Definition: http.cc:155
Comm::ConnectionPointer const & serverConnection() const
Definition: FwdState.h:107
bool hasMaxAge() const
int unsigned int const char *desc STUB void int len
Definition: stub_fd.cc:20
char * content()
start of the added data
Definition: MemBuf.h:41
const char * url() const
Definition: store.cc:1608
bool surrogateNoStore
Definition: http.h:70
CachePeer * getPeer() const
Definition: Connection.cc:98
void ignoreRange(const char *reason)
forgets about the cached Range header (for a reason)
Definition: HttpRequest.cc:628
void addVia(const AnyP::ProtocolVersion &ver, const HttpHeader *from=0)
Definition: HttpHeader.cc:1010
struct SquidConfig::@99 Timeout
static void httpMaybeRemovePublic(StoreEntry *, Http::StatusCode)
Definition: http.cc:178
virtual void start()
called by AsyncStart; do not call directly
Definition: http.cc:2310
unsigned char code
Definition: html_quote.c:20
void const char * buf
Definition: stub_helper.cc:16
void keepaliveAccounting(HttpReply *)
Definition: http.cc:625
int n_keepalives_sent
Definition: CachePeer.h:52
std::ostream & HERE(std::ostream &s)
Definition: Debug.h:153
ssize_t HttpHeaderPos
Definition: HttpHeader.h:45
time_t negativeTtl
Definition: SquidConfig.h:92
size_t getMoreData(MemBuf &buf)
Definition: BodyPipe.cc:295
ConnectionStatus persistentConnStatus() const
Definition: http.cc:1075
int reads
Definition: IoStats.h:19
int front_end_https
0 - off, 1 - on, 2 - auto
Definition: CachePeer.h:195
mb_size_t contentSize() const
available data size
Definition: MemBuf.h:47
SBuf inBuf
I/O buffer for receiving server responses.
Definition: http.h:68
HttpHeader header
Definition: Message.h:74
virtual bool parse(const SBuf &)
bool makePublic(const KeyScope keyScope=ksDefault)
Definition: store.cc:143
virtual void doneSendingRequestBody()=0
Definition: Client.cc:317
bool accelerated
Definition: RequestFlags.h:60
bool sendRequest()
Definition: http.cc:2182
SBuf vary_headers
Definition: MemObject.h:180
size_t base64_encode_final(struct base64_encode_ctx *ctx, char *dst)
Definition: base64.c:308
Http::StateFlags flags
Definition: http.h:66
void putInt64(Http::HdrType id, int64_t number)
Definition: HttpHeader.cc:1045
char * buf
Definition: MemBuf.h:134
AccessLogEntryPointer al
info for the future access.log entry
Definition: FwdState.h:139
void httpStart(FwdState *fwd)
Definition: http.cc:2303
virtual const char * getMD5Text() const
Definition: store.cc:183
RequestFlags flags
Definition: HttpRequest.h:129
#define EBIT_SET(flag, bit)
Definition: defines.h:105
bool sawDateGoBack
Definition: http.h:152
const SBuf & image() const
void maxAge(int v)
store_status_t store_status
Definition: Store.h:218
mb_size_t buildRequestPrefix(MemBuf *mb)
Definition: http.cc:2146
prohibits making the key public
Definition: enums.h:79
void neighborsHtcpClear(StoreEntry *e, const char *uri, HttpRequest *req, const HttpRequestMethod &method, htcp_clr_reason reason)
Definition: neighbors.cc:1795
Answers answer
the decision id
Definition: http.h:37
void processReplyBody()
Definition: http.cc:1398
allow_t const & fastCheck()
Definition: Checklist.cc:336
void putStr(Http::HdrType id, const char *str)
Definition: HttpHeader.cc:1063
bool hasMaxAge(int32_t *val=nullptr) const
Definition: HttpHdrCc.h:122
bool hasNoCacheWithParameters() const
Definition: HttpHdrCc.h:87
void clean()
Definition: HttpHeader.cc:184
bool hasNoCacheWithoutParameters() const
Definition: HttpHdrCc.h:88
bool cacheNegatively()
Definition: store.cc:164
#define BBUF_SZ
HttpRequestPointer request
Definition: Client.h:166
void setPayloadBuffer(MemBuf *parsedContent)
set the buffer to be used to store decoded chunk data
void onlyIfCached(bool v)
Definition: HttpHdrCc.h:146
Comm::ConnectionPointer serverConnection
Definition: http.h:85
int detect_broken_server_pconns
Definition: SquidConfig.h:313
mb_size_t max_capacity
Definition: MemBuf.h:142
int64_t getRangeOffsetLimit()
Definition: HttpRequest.cc:601
#define PROF_start(probename)
Definition: Profiler.h:62
peer_t neighborType(const CachePeer *p, const URL &url)
Definition: neighbors.cc:114
void putCc(const HttpHdrCc *cc)
Definition: HttpHeader.cc:1079
bool no_delay
Definition: CachePeer.h:102
int64_t payloadTruncated
positive when we read more than we wanted
Definition: http.h:148
char * opt_forwarded_for
bool dontRetry()
Definition: FwdState.h:102
#define CBDATA_CLASS_INIT(type)
Definition: cbdata.h:318
size_t base64_encode_update(struct base64_encode_ctx *ctx, char *dst, size_t length, const uint8_t *src)
Definition: base64.c:265
HttpReply * setVirginReply(HttpReply *r)
Definition: Client.cc:118
char const * username() const
Definition: UserRequest.cc:32
Comm::Flag flag
comm layer result status.
Definition: CommCalls.h:87
struct SquidConfig::@114 accessList
String extacl_user
Definition: HttpRequest.h:167
bool handling1xx
we are ignoring or forwarding 1xx response
Definition: StateFlags.h:22
void appendf(const char *fmt,...) PRINTF_FORMAT_ARG2
Append operation with printf-style arguments.
Definition: Packable.h:61
void processReplyHeader()
Definition: http.cc:662
ssize_t mb_size_t
Definition: MemBuf.h:17
bool chunked() const
whether message uses chunked Transfer-Encoding
Definition: HttpHeader.h:188
virtual void handleMoreRequestBodyAvailable()
Definition: http.cc:2398
bool receivedWholeRequestBody
handleRequestBodyProductionEnded called
Definition: Client.h:180
Definition: MemBuf.h:23
Auth::UserRequest::Pointer auth_user_request
Definition: HttpRequest.h:115
struct CachePeer::@31 options
void abortTransaction(const char *reason)
Definition: http.h:108
void packInto(Packable *p, bool mask_sensitive_info=false) const
Definition: HttpHeader.cc:545
bool decodeAndWriteReplyBody()
Definition: http.cc:1366
void fail(ErrorState *err)
Definition: FwdState.cc:461
virtual void closeServer()
Definition: http.cc:1634
BodyPipe::Pointer body_pipe
optional pipeline to receive message body
Definition: Message.h:97
const char * ProtocolType_str[]
ReuseDecision::Answers reusableReply(ReuseDecision &decision)
Definition: http.cc:315
bool adaptationAccessCheckPending
Definition: Client.h:177
const HttpReplyPointer & getReply() const
Definition: MemObject.h:57
AsyncCall::Pointer comm_add_close_handler(int fd, CLCB *handler, void *data)
Definition: comm.cc:961
IoStats IOStats
bool multipartRangeRequest() const
Definition: HttpRequest.cc:444
const char * getStr(Http::HdrType id) const
Definition: HttpHeader.cc:1203
void detailError(int dCode)
set error type-specific detail code
Definition: errorpage.h:97
virtual size_t bytesWanted(Range< size_t > const aRange, bool ignoreDelayPool=false) const
Definition: store.cc:227
#define MAX_IPSTRLEN
Length of buffer that needs to be allocated to old a null-terminated IP-string.
Definition: forward.h:23
const SBuf & remaining() const
the remaining unprocessed section of buffer
Definition: Parser.h:96
void clean()
Definition: String.cc:125
#define MAX_URL
Definition: defines.h:118
unsigned int minor
minor version number
int xerrno
Definition: errorpage.h:149
int surrogate_is_remote
Definition: SquidConfig.h:311
#define PROF_stop(probename)
Definition: Profiler.h:63
bool refreshIsCachable(const StoreEntry *entry)
Definition: refresh.cc:529
#define rfc1738_escape_part(x)
Definition: rfc1738.h:55
void addEntry(HttpHeaderEntry *e)
Definition: HttpHeader.cc:742
time_t expires
Definition: HttpReply.h:48
void readReply(const CommIoCbParams &io)
Definition: http.cc:1133
~HttpStateData()
Definition: http.cc:126
StoreEntry * storeGetPublicByRequest(HttpRequest *req, const KeyScope keyScope)
Definition: store.cc:546
char * toStr(char *buf, const unsigned int blen, int force=AF_UNSPEC) const
Definition: Address.cc:795
bool hasNoStore() const
Definition: HttpHdrCc.h:102
#define PEER_PROXY_NEGOTIATE_NOKEYTAB
ConnectionStatus
Definition: http.h:87
void bytesIn(int qty)
Definition: DelayId.cc:154
virtual bool isEmpty() const
Definition: Store.h:60
#define SQUIDSBUFPH
Definition: SBuf.h:31
#define DBG_DATA
Definition: Debug.h:48
std::ostream & operator<<(std::ostream &os, const HttpStateData::ReuseDecision &d)
Definition: http.cc:2476
Answers make(const Answers ans, const char *why)
stores the corresponding decision
Definition: http.cc:2469
ProtocolType protocol
which protocol this version is for
void comm_remove_close_handler(int fd, CLCB *handler, void *data)
Definition: comm.cc:988
AnyP::ProtocolVersion version
breakdown of protocol version label: (HTTP/ICY) and (0.9/1.0/1.1)
Definition: StatusLine.h:70
static bool decideIfWeDoRanges(HttpRequest *orig_request)
Definition: http.cc:2116
const char * rawContent() const
Definition: SBuf.cc:519
void reset()
Definition: store.cc:1684
void doneSendingRequestBody()
Definition: http.cc:2382
HttpReply * finalReply()
Definition: Client.cc:129
const Http::StatusCode statusCode
HTTP status for debugging.
Definition: http.h:40
bool finishingBrokenPost()
if broken posts are enabled for the request, try to fix and return true
Definition: http.cc:2330
#define SQUID_ENTER_THROWING_CODE()
Definition: http.cc:69
MemBlob::size_type size_type
Definition: SBuf.h:89
bool parseHeader(Http1::Parser &)
Definition: Message.cc:223
#define SQUIDSBUFPRINT(s)
Definition: SBuf.h:32
virtual bool getMoreRequestBody(MemBuf &buf)
either fill buf with available [encoded] request body bytes or return false
Definition: http.cc:2269
char * peer_login
Definition: HttpRequest.h:152
virtual void handleRequestBodyProducerAborted()
Definition: http.cc:2430
bool originserver
Definition: CachePeer.h:118
bool spoofClientIp
Definition: RequestFlags.h:72
StoreEntry * entry
Definition: FwdState.h:137
int commSetConnTimeout(const Comm::ConnectionPointer &conn, int timeout, AsyncCall::Pointer &callback)
Definition: comm.cc:552
HttpRequestPointer request
Definition: MemObject.h:161
#define EBIT_TEST(flag, bit)
Definition: defines.h:107
time_t lastmod
Definition: HttpRequest.h:156
void wroteLast(const CommIoCbParams &io)
called after writing the very last request byte (body, last-chunk, etc)
Definition: http.cc:1578
C * getRaw() const
Definition: RefCount.h:74
const char * doneWithFwd
Definition: Client.h:184
class SquidConfig Config
Definition: SquidConfig.cc:12
bool hasSMaxAge(int32_t *val=nullptr) const
Definition: HttpHdrCc.h:127
String etag
A strong etag of the cached entry. Used for refreshing that entry.
Definition: HttpRequest.h:180
#define NULL
Definition: types.h:166
void httpHdrMangleList(HttpHeader *l, HttpRequest *request, const AccessLogEntryPointer &al, req_or_rep_t req_or_rep)
uint32_t sources
The message sources.
Definition: Message.h:99
static StoreEntry * findPreviouslyCachedEntry(StoreEntry *newEntry)
Definition: http.cc:168
Http::StatusCode peer_reply_status
last HTTP status code received
const char * urlXXX() const
Definition: MemObject.h:93
char * peer_domain
Definition: HttpRequest.h:161
time_t read
Definition: SquidConfig.h:102
size_type spaceSize() const
Definition: SBuf.h:382
bool maybeMakeSpaceAvailable(bool grow)
Definition: http.cc:1541
#define false
Definition: GnuRegex.c:233
char * host
Definition: CachePeer.h:41
void Write(const Comm::ConnectionPointer &conn, const char *buf, int size, AsyncCall::Pointer &callback, FREE *free_func)
Definition: Write.cc:35
virtual void syncAle(HttpRequest *adaptedRequest, const char *logUri) const
assigns uninitialized adapted_request and url ALE components
int Ctx
Definition: Debug.h:37
const char * reason
the decision reason
Definition: http.h:38
err_type
Definition: err_type.h:12
bool chunked_request
writing a chunked request
Definition: StateFlags.h:30
HttpStateData(FwdState *)
Definition: http.cc:86
#define base64_encode_len(length)
Definition: base64.h:169
void truncateVirginBody()
Definition: http.cc:1328
HttpHeaderEntry * clone() const
Definition: HttpHeader.cc:1510
struct IoStats::@81 Http
bool proxy_only
Definition: CachePeer.h:83
void unregister(Comm::ConnectionPointer &conn)
Definition: FwdState.cc:490
#define SQUID_EXIT_THROWING_CODE(status)
Definition: http.cc:70
Http::StatusCode status() const
retrieve the status code for this status line
Definition: StatusLine.h:45
void noStoreRemote(bool v)
void proceedAfter1xx()
restores state and resumes processing after 1xx is ignored or forwarded
Definition: http.cc:832

 

Introduction

Documentation

Support

Miscellaneous

Web Site Translations

Mirrors