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

 

Introduction

Documentation

Support

Miscellaneous

Web Site Translations

Mirrors