]> git.ipfire.org Git - thirdparty/squid.git/blame - src/client_side_request.cc
Fix clang 'smpAware' overrides a member function but is not marked 'override'
[thirdparty/squid.git] / src / client_side_request.cc
CommitLineData
edce4d98 1/*
ef57eb7b 2 * Copyright (C) 1996-2016 The Squid Software Foundation and contributors
0a9297f6 3 *
bbc27441
AJ
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.
edce4d98 7 */
8
bbc27441
AJ
9/* DEBUG: section 85 Client-side Request Routines */
10
69660be0 11/*
12 * General logic of request processing:
26ac0430 13 *
69660be0 14 * We run a series of tests to determine if access will be permitted, and to do
15 * any redirection. Then we call into the result clientStream to retrieve data.
16 * From that point on it's up to reply management.
edce4d98 17 */
18
582c2af2 19#include "squid.h"
c0941a6a
AR
20#include "acl/FilledChecklist.h"
21#include "acl/Gadgets.h"
65d448bc 22#include "anyp/PortCfg.h"
9e104535 23#include "base/AsyncJobCalls.h"
27bc2077
AJ
24#include "client_side.h"
25#include "client_side_reply.h"
26#include "client_side_request.h"
602d9612 27#include "ClientRequestContext.h"
582c2af2 28#include "clientStream.h"
5c336a3b 29#include "comm/Connection.h"
ec41b64c 30#include "comm/Write.h"
582c2af2 31#include "err_detail_type.h"
2bd84e5f 32#include "errorpage.h"
c4ad1349 33#include "fd.h"
27bc2077 34#include "fde.h"
31971e6a 35#include "format/Token.h"
d05c079c 36#include "gopher.h"
e166785a 37#include "helper.h"
24438ec5 38#include "helper/Reply.h"
5c0c642e 39#include "http.h"
d3dddfb5 40#include "http/Stream.h"
ce394734 41#include "HttpHdrCc.h"
27bc2077
AJ
42#include "HttpReply.h"
43#include "HttpRequest.h"
425de4c8 44#include "ip/QosConfig.h"
602d9612 45#include "ipcache.h"
1c7ae5ff 46#include "log/access_log.h"
27bc2077 47#include "MemObject.h"
8a01b99e 48#include "Parsing.h"
582c2af2 49#include "profiler/Profiler.h"
e166785a 50#include "redirect.h"
4d5904f7 51#include "SquidConfig.h"
27bc2077 52#include "SquidTime.h"
582c2af2 53#include "Store.h"
28204b3b 54#include "StrList.h"
685c6ff5 55#include "tools.h"
b1bd952a 56#include "URL.h"
27bc2077 57#include "wordlist.h"
582c2af2
FC
58#if USE_AUTH
59#include "auth/UserRequest.h"
60#endif
61#if USE_ADAPTATION
62#include "adaptation/AccessCheck.h"
63#include "adaptation/Answer.h"
64#include "adaptation/Iterator.h"
65#include "adaptation/Service.h"
66#if ICAP_CLIENT
67#include "adaptation/icap/History.h"
68#endif
69#endif
cb4f4424 70#if USE_OPENSSL
2bd84e5f 71#include "ssl/ServerBump.h"
602d9612 72#include "ssl/support.h"
4db984be 73#endif
3ff65596 74
edce4d98 75#if LINGERING_CLOSE
76#define comm_close comm_lingering_close
77#endif
78
79static const char *const crlf = "\r\n";
80
609c620a 81#if FOLLOW_X_FORWARDED_FOR
2efeb0b7 82static void clientFollowXForwardedForCheck(allow_t answer, void *data);
609c620a 83#endif /* FOLLOW_X_FORWARDED_FOR */
3d674977 84
955394ce 85ErrorState *clientBuildError(err_type, Http::StatusCode, char const *url, Ip::Address &, HttpRequest *);
2bd84e5f 86
8e2745f4 87CBDATA_CLASS_INIT(ClientRequestContext);
88
edce4d98 89/* Local functions */
edce4d98 90/* other */
2efeb0b7 91static void clientAccessCheckDoneWrapper(allow_t, void *);
cb4f4424 92#if USE_OPENSSL
2efeb0b7 93static void sslBumpAccessCheckDoneWrapper(allow_t, void *);
e0c0d54c 94#endif
59a1efb2 95static int clientHierarchical(ClientHttpRequest * http);
96static void clientInterpretRequestHeaders(ClientHttpRequest * http);
e166785a 97static HLPCB clientRedirectDoneWrapper;
a8a0b1c2 98static HLPCB clientStoreIdDoneWrapper;
2efeb0b7 99static void checkNoCacheDoneWrapper(allow_t, void *);
82afb125
FC
100SQUIDCEXTERN CSR clientGetMoreData;
101SQUIDCEXTERN CSS clientReplyStatus;
102SQUIDCEXTERN CSD clientReplyDetach;
528b2c61 103static void checkFailureRatio(err_type, hier_code);
edce4d98 104
8e2745f4 105ClientRequestContext::~ClientRequestContext()
106{
de31d06f 107 /*
a546b04b 108 * Release our "lock" on our parent, ClientHttpRequest, if we
109 * still have one
de31d06f 110 */
a546b04b 111
112 if (http)
113 cbdataReferenceDone(http);
62e76326 114
2bd84e5f 115 delete error;
cc8c4af2 116 debugs(85,3, "ClientRequestContext destructed, this=" << this);
8e2745f4 117}
118
cc8c4af2
AJ
119ClientRequestContext::ClientRequestContext(ClientHttpRequest *anHttp) :
120 http(cbdataReference(anHttp)),
121 acl_checklist(NULL),
122 redirect_state(REDIRECT_NONE),
123 store_id_state(REDIRECT_NONE),
124 host_header_verify_done(false),
125 http_access_done(false),
126 adapted_http_access_done(false),
127#if USE_ADAPTATION
128 adaptation_acl_check_done(false),
129#endif
130 redirect_done(false),
131 store_id_done(false),
132 no_cache_done(false),
133 interpreted_req_hdrs(false),
134 tosToClientDone(false),
135 nfmarkToClientDone(false),
cb4f4424 136#if USE_OPENSSL
cc8c4af2 137 sslBumpCheckDone(false),
e0c0d54c 138#endif
cc8c4af2
AJ
139 error(NULL),
140 readNextRequest(false)
141{
142 debugs(85, 3, "ClientRequestContext constructed, this=" << this);
edce4d98 143}
144
528b2c61 145CBDATA_CLASS_INIT(ClientHttpRequest);
8e2745f4 146
26ac0430 147ClientHttpRequest::ClientHttpRequest(ConnStateData * aConn) :
a83c6ed6 148#if USE_ADAPTATION
f53969cc 149 AsyncJob("ClientHttpRequest"),
1cf238db 150#endif
cc8c4af2
AJ
151 request(NULL),
152 uri(NULL),
153 log_uri(NULL),
154 req_sz(0),
155 logType(LOG_TAG_NONE),
156 calloutContext(NULL),
157 maxReplyBodySize_(0),
158 entry_(NULL),
159 loggingEntry_(NULL),
160 conn_(NULL)
161#if USE_OPENSSL
162 , sslBumpNeed_(Ssl::bumpEnd)
163#endif
164#if USE_ADAPTATION
165 , request_satisfaction_mode(false)
166 , request_satisfaction_offset(0)
167#endif
528b2c61 168{
a0355e95 169 setConn(aConn);
41ebd397 170 al = new AccessLogEntry;
af0ded40 171 al->cache.start_time = current_time;
70b0f938
AJ
172 if (aConn) {
173 al->tcpClient = clientConnection = aConn->clientConnection;
174 al->cache.port = aConn->port;
175 al->cache.caddr = aConn->log_addr;
d4806c91 176
cb4f4424 177#if USE_OPENSSL
70b0f938
AJ
178 if (aConn->clientConnection != NULL && aConn->clientConnection->isOpen()) {
179 if (auto ssl = fd_table[aConn->clientConnection->fd].ssl.get())
35b3559c 180 al->cache.sslClientCert.resetWithoutLocking(SSL_get_peer_certificate(ssl));
70b0f938 181 }
f4698e0b 182#endif
70b0f938 183 }
a0355e95 184 dlinkAdd(this, &active, &ClientActiveRequests);
528b2c61 185}
186
0655fa4d 187/*
188 * returns true if client specified that the object must come from the cache
189 * without contacting origin server
190 */
191bool
192ClientHttpRequest::onlyIfCached()const
193{
194 assert(request);
195 return request->cache_control &&
4ce6e3b5 196 request->cache_control->onlyIfCached();
0655fa4d 197}
198
77aacca5 199/**
528b2c61 200 * This function is designed to serve a fairly specific purpose.
201 * Occasionally our vBNS-connected caches can talk to each other, but not
202 * the rest of the world. Here we try to detect frequent failures which
203 * make the cache unusable (e.g. DNS lookup and connect() failures). If
204 * the failure:success ratio goes above 1.0 then we go into "hit only"
205 * mode where we only return UDP_HIT or UDP_MISS_NOFETCH. Neighbors
206 * will only fetch HITs from us if they are using the ICP protocol. We
207 * stay in this mode for 5 minutes.
26ac0430 208 *
528b2c61 209 * Duane W., Sept 16, 1996
210 */
528b2c61 211static void
212checkFailureRatio(err_type etype, hier_code hcode)
213{
77aacca5
AJ
214 // Can be set at compile time with -D compiler flag
215#ifndef FAILURE_MODE_TIME
216#define FAILURE_MODE_TIME 300
217#endif
218
8d74a311
AJ
219 if (hcode == HIER_NONE)
220 return;
221
222 // don't bother when ICP is disabled.
223 if (Config.Port.icp <= 0)
224 return;
225
528b2c61 226 static double magic_factor = 100.0;
227 double n_good;
228 double n_bad;
62e76326 229
528b2c61 230 n_good = magic_factor / (1.0 + request_failure_ratio);
62e76326 231
528b2c61 232 n_bad = magic_factor - n_good;
62e76326 233
528b2c61 234 switch (etype) {
62e76326 235
528b2c61 236 case ERR_DNS_FAIL:
62e76326 237
528b2c61 238 case ERR_CONNECT_FAIL:
3712be3f 239 case ERR_SECURE_CONNECT_FAIL:
62e76326 240
528b2c61 241 case ERR_READ_ERROR:
5086523e 242 ++n_bad;
62e76326 243 break;
244
528b2c61 245 default:
5086523e 246 ++n_good;
528b2c61 247 }
62e76326 248
528b2c61 249 request_failure_ratio = n_bad / n_good;
62e76326 250
528b2c61 251 if (hit_only_mode_until > squid_curtime)
62e76326 252 return;
253
528b2c61 254 if (request_failure_ratio < 1.0)
62e76326 255 return;
256
77aacca5 257 debugs(33, DBG_CRITICAL, "WARNING: Failure Ratio at "<< std::setw(4)<<
bf8fe701 258 std::setprecision(3) << request_failure_ratio);
62e76326 259
8d74a311 260 debugs(33, DBG_CRITICAL, "WARNING: ICP going into HIT-only mode for " <<
bf8fe701 261 FAILURE_MODE_TIME / 60 << " minutes...");
62e76326 262
528b2c61 263 hit_only_mode_until = squid_curtime + FAILURE_MODE_TIME;
62e76326 264
f53969cc 265 request_failure_ratio = 0.8; /* reset to something less than 1.0 */
528b2c61 266}
267
268ClientHttpRequest::~ClientHttpRequest()
269{
bf8fe701 270 debugs(33, 3, "httpRequestFree: " << uri);
72bdee4c 271 PROF_start(httpRequestFree);
62e76326 272
5f8252d2 273 // Even though freeResources() below may destroy the request,
274 // we no longer set request->body_pipe to NULL here
275 // because we did not initiate that pipe (ConnStateData did)
62e76326 276
528b2c61 277 /* the ICP check here was erroneous
26ac0430 278 * - StoreEntry::releaseRequest was always called if entry was valid
528b2c61 279 */
9ce7856a 280
528b2c61 281 logRequest();
9ce7856a 282
0976f8db 283 loggingEntry(NULL);
284
528b2c61 285 if (request)
41ebd397 286 checkFailureRatio(request->errType, al->hier.code);
62e76326 287
528b2c61 288 freeResources();
62e76326 289
a83c6ed6
AR
290#if USE_ADAPTATION
291 announceInitiatorAbort(virginHeadSource);
9d4d7c5e 292
a83c6ed6
AR
293 if (adaptedBodySource != NULL)
294 stopConsumingFrom(adaptedBodySource);
de31d06f 295#endif
9ce7856a 296
de31d06f 297 if (calloutContext)
298 delete calloutContext;
299
be364179
AJ
300 clientConnection = NULL;
301
26ac0430
AJ
302 if (conn_)
303 cbdataReferenceDone(conn_);
1cf238db 304
528b2c61 305 /* moving to the next connection is handled by the context free */
306 dlinkDelete(&active, &ClientActiveRequests);
9ce7856a 307
72bdee4c 308 PROF_stop(httpRequestFree);
528b2c61 309}
62e76326 310
11992b6f
AJ
311/**
312 * Create a request and kick it off
313 *
314 * \retval 0 success
315 * \retval -1 failure
316 *
69660be0 317 * TODO: Pass in the buffers to be used in the inital Read request, as they are
318 * determined by the user
edce4d98 319 */
11992b6f 320int
60745f24 321clientBeginRequest(const HttpRequestMethod& method, char const *url, CSCB * streamcallback,
0655fa4d 322 CSD * streamdetach, ClientStreamData streamdata, HttpHeader const *header,
62e76326 323 char *tailbuf, size_t taillen)
edce4d98 324{
325 size_t url_sz;
a0355e95 326 ClientHttpRequest *http = new ClientHttpRequest(NULL);
190154cf 327 HttpRequest *request;
528b2c61 328 StoreIOBuffer tempBuffer;
af0ded40
CT
329 if (http->al != NULL)
330 http->al->cache.start_time = current_time;
edce4d98 331 /* this is only used to adjust the connection offset in client_side.c */
332 http->req_sz = 0;
c8be6d7b 333 tempBuffer.length = taillen;
334 tempBuffer.data = tailbuf;
edce4d98 335 /* client stream setup */
336 clientStreamInit(&http->client_stream, clientGetMoreData, clientReplyDetach,
0655fa4d 337 clientReplyStatus, new clientReplyContext(http), streamcallback,
62e76326 338 streamdetach, streamdata, tempBuffer);
edce4d98 339 /* make it visible in the 'current acctive requests list' */
edce4d98 340 /* Set flags */
a46d2c0e 341 /* internal requests only makes sense in an
342 * accelerator today. TODO: accept flags ? */
be4d35dc 343 http->flags.accel = true;
edce4d98 344 /* allow size for url rewriting */
345 url_sz = strlen(url) + Config.appendDomainLen + 5;
e6ccf245 346 http->uri = (char *)xcalloc(url_sz, 1);
edce4d98 347 strcpy(http->uri, url);
348
d6067ac1 349 if ((request = HttpRequest::CreateFromUrl(http->uri, method)) == NULL) {
bf8fe701 350 debugs(85, 5, "Invalid URL: " << http->uri);
62e76326 351 return -1;
edce4d98 352 }
62e76326 353
69660be0 354 /*
11992b6f 355 * now update the headers in request with our supplied headers. urlParse
69660be0 356 * should return a blank header set, but we use Update to be sure of
357 * correctness.
edce4d98 358 */
359 if (header)
2d4f252d 360 request->header.update(header);
62e76326 361
edce4d98 362 http->log_uri = xstrdup(urlCanonicalClean(request));
62e76326 363
edce4d98 364 /* http struct now ready */
365
69660be0 366 /*
367 * build new header list *? TODO
edce4d98 368 */
45e5102d 369 request->flags.accelerated = http->flags.accel;
62e76326 370
e857372a 371 request->flags.internalClient = true;
a46d2c0e 372
373 /* this is an internally created
374 * request, not subject to acceleration
375 * target overrides */
69660be0 376 /*
377 * FIXME? Do we want to detect and handle internal requests of internal
378 * objects ?
379 */
edce4d98 380
381 /* Internally created requests cannot have bodies today */
382 request->content_length = 0;
62e76326 383
4dd643d5 384 request->client_addr.setNoAddr();
62e76326 385
3d674977 386#if FOLLOW_X_FORWARDED_FOR
4dd643d5 387 request->indirect_client_addr.setNoAddr();
3d674977 388#endif /* FOLLOW_X_FORWARDED_FOR */
26ac0430 389
f53969cc 390 request->my_addr.setNoAddr(); /* undefined for internal requests */
62e76326 391
4dd643d5 392 request->my_addr.port(0);
62e76326 393
2592bc70 394 request->http_ver = Http::ProtocolVersion();
62e76326 395
b248c2a3
AJ
396 http->request = request;
397 HTTPMSGLOCK(http->request);
edce4d98 398
399 /* optional - skip the access check ? */
de31d06f 400 http->calloutContext = new ClientRequestContext(http);
401
57abaac0 402 http->calloutContext->http_access_done = false;
de31d06f 403
57abaac0 404 http->calloutContext->redirect_done = true;
de31d06f 405
57abaac0 406 http->calloutContext->no_cache_done = true;
de31d06f 407
408 http->doCallouts();
62e76326 409
edce4d98 410 return 0;
411}
412
de31d06f 413bool
414ClientRequestContext::httpStateIsValid()
415{
416 ClientHttpRequest *http_ = http;
417
418 if (cbdataReferenceValid(http_))
419 return true;
420
421 http = NULL;
422
423 cbdataReferenceDone(http_);
424
425 return false;
426}
427
3d674977
AJ
428#if FOLLOW_X_FORWARDED_FOR
429/**
a9044668 430 * clientFollowXForwardedForCheck() checks the content of X-Forwarded-For:
3d674977
AJ
431 * against the followXFF ACL, or cleans up and passes control to
432 * clientAccessCheck().
d096ace1
AJ
433 *
434 * The trust model here is a little ambiguous. So to clarify the logic:
435 * - we may always use the direct client address as the client IP.
a9044668 436 * - these trust tests merey tell whether we trust given IP enough to believe the
d096ace1
AJ
437 * IP string which it appended to the X-Forwarded-For: header.
438 * - if at any point we don't trust what an IP adds we stop looking.
439 * - at that point the current contents of indirect_client_addr are the value set
440 * by the last previously trusted IP.
441 * ++ indirect_client_addr contains the remote direct client from the trusted peers viewpoint.
3d674977 442 */
3d674977 443static void
2efeb0b7 444clientFollowXForwardedForCheck(allow_t answer, void *data)
3d674977
AJ
445{
446 ClientRequestContext *calloutContext = (ClientRequestContext *) data;
3d674977
AJ
447
448 if (!calloutContext->httpStateIsValid())
449 return;
450
d096ace1
AJ
451 ClientHttpRequest *http = calloutContext->http;
452 HttpRequest *request = http->request;
453
3d674977
AJ
454 /*
455 * answer should be be ACCESS_ALLOWED or ACCESS_DENIED if we are
456 * called as a result of ACL checks, or -1 if we are called when
457 * there's nothing left to do.
458 */
459 if (answer == ACCESS_ALLOWED &&
26ac0430 460 request->x_forwarded_for_iterator.size () != 0) {
d096ace1 461
3d674977 462 /*
d096ace1
AJ
463 * Remove the last comma-delimited element from the
464 * x_forwarded_for_iterator and use it to repeat the cycle.
465 */
3d674977
AJ
466 const char *p;
467 const char *asciiaddr;
468 int l;
b7ac5457 469 Ip::Address addr;
bb790702 470 p = request->x_forwarded_for_iterator.termedBuf();
3d674977
AJ
471 l = request->x_forwarded_for_iterator.size();
472
473 /*
474 * XXX x_forwarded_for_iterator should really be a list of
475 * IP addresses, but it's a String instead. We have to
476 * walk backwards through the String, biting off the last
477 * comma-delimited part each time. As long as the data is in
478 * a String, we should probably implement and use a variant of
479 * strListGetItem() that walks backwards instead of forwards
480 * through a comma-separated list. But we don't even do that;
481 * we just do the work in-line here.
482 */
483 /* skip trailing space and commas */
484 while (l > 0 && (p[l-1] == ',' || xisspace(p[l-1])))
5e263176 485 --l;
3d674977
AJ
486 request->x_forwarded_for_iterator.cut(l);
487 /* look for start of last item in list */
488 while (l > 0 && ! (p[l-1] == ',' || xisspace(p[l-1])))
5e263176 489 --l;
3d674977 490 asciiaddr = p+l;
fafd0efa 491 if ((addr = asciiaddr)) {
3d674977
AJ
492 request->indirect_client_addr = addr;
493 request->x_forwarded_for_iterator.cut(l);
d096ace1
AJ
494 calloutContext->acl_checklist = clientAclChecklistCreate(Config.accessList.followXFF, http);
495 if (!Config.onoff.acl_uses_indirect_client) {
496 /* override the default src_addr tested if we have to go deeper than one level into XFF */
497 Filled(calloutContext->acl_checklist)->src_addr = request->indirect_client_addr;
3d674977 498 }
d096ace1 499 calloutContext->acl_checklist->nonBlockingCheck(clientFollowXForwardedForCheck, data);
3d674977
AJ
500 return;
501 }
502 } /*if (answer == ACCESS_ALLOWED &&
503 request->x_forwarded_for_iterator.size () != 0)*/
504
505 /* clean up, and pass control to clientAccessCheck */
26ac0430 506 if (Config.onoff.log_uses_indirect_client) {
3d674977
AJ
507 /*
508 * Ensure that the access log shows the indirect client
509 * instead of the direct client.
510 */
511 ConnStateData *conn = http->getConn();
512 conn->log_addr = request->indirect_client_addr;
d4806c91 513 http->al->cache.caddr = conn->log_addr;
3d674977
AJ
514 }
515 request->x_forwarded_for_iterator.clean();
e857372a 516 request->flags.done_follow_x_forwarded_for = true;
3d674977 517
d096ace1
AJ
518 if (answer != ACCESS_ALLOWED && answer != ACCESS_DENIED) {
519 debugs(28, DBG_CRITICAL, "ERROR: Processing X-Forwarded-For. Stopping at IP address: " << request->indirect_client_addr );
493d3865
AJ
520 }
521
522 /* process actual access ACL as normal. */
523 calloutContext->clientAccessCheck();
3d674977
AJ
524}
525#endif /* FOLLOW_X_FORWARDED_FOR */
526
fe97983f 527static void
4a3b98d7 528hostHeaderIpVerifyWrapper(const ipcache_addrs* ia, const Dns::LookupDetails &dns, void *data)
fe97983f
AJ
529{
530 ClientRequestContext *c = static_cast<ClientRequestContext*>(data);
531 c->hostHeaderIpVerify(ia, dns);
532}
533
534void
4a3b98d7 535ClientRequestContext::hostHeaderIpVerify(const ipcache_addrs* ia, const Dns::LookupDetails &dns)
fe97983f
AJ
536{
537 Comm::ConnectionPointer clientConn = http->getConn()->clientConnection;
538
539 // note the DNS details for the transaction stats.
540 http->request->recordLookup(dns);
541
542 if (ia != NULL && ia->count > 0) {
543 // Is the NAT destination IP in DNS?
5086523e 544 for (int i = 0; i < ia->count; ++i) {
fe97983f
AJ
545 if (clientConn->local.matchIPAddr(ia->in_addrs[i]) == 0) {
546 debugs(85, 3, HERE << "validate IP " << clientConn->local << " possible from Host:");
e857372a 547 http->request->flags.hostVerified = true;
fe97983f
AJ
548 http->doCallouts();
549 return;
550 }
551 debugs(85, 3, HERE << "validate IP " << clientConn->local << " non-match from Host: IP " << ia->in_addrs[i]);
552 }
553 }
554 debugs(85, 3, HERE << "FAIL: validate IP " << clientConn->local << " possible from Host:");
05b28f84 555 hostHeaderVerifyFailed("local IP", "any domain IP");
fe97983f
AJ
556}
557
558void
05b28f84 559ClientRequestContext::hostHeaderVerifyFailed(const char *A, const char *B)
fe97983f 560{
2962f8b8
AJ
561 // IP address validation for Host: failed. Admin wants to ignore them.
562 // NP: we do not yet handle CONNECT tunnels well, so ignore for them
c2a7cefd 563 if (!Config.onoff.hostStrictVerify && http->request->method != Http::METHOD_CONNECT) {
2962f8b8 564 debugs(85, 3, "SECURITY ALERT: Host header forgery detected on " << http->getConn()->clientConnection <<
851feda6 565 " (" << A << " does not match " << B << ") on URL: " << http->request->effectiveRequestUri());
2962f8b8 566
450fe1cb 567 // NP: it is tempting to use 'flags.noCache' but that is all about READing cache data.
2962f8b8 568 // The problems here are about WRITE for new cache content, which means flags.cachable
e857372a 569 http->request->flags.cachable = false; // MUST NOT cache (for now)
2962f8b8 570 // XXX: when we have updated the cache key to base on raw-IP + URI this cacheable limit can go.
e857372a 571 http->request->flags.hierarchical = false; // MUST NOT pass to peers (for now)
2962f8b8 572 // XXX: when we have sorted out the best way to relay requests properly to peers this hierarchical limit can go.
567fe088 573 http->doCallouts();
2962f8b8
AJ
574 return;
575 }
576
8f489ad7
AJ
577 debugs(85, DBG_IMPORTANT, "SECURITY ALERT: Host header forgery detected on " <<
578 http->getConn()->clientConnection << " (" << A << " does not match " << B << ")");
d610d018
AR
579 if (const char *ua = http->request->header.getStr(Http::HdrType::USER_AGENT))
580 debugs(85, DBG_IMPORTANT, "SECURITY ALERT: By user agent: " << ua);
851feda6 581 debugs(85, DBG_IMPORTANT, "SECURITY ALERT: on URL: " << http->request->effectiveRequestUri());
fe97983f
AJ
582
583 // IP address validation for Host: failed. reject the connection.
584 clientStreamNode *node = (clientStreamNode *)http->client_stream.tail->prev->data;
585 clientReplyContext *repContext = dynamic_cast<clientReplyContext *>(node->data.getRaw());
586 assert (repContext);
955394ce 587 repContext->setReplyToError(ERR_CONFLICT_HOST, Http::scConflict,
fe97983f
AJ
588 http->request->method, NULL,
589 http->getConn()->clientConnection->remote,
590 http->request,
591 NULL,
592#if USE_AUTH
cc1e110a
AJ
593 http->getConn() != NULL && http->getConn()->getAuth() != NULL ?
594 http->getConn()->getAuth() : http->request->auth_user_request);
fe97983f
AJ
595#else
596 NULL);
597#endif
598 node = (clientStreamNode *)http->client_stream.tail->data;
599 clientStreamRead(node, http, node->readBuffer);
600}
601
602void
603ClientRequestContext::hostHeaderVerify()
604{
605 // Require a Host: header.
789217a2 606 const char *host = http->request->header.getStr(Http::HdrType::HOST);
fe97983f
AJ
607
608 if (!host) {
609 // TODO: dump out the HTTP/1.1 error about missing host header.
610 // otherwise this is fine, can't forge a header value when its not even set.
611 debugs(85, 3, HERE << "validate skipped with no Host: header present.");
612 http->doCallouts();
613 return;
614 }
615
45e5102d 616 if (http->request->flags.internal) {
8f489ad7
AJ
617 // TODO: kill this when URL handling allows partial URLs out of accel mode
618 // and we no longer screw with the URL just to add our internal host there
619 debugs(85, 6, HERE << "validate skipped due to internal composite URL.");
620 http->doCallouts();
621 return;
622 }
623
fe97983f
AJ
624 // Locate if there is a port attached, strip ready for IP lookup
625 char *portStr = NULL;
91663dce
AJ
626 char *hostB = xstrdup(host);
627 host = hostB;
fe97983f
AJ
628 if (host[0] == '[') {
629 // IPv6 literal.
fe97983f 630 portStr = strchr(hostB, ']');
91663dce
AJ
631 if (portStr && *(++portStr) != ':') {
632 portStr = NULL;
fe97983f 633 }
91663dce 634 } else {
fe97983f 635 // Domain or IPv4 literal with port
fe97983f 636 portStr = strrchr(hostB, ':');
91663dce
AJ
637 }
638
639 uint16_t port = 0;
640 if (portStr) {
641 *portStr = '\0'; // strip the ':'
126e1dc0
AJ
642 if (*(++portStr) != '\0') {
643 char *end = NULL;
644 int64_t ret = strtoll(portStr, &end, 10);
645 if (end == portStr || *end != '\0' || ret < 1 || ret > 0xFFFF) {
646 // invalid port details. Replace the ':'
647 *(--portStr) = ':';
648 portStr = NULL;
649 } else
650 port = (ret & 0xFFFF);
651 }
fe97983f
AJ
652 }
653
5c51bffb 654 debugs(85, 3, "validate host=" << host << ", port=" << port << ", portStr=" << (portStr?portStr:"NULL"));
0d901ef4 655 if (http->request->flags.intercepted || http->request->flags.interceptTproxy) {
ba4d9da0 656 // verify the Host: port (if any) matches the apparent destination
4dd643d5 657 if (portStr && port != http->getConn()->clientConnection->local.port()) {
5c51bffb 658 debugs(85, 3, "FAIL on validate port " << http->getConn()->clientConnection->local.port() <<
05b28f84
AJ
659 " matches Host: port " << port << " (" << portStr << ")");
660 hostHeaderVerifyFailed("intercepted port", portStr);
ba4d9da0
AJ
661 } else {
662 // XXX: match the scheme default port against the apparent destination
fe97983f 663
ba4d9da0
AJ
664 // verify the destination DNS is one of the Host: headers IPs
665 ipcache_nbgethostbyname(host, hostHeaderIpVerifyWrapper, this);
666 }
06059513 667 } else if (!Config.onoff.hostStrictVerify) {
5c51bffb 668 debugs(85, 3, "validate skipped.");
90529125 669 http->doCallouts();
5c51bffb 670 } else if (strlen(host) != strlen(http->request->url.host())) {
8f489ad7 671 // Verify forward-proxy requested URL domain matches the Host: header
5c51bffb
AJ
672 debugs(85, 3, "FAIL on validate URL domain length " << http->request->url.host() << " matches Host: " << host);
673 hostHeaderVerifyFailed(host, http->request->url.host());
674 } else if (matchDomainName(host, http->request->url.host()) != 0) {
ba4d9da0 675 // Verify forward-proxy requested URL domain matches the Host: header
5c51bffb
AJ
676 debugs(85, 3, "FAIL on validate URL domain " << http->request->url.host() << " matches Host: " << host);
677 hostHeaderVerifyFailed(host, http->request->url.host());
678 } else if (portStr && port != http->request->url.port()) {
ba4d9da0 679 // Verify forward-proxy requested URL domain matches the Host: header
5c51bffb 680 debugs(85, 3, "FAIL on validate URL port " << http->request->url.port() << " matches Host: port " << portStr);
ba4d9da0 681 hostHeaderVerifyFailed("URL port", portStr);
5c51bffb 682 } else if (!portStr && http->request->method != Http::METHOD_CONNECT && http->request->url.port() != http->request->url.getScheme().defaultPort()) {
ba4d9da0 683 // Verify forward-proxy requested URL domain matches the Host: header
65d2fdbf 684 // Special case: we don't have a default-port to check for CONNECT. Assume URL is correct.
5c51bffb 685 debugs(85, 3, "FAIL on validate URL port " << http->request->url.port() << " matches Host: default port " << http->request->url.getScheme().defaultPort());
ba4d9da0
AJ
686 hostHeaderVerifyFailed("URL port", "default port");
687 } else {
688 // Okay no problem.
5c51bffb 689 debugs(85, 3, "validate passed.");
e857372a 690 http->request->flags.hostVerified = true;
ba4d9da0 691 http->doCallouts();
fe97983f 692 }
ba4d9da0 693 safe_free(hostB);
fe97983f
AJ
694}
695
edce4d98 696/* This is the entry point for external users of the client_side routines */
697void
de31d06f 698ClientRequestContext::clientAccessCheck()
edce4d98 699{
fbe9e379 700#if FOLLOW_X_FORWARDED_FOR
f1a1f20a 701 if (!http->request->flags.doneFollowXff() &&
26ac0430 702 Config.accessList.followXFF &&
789217a2 703 http->request->header.has(Http::HdrType::X_FORWARDED_FOR)) {
d096ace1
AJ
704
705 /* we always trust the direct client address for actual use */
706 http->request->indirect_client_addr = http->request->client_addr;
4dd643d5 707 http->request->indirect_client_addr.port(0);
d096ace1
AJ
708
709 /* setup the XFF iterator for processing */
789217a2 710 http->request->x_forwarded_for_iterator = http->request->header.getList(Http::HdrType::X_FORWARDED_FOR);
d096ace1
AJ
711
712 /* begin by checking to see if we trust direct client enough to walk XFF */
713 acl_checklist = clientAclChecklistCreate(Config.accessList.followXFF, http);
714 acl_checklist->nonBlockingCheck(clientFollowXForwardedForCheck, this);
3d674977
AJ
715 return;
716 }
fbe9e379 717#endif
493d3865 718
b50e327b
AJ
719 if (Config.accessList.http) {
720 acl_checklist = clientAclChecklistCreate(Config.accessList.http, http);
721 acl_checklist->nonBlockingCheck(clientAccessCheckDoneWrapper, this);
722 } else {
723 debugs(0, DBG_CRITICAL, "No http_access configuration found. This will block ALL traffic");
724 clientAccessCheckDone(ACCESS_DENIED);
725 }
edce4d98 726}
727
533493da
AJ
728/**
729 * Identical in operation to clientAccessCheck() but performed later using different configured ACL list.
730 * The default here is to allow all. Since the earlier http_access should do a default deny all.
731 * This check is just for a last-minute denial based on adapted request headers.
732 */
733void
734ClientRequestContext::clientAccessCheck2()
735{
736 if (Config.accessList.adapted_http) {
737 acl_checklist = clientAclChecklistCreate(Config.accessList.adapted_http, http);
738 acl_checklist->nonBlockingCheck(clientAccessCheckDoneWrapper, this);
739 } else {
327e2131 740 debugs(85, 2, HERE << "No adapted_http_access configuration. default: ALLOW");
533493da
AJ
741 clientAccessCheckDone(ACCESS_ALLOWED);
742 }
743}
744
edce4d98 745void
2efeb0b7 746clientAccessCheckDoneWrapper(allow_t answer, void *data)
edce4d98 747{
de31d06f 748 ClientRequestContext *calloutContext = (ClientRequestContext *) data;
fbade053 749
de31d06f 750 if (!calloutContext->httpStateIsValid())
62e76326 751 return;
62e76326 752
de31d06f 753 calloutContext->clientAccessCheckDone(answer);
754}
755
9d5e7196
AJ
756void
757ClientRequestContext::clientAccessCheckDone(const allow_t &answer)
de31d06f 758{
759 acl_checklist = NULL;
edce4d98 760 err_type page_id;
955394ce 761 Http::StatusCode status;
7f06a3d8 762 debugs(85, 2, "The request " << http->request->method << ' ' <<
9d5e7196 763 http->uri << " is " << answer <<
6f58d7d7 764 "; last ACL checked: " << (AclMatchedName ? AclMatchedName : "[none]"));
f5691f9c 765
2f1431ea
AJ
766#if USE_AUTH
767 char const *proxy_auth_msg = "<null>";
cc1e110a
AJ
768 if (http->getConn() != NULL && http->getConn()->getAuth() != NULL)
769 proxy_auth_msg = http->getConn()->getAuth()->denyMessage("<null>");
f5691f9c 770 else if (http->request->auth_user_request != NULL)
771 proxy_auth_msg = http->request->auth_user_request->denyMessage("<null>");
2f1431ea 772#endif
62e76326 773
dd332b92 774 if (answer != ACCESS_ALLOWED) {
9d5e7196 775 // auth has a grace period where credentials can be expired but okay not to challenge.
309347ef 776
9d5e7196
AJ
777 /* Send an auth challenge or error */
778 // XXX: do we still need aclIsProxyAuth() ?
dd332b92 779 bool auth_challenge = (answer == ACCESS_AUTH_REQUIRED || aclIsProxyAuth(AclMatchedName));
9d5e7196
AJ
780 debugs(85, 5, "Access Denied: " << http->uri);
781 debugs(85, 5, "AclMatchedName = " << (AclMatchedName ? AclMatchedName : "<null>"));
2f1431ea 782#if USE_AUTH
9d5e7196
AJ
783 if (auth_challenge)
784 debugs(33, 5, "Proxy Auth Message = " << (proxy_auth_msg ? proxy_auth_msg : "<null>"));
2f1431ea 785#endif
9ce7856a 786
9d5e7196
AJ
787 /*
788 * NOTE: get page_id here, based on AclMatchedName because if
789 * USE_DELAY_POOLS is enabled, then AclMatchedName gets clobbered in
790 * the clientCreateStoreEntry() call just below. Pedro Ribeiro
791 * <pribeiro@isel.pt>
792 */
793 page_id = aclGetDenyInfoPage(&Config.denyInfoList, AclMatchedName, answer != ACCESS_AUTH_REQUIRED);
9ce7856a 794
9d5e7196 795 http->logType = LOG_TCP_DENIED;
62e76326 796
9d5e7196 797 if (auth_challenge) {
2f1431ea 798#if USE_AUTH
450fe1cb 799 if (http->request->flags.sslBumped) {
9d5e7196 800 /*SSL Bumped request, authentication is not possible*/
955394ce 801 status = Http::scForbidden;
9d5e7196
AJ
802 } else if (!http->flags.accel) {
803 /* Proxy authorisation needed */
955394ce 804 status = Http::scProxyAuthenticationRequired;
9d5e7196
AJ
805 } else {
806 /* WWW authorisation needed */
955394ce 807 status = Http::scUnauthorized;
9d5e7196 808 }
ed6163ef 809#else
9d5e7196 810 // need auth, but not possible to do.
955394ce 811 status = Http::scForbidden;
ed6163ef 812#endif
9d5e7196
AJ
813 if (page_id == ERR_NONE)
814 page_id = ERR_CACHE_ACCESS_DENIED;
815 } else {
955394ce 816 status = Http::scForbidden;
ed6163ef 817
9d5e7196
AJ
818 if (page_id == ERR_NONE)
819 page_id = ERR_ACCESS_DENIED;
820 }
62e76326 821
9d5e7196 822 Ip::Address tmpnoaddr;
4dd643d5 823 tmpnoaddr.setNoAddr();
87f237a9 824 error = clientBuildError(page_id, status,
68715527
CT
825 NULL,
826 http->getConn() != NULL ? http->getConn()->clientConnection->remote : tmpnoaddr,
827 http->request
87f237a9 828 );
68715527 829
2f1431ea 830#if USE_AUTH
87f237a9 831 error->auth_user_request =
cc1e110a
AJ
832 http->getConn() != NULL && http->getConn()->getAuth() != NULL ?
833 http->getConn()->getAuth() : http->request->auth_user_request;
2f1431ea 834#endif
68715527
CT
835
836 readNextRequest = true;
9d5e7196 837 }
de31d06f 838
dd332b92 839 /* ACCESS_ALLOWED continues here ... */
3f0e38d6
AJ
840 xfree(http->uri);
841 http->uri = SBufToCstring(http->request->effectiveRequestUri());
de31d06f 842 http->doCallouts();
843}
844
a83c6ed6 845#if USE_ADAPTATION
de31d06f 846void
79628299 847ClientHttpRequest::noteAdaptationAclCheckDone(Adaptation::ServiceGroupPointer g)
de31d06f 848{
a83c6ed6 849 debugs(93,3,HERE << this << " adaptationAclCheckDone called");
6ec67de9 850
e1381638 851#if ICAP_CLIENT
79628299 852 Adaptation::Icap::History::Pointer ih = request->icapHistory();
e1381638 853 if (ih != NULL) {
6bc2a98d 854 if (getConn() != NULL && getConn()->clientConnection != NULL) {
79628299 855 ih->rfc931 = getConn()->clientConnection->rfc931;
cb4f4424 856#if USE_OPENSSL
6bc2a98d 857 if (getConn()->clientConnection->isOpen()) {
33cc0629 858 ih->ssluser = sslGetUserEmail(fd_table[getConn()->clientConnection->fd].ssl.get());
6bc2a98d 859 }
e1381638 860#endif
3ff65596 861 }
79628299
CT
862 ih->log_uri = log_uri;
863 ih->req_sz = req_sz;
3ff65596
AR
864 }
865#endif
866
a22e6cd3
AR
867 if (!g) {
868 debugs(85,3, HERE << "no adaptation needed");
79628299 869 doCallouts();
5f8252d2 870 return;
871 }
de31d06f 872
79628299 873 startAdaptation(g);
edce4d98 874}
875
de31d06f 876#endif
877
14cc8559 878static void
2efeb0b7 879clientRedirectAccessCheckDone(allow_t answer, void *data)
14cc8559 880{
881 ClientRequestContext *context = (ClientRequestContext *)data;
9d5e7196
AJ
882 ClientHttpRequest *http = context->http;
883 context->acl_checklist = NULL;
14cc8559 884
885 if (answer == ACCESS_ALLOWED)
9d5e7196 886 redirectStart(http, clientRedirectDoneWrapper, context);
bc98bc4b 887 else {
24438ec5 888 Helper::Reply nilReply;
2428ce02 889 nilReply.result = Helper::Error;
bc98bc4b
AJ
890 context->clientRedirectDone(nilReply);
891 }
14cc8559 892}
893
de31d06f 894void
895ClientRequestContext::clientRedirectStart()
14cc8559 896{
48e7baac 897 debugs(33, 5, HERE << "'" << http->uri << "'");
b11724bb 898 (void)SyncNotes(*http->al, *http->request);
14cc8559 899 if (Config.accessList.redirector) {
de31d06f 900 acl_checklist = clientAclChecklistCreate(Config.accessList.redirector, http);
901 acl_checklist->nonBlockingCheck(clientRedirectAccessCheckDone, this);
14cc8559 902 } else
de31d06f 903 redirectStart(http, clientRedirectDoneWrapper, this);
14cc8559 904}
905
a8a0b1c2
EC
906/**
907 * This methods handles Access checks result of StoreId access list.
908 * Will handle as "ERR" (no change) in a case Access is not allowed.
909 */
910static void
911clientStoreIdAccessCheckDone(allow_t answer, void *data)
912{
913 ClientRequestContext *context = static_cast<ClientRequestContext *>(data);
914 ClientHttpRequest *http = context->http;
915 context->acl_checklist = NULL;
916
917 if (answer == ACCESS_ALLOWED)
918 storeIdStart(http, clientStoreIdDoneWrapper, context);
919 else {
920 debugs(85, 3, "access denied expected ERR reply handling: " << answer);
24438ec5 921 Helper::Reply nilReply;
2428ce02 922 nilReply.result = Helper::Error;
a8a0b1c2
EC
923 context->clientStoreIdDone(nilReply);
924 }
925}
926
927/**
928 * Start locating an alternative storeage ID string (if any) from admin
929 * configured helper program. This is an asynchronous operation terminating in
930 * ClientRequestContext::clientStoreIdDone() when completed.
931 */
932void
933ClientRequestContext::clientStoreIdStart()
934{
935 debugs(33, 5,"'" << http->uri << "'");
936
937 if (Config.accessList.store_id) {
938 acl_checklist = clientAclChecklistCreate(Config.accessList.store_id, http);
939 acl_checklist->nonBlockingCheck(clientStoreIdAccessCheckDone, this);
940 } else
941 storeIdStart(http, clientStoreIdDoneWrapper, this);
942}
943
edce4d98 944static int
59a1efb2 945clientHierarchical(ClientHttpRequest * http)
edce4d98 946{
190154cf 947 HttpRequest *request = http->request;
60745f24 948 HttpRequestMethod method = request->method;
edce4d98 949
2962f8b8 950 // intercepted requests MUST NOT (yet) be sent to peers unless verified
0d901ef4 951 if (!request->flags.hostVerified && (request->flags.intercepted || request->flags.interceptTproxy))
2962f8b8
AJ
952 return 0;
953
69660be0 954 /*
955 * IMS needs a private key, so we can use the hierarchy for IMS only if our
956 * neighbors support private keys
957 */
62e76326 958
45e5102d 959 if (request->flags.ims && !neighbors_do_private_keys)
62e76326 960 return 0;
961
69660be0 962 /*
963 * This is incorrect: authenticating requests can be sent via a hierarchy
06b97e72 964 * (they can even be cached if the correct headers are set on the reply)
edce4d98 965 */
45e5102d 966 if (request->flags.auth)
62e76326 967 return 0;
968
c2a7cefd 969 if (method == Http::METHOD_TRACE)
62e76326 970 return 1;
971
c2a7cefd 972 if (method != Http::METHOD_GET)
62e76326 973 return 0;
974
450fe1cb 975 if (request->flags.loopDetected)
62e76326 976 return 0;
977
4e3f4dc7 978 if (request->url.getScheme() == AnyP::PROTO_HTTP)
c2a7cefd 979 return method.respMaybeCacheable();
62e76326 980
4e3f4dc7 981 if (request->url.getScheme() == AnyP::PROTO_GOPHER)
62e76326 982 return gopherCachable(request);
983
4e3f4dc7 984 if (request->url.getScheme() == AnyP::PROTO_CACHE_OBJECT)
62e76326 985 return 0;
986
edce4d98 987 return 1;
988}
989
46a1f562
HN
990static void
991clientCheckPinning(ClientHttpRequest * http)
992{
993 HttpRequest *request = http->request;
994 HttpHeader *req_hdr = &request->header;
995 ConnStateData *http_conn = http->getConn();
996
997 /* Internal requests such as those from ESI includes may be without
998 * a client connection
999 */
1000 if (!http_conn)
f54f527e 1001 return;
46a1f562 1002
450fe1cb
FC
1003 request->flags.connectionAuthDisabled = http_conn->port->connection_auth_disabled;
1004 if (!request->flags.connectionAuthDisabled) {
73c36fd9 1005 if (Comm::IsConnOpen(http_conn->pinning.serverConnection)) {
46a1f562 1006 if (http_conn->pinning.auth) {
e857372a
FC
1007 request->flags.connectionAuth = true;
1008 request->flags.auth = true;
46a1f562 1009 } else {
e857372a 1010 request->flags.connectionProxyAuth = true;
46a1f562 1011 }
b1cf2350
AJ
1012 // These should already be linked correctly.
1013 assert(request->clientConnectionManager == http_conn);
46a1f562
HN
1014 }
1015 }
1016
1017 /* check if connection auth is used, and flag as candidate for pinning
45e5102d 1018 * in such case.
450fe1cb 1019 * Note: we may need to set flags.connectionAuth even if the connection
46a1f562
HN
1020 * is already pinned if it was pinned earlier due to proxy auth
1021 */
450fe1cb 1022 if (!request->flags.connectionAuth) {
789217a2 1023 if (req_hdr->has(Http::HdrType::AUTHORIZATION) || req_hdr->has(Http::HdrType::PROXY_AUTHORIZATION)) {
46a1f562
HN
1024 HttpHeaderPos pos = HttpHeaderInitPos;
1025 HttpHeaderEntry *e;
1026 int may_pin = 0;
1027 while ((e = req_hdr->getEntry(&pos))) {
789217a2 1028 if (e->id == Http::HdrType::AUTHORIZATION || e->id == Http::HdrType::PROXY_AUTHORIZATION) {
46a1f562
HN
1029 const char *value = e->value.rawBuf();
1030 if (strncasecmp(value, "NTLM ", 5) == 0
1031 ||
1032 strncasecmp(value, "Negotiate ", 10) == 0
1033 ||
1034 strncasecmp(value, "Kerberos ", 9) == 0) {
789217a2 1035 if (e->id == Http::HdrType::AUTHORIZATION) {
e857372a 1036 request->flags.connectionAuth = true;
46a1f562
HN
1037 may_pin = 1;
1038 } else {
e857372a 1039 request->flags.connectionProxyAuth = true;
46a1f562
HN
1040 may_pin = 1;
1041 }
1042 }
1043 }
1044 }
1045 if (may_pin && !request->pinnedConnection()) {
b1cf2350
AJ
1046 // These should already be linked correctly. Just need the ServerConnection to pinn.
1047 assert(request->clientConnectionManager == http_conn);
46a1f562
HN
1048 }
1049 }
1050 }
1051}
1052
edce4d98 1053static void
59a1efb2 1054clientInterpretRequestHeaders(ClientHttpRequest * http)
edce4d98 1055{
190154cf 1056 HttpRequest *request = http->request;
0ef77270 1057 HttpHeader *req_hdr = &request->header;
5086523e 1058 bool no_cache = false;
62e76326 1059
edce4d98 1060 request->imslen = -1;
789217a2 1061 request->ims = req_hdr->getTime(Http::HdrType::IF_MODIFIED_SINCE);
62e76326 1062
edce4d98 1063 if (request->ims > 0)
e857372a 1064 request->flags.ims = true;
62e76326 1065
450fe1cb 1066 if (!request->flags.ignoreCc) {
47fbd2a7 1067 if (request->cache_control) {
1259f9cf 1068 if (request->cache_control->hasNoCache())
5086523e 1069 no_cache=true;
62e76326 1070
adc2a453 1071 // RFC 2616: treat Pragma:no-cache as if it was Cache-Control:no-cache when Cache-Control is missing
789217a2
FC
1072 } else if (req_hdr->has(Http::HdrType::PRAGMA))
1073 no_cache = req_hdr->hasListMember(Http::HdrType::PRAGMA,"no-cache",',');
edce4d98 1074 }
914b89a2 1075
c2a7cefd 1076 if (request->method == Http::METHOD_OTHER) {
5086523e 1077 no_cache=true;
60745f24 1078 }
62e76326 1079
edce4d98 1080 if (no_cache) {
626096be 1081#if USE_HTTP_VIOLATIONS
62e76326 1082
1083 if (Config.onoff.reload_into_ims)
e857372a 1084 request->flags.nocacheHack = true;
62e76326 1085 else if (refresh_nocache_hack)
e857372a 1086 request->flags.nocacheHack = true;
62e76326 1087 else
edce4d98 1088#endif
62e76326 1089
e857372a 1090 request->flags.noCache = true;
edce4d98 1091 }
62e76326 1092
0ef77270 1093 /* ignore range header in non-GETs or non-HEADs */
c2a7cefd 1094 if (request->method == Http::METHOD_GET || request->method == Http::METHOD_HEAD) {
56713d9a
AR
1095 // XXX: initialize if we got here without HttpRequest::parseHeader()
1096 if (!request->range)
1097 request->range = req_hdr->getRange();
62e76326 1098
1099 if (request->range) {
e857372a 1100 request->flags.isRanged = true;
62e76326 1101 clientStreamNode *node = (clientStreamNode *)http->client_stream.tail->data;
1102 /* XXX: This is suboptimal. We should give the stream the range set,
1103 * and thereby let the top of the stream set the offset when the
26ac0430 1104 * size becomes known. As it is, we will end up requesting from 0
62e76326 1105 * for evey -X range specification.
1106 * RBC - this may be somewhat wrong. We should probably set the range
1107 * iter up at this point.
1108 */
1109 node->readBuffer.offset = request->range->lowestOffset(0);
1110 http->range_iter.pos = request->range->begin();
24a8eaae 1111 http->range_iter.end = request->range->end();
62e76326 1112 http->range_iter.valid = true;
1113 }
edce4d98 1114 }
62e76326 1115
0ef77270 1116 /* Only HEAD and GET requests permit a Range or Request-Range header.
1117 * If these headers appear on any other type of request, delete them now.
1118 */
1119 else {
789217a2
FC
1120 req_hdr->delById(Http::HdrType::RANGE);
1121 req_hdr->delById(Http::HdrType::REQUEST_RANGE);
f0baf149 1122 request->ignoreRange("neither HEAD nor GET");
0ef77270 1123 }
1124
789217a2 1125 if (req_hdr->has(Http::HdrType::AUTHORIZATION))
e857372a 1126 request->flags.auth = true;
62e76326 1127
46a1f562 1128 clientCheckPinning(http);
d67acb4e 1129
92d6986d 1130 if (!request->url.userInfo().isEmpty())
e857372a 1131 request->flags.auth = true;
62e76326 1132
789217a2
FC
1133 if (req_hdr->has(Http::HdrType::VIA)) {
1134 String s = req_hdr->getList(Http::HdrType::VIA);
62e76326 1135 /*
3c4fcf0f 1136 * ThisCache cannot be a member of Via header, "1.1 ThisCache" can.
62e76326 1137 * Note ThisCache2 has a space prepended to the hostname so we don't
1138 * accidentally match super-domains.
1139 */
1140
1141 if (strListIsSubstr(&s, ThisCache2, ',')) {
1142 debugObj(33, 1, "WARNING: Forwarding loop detected for:\n",
1143 request, (ObjPackMethod) & httpRequestPack);
e857372a 1144 request->flags.loopDetected = true;
62e76326 1145 }
1146
21f6708d 1147#if USE_FORW_VIA_DB
bb790702 1148 fvdbCountVia(s.termedBuf());
62e76326 1149
edce4d98 1150#endif
62e76326 1151
30abd221 1152 s.clean();
edce4d98 1153 }
62e76326 1154
21f6708d 1155#if USE_FORW_VIA_DB
62e76326 1156
789217a2
FC
1157 if (req_hdr->has(Http::HdrType::X_FORWARDED_FOR)) {
1158 String s = req_hdr->getList(Http::HdrType::X_FORWARDED_FOR);
bb790702 1159 fvdbCountForw(s.termedBuf());
30abd221 1160 s.clean();
edce4d98 1161 }
62e76326 1162
edce4d98 1163#endif
62e76326 1164
c2a7cefd 1165 request->flags.cachable = http->request->maybeCacheable();
62e76326 1166
edce4d98 1167 if (clientHierarchical(http))
e857372a 1168 request->flags.hierarchical = true;
62e76326 1169
bf8fe701 1170 debugs(85, 5, "clientInterpretRequestHeaders: REQ_NOCACHE = " <<
450fe1cb 1171 (request->flags.noCache ? "SET" : "NOT SET"));
bf8fe701 1172 debugs(85, 5, "clientInterpretRequestHeaders: REQ_CACHABLE = " <<
45e5102d 1173 (request->flags.cachable ? "SET" : "NOT SET"));
bf8fe701 1174 debugs(85, 5, "clientInterpretRequestHeaders: REQ_HIERARCHICAL = " <<
45e5102d 1175 (request->flags.hierarchical ? "SET" : "NOT SET"));
62e76326 1176
edce4d98 1177}
1178
1179void
24438ec5 1180clientRedirectDoneWrapper(void *data, const Helper::Reply &result)
edce4d98 1181{
de31d06f 1182 ClientRequestContext *calloutContext = (ClientRequestContext *)data;
db02222f 1183
de31d06f 1184 if (!calloutContext->httpStateIsValid())
62e76326 1185 return;
62e76326 1186
de31d06f 1187 calloutContext->clientRedirectDone(result);
1188}
1189
a8a0b1c2 1190void
24438ec5 1191clientStoreIdDoneWrapper(void *data, const Helper::Reply &result)
a8a0b1c2
EC
1192{
1193 ClientRequestContext *calloutContext = (ClientRequestContext *)data;
1194
1195 if (!calloutContext->httpStateIsValid())
1196 return;
1197
1198 calloutContext->clientStoreIdDone(result);
1199}
1200
de31d06f 1201void
24438ec5 1202ClientRequestContext::clientRedirectDone(const Helper::Reply &reply)
de31d06f 1203{
190154cf 1204 HttpRequest *old_request = http->request;
e166785a 1205 debugs(85, 5, HERE << "'" << http->uri << "' result=" << reply);
de31d06f 1206 assert(redirect_state == REDIRECT_PENDING);
1207 redirect_state = REDIRECT_DONE;
62e76326 1208
cf9f0261 1209 // Put helper response Notes into the transaction state record (ALE) eventually
d06e17ea 1210 // do it early to ensure that no matter what the outcome the notes are present.
457857fe
CT
1211 if (http->al != NULL)
1212 (void)SyncNotes(*http->al, *old_request);
1213
1214 UpdateRequestNotes(http->getConn(), *old_request, reply.notes);
d06e17ea 1215
63fc9fb5 1216 switch (reply.result) {
32fd6d8a
CT
1217 case Helper::TimedOut:
1218 if (Config.onUrlRewriteTimeout.action != toutActBypass) {
1219 http->calloutsError(ERR_GATEWAY_FAILURE, ERR_DETAIL_REDIRECTOR_TIMEDOUT);
1220 debugs(85, DBG_IMPORTANT, "ERROR: URL rewrite helper: Timedout");
1221 }
1222 break;
1223
2428ce02
AJ
1224 case Helper::Unknown:
1225 case Helper::TT:
d06e17ea
AJ
1226 // Handler in redirect.cc should have already mapped Unknown
1227 // IF it contained valid entry for the old URL-rewrite helper protocol
1228 debugs(85, DBG_IMPORTANT, "ERROR: URL rewrite helper returned invalid result code. Wrong helper? " << reply);
1229 break;
1230
2428ce02 1231 case Helper::BrokenHelper:
32fd6d8a 1232 debugs(85, DBG_IMPORTANT, "ERROR: URL rewrite helper: " << reply);
d06e17ea
AJ
1233 break;
1234
2428ce02 1235 case Helper::Error:
d06e17ea
AJ
1236 // no change to be done.
1237 break;
62e76326 1238
2428ce02 1239 case Helper::Okay: {
d06e17ea
AJ
1240 // #1: redirect with a specific status code OK status=NNN url="..."
1241 // #2: redirect with a default status code OK url="..."
1242 // #3: re-write the URL OK rewrite-url="..."
1243
cf9f0261
CT
1244 const char *statusNote = reply.notes.findFirst("status");
1245 const char *urlNote = reply.notes.findFirst("url");
d06e17ea
AJ
1246
1247 if (urlNote != NULL) {
1248 // HTTP protocol redirect to be done.
1249
1250 // TODO: change default redirect status for appropriate requests
1251 // Squid defaults to 302 status for now for better compatibility with old clients.
f11c8e2f 1252 // HTTP/1.0 client should get 302 (Http::scFound)
955394ce
AJ
1253 // HTTP/1.1 client contacting reverse-proxy should get 307 (Http::scTemporaryRedirect)
1254 // HTTP/1.1 client being diverted by forward-proxy should get 303 (Http::scSeeOther)
f11c8e2f 1255 Http::StatusCode status = Http::scFound;
d06e17ea 1256 if (statusNote != NULL) {
cf9f0261 1257 const char * result = statusNote;
955394ce 1258 status = static_cast<Http::StatusCode>(atoi(result));
d06e17ea 1259 }
62e76326 1260
955394ce 1261 if (status == Http::scMovedPermanently
f11c8e2f 1262 || status == Http::scFound
955394ce
AJ
1263 || status == Http::scSeeOther
1264 || status == Http::scPermanentRedirect
1265 || status == Http::scTemporaryRedirect) {
62e76326 1266 http->redirect.status = status;
cf9f0261 1267 http->redirect.location = xstrdup(urlNote);
e5b677f0 1268 // TODO: validate the URL produced here is RFC 2616 compliant absolute URI
62e76326 1269 } else {
cf9f0261 1270 debugs(85, DBG_CRITICAL, "ERROR: URL-rewrite produces invalid " << status << " redirect Location: " << urlNote);
62e76326 1271 }
d06e17ea
AJ
1272 } else {
1273 // URL-rewrite wanted. Ew.
cf9f0261 1274 urlNote = reply.notes.findFirst("rewrite-url");
d06e17ea
AJ
1275
1276 // prevent broken helpers causing too much damage. If old URL == new URL skip the re-write.
cf9f0261 1277 if (urlNote != NULL && strcmp(urlNote, http->uri)) {
d06e17ea
AJ
1278 // XXX: validate the URL properly *without* generating a whole new request object right here.
1279 // XXX: the clone() should be done only AFTER we know the new URL is valid.
1280 HttpRequest *new_request = old_request->clone();
cf9f0261 1281 if (urlParse(old_request->method, const_cast<char*>(urlNote), new_request)) {
851feda6 1282 debugs(61, 2, "URL-rewriter diverts URL from " << old_request->effectiveRequestUri() << " to " << new_request->effectiveRequestUri());
d06e17ea
AJ
1283
1284 // update the new request to flag the re-writing was done on it
e857372a 1285 new_request->flags.redirected = true;
d06e17ea
AJ
1286
1287 // unlink bodypipe from the old request. Not needed there any longer.
1288 if (old_request->body_pipe != NULL) {
1289 old_request->body_pipe = NULL;
1290 debugs(61,2, HERE << "URL-rewriter diverts body_pipe " << new_request->body_pipe <<
1291 " from request " << old_request << " to " << new_request);
1292 }
9be14530 1293
d06e17ea 1294 // update the current working ClientHttpRequest fields
3f0e38d6
AJ
1295 xfree(http->uri);
1296 http->uri = SBufToCstring(new_request->effectiveRequestUri());
d06e17ea 1297 HTTPMSGUNLOCK(old_request);
b248c2a3
AJ
1298 http->request = new_request;
1299 HTTPMSGLOCK(http->request);
d06e17ea
AJ
1300 } else {
1301 debugs(85, DBG_CRITICAL, "ERROR: URL-rewrite produces invalid request: " <<
cf9f0261 1302 old_request->method << " " << urlNote << " " << old_request->http_ver);
d06e17ea
AJ
1303 delete new_request;
1304 }
9be14530 1305 }
74b48915 1306 }
edce4d98 1307 }
d06e17ea
AJ
1308 break;
1309 }
62e76326 1310
edce4d98 1311 /* FIXME PIPELINE: This is innacurate during pipelining */
62e76326 1312
73c36fd9
AJ
1313 if (http->getConn() != NULL && Comm::IsConnOpen(http->getConn()->clientConnection))
1314 fd_note(http->getConn()->clientConnection->fd, http->uri);
62e76326 1315
c8be6d7b 1316 assert(http->uri);
62e76326 1317
de31d06f 1318 http->doCallouts();
edce4d98 1319}
1320
a8a0b1c2
EC
1321/**
1322 * This method handles the different replies from StoreID helper.
1323 */
1324void
24438ec5 1325ClientRequestContext::clientStoreIdDone(const Helper::Reply &reply)
a8a0b1c2
EC
1326{
1327 HttpRequest *old_request = http->request;
1328 debugs(85, 5, "'" << http->uri << "' result=" << reply);
1329 assert(store_id_state == REDIRECT_PENDING);
1330 store_id_state = REDIRECT_DONE;
1331
cf9f0261 1332 // Put helper response Notes into the transaction state record (ALE) eventually
a8a0b1c2 1333 // do it early to ensure that no matter what the outcome the notes are present.
457857fe
CT
1334 if (http->al != NULL)
1335 (void)SyncNotes(*http->al, *old_request);
1336
1337 UpdateRequestNotes(http->getConn(), *old_request, reply.notes);
a8a0b1c2
EC
1338
1339 switch (reply.result) {
2428ce02
AJ
1340 case Helper::Unknown:
1341 case Helper::TT:
a8a0b1c2
EC
1342 // Handler in redirect.cc should have already mapped Unknown
1343 // IF it contained valid entry for the old helper protocol
1344 debugs(85, DBG_IMPORTANT, "ERROR: storeID helper returned invalid result code. Wrong helper? " << reply);
1345 break;
1346
32fd6d8a 1347 case Helper::TimedOut:
f53969cc 1348 // Timeouts for storeID are not implemented
2428ce02 1349 case Helper::BrokenHelper:
32fd6d8a 1350 debugs(85, DBG_IMPORTANT, "ERROR: storeID helper: " << reply);
a8a0b1c2
EC
1351 break;
1352
2428ce02 1353 case Helper::Error:
a8a0b1c2
EC
1354 // no change to be done.
1355 break;
1356
2428ce02 1357 case Helper::Okay: {
cf9f0261 1358 const char *urlNote = reply.notes.findFirst("store-id");
a8a0b1c2
EC
1359
1360 // prevent broken helpers causing too much damage. If old URL == new URL skip the re-write.
cf9f0261 1361 if (urlNote != NULL && strcmp(urlNote, http->uri) ) {
a8a0b1c2 1362 // Debug section required for some very specific cases.
cf9f0261
CT
1363 debugs(85, 9, "Setting storeID with: " << urlNote );
1364 http->request->store_id = urlNote;
1365 http->store_id = urlNote;
a8a0b1c2
EC
1366 }
1367 }
1368 break;
1369 }
1370
1371 http->doCallouts();
1372}
1373
b50e327b
AJ
1374/** Test cache allow/deny configuration
1375 * Sets flags.cachable=1 if caching is not denied.
1376 */
edce4d98 1377void
8e2745f4 1378ClientRequestContext::checkNoCache()
edce4d98 1379{
b50e327b
AJ
1380 if (Config.accessList.noCache) {
1381 acl_checklist = clientAclChecklistCreate(Config.accessList.noCache, http);
1382 acl_checklist->nonBlockingCheck(checkNoCacheDoneWrapper, this);
1383 } else {
1384 /* unless otherwise specified, we try to cache. */
2efeb0b7 1385 checkNoCacheDone(ACCESS_ALLOWED);
b50e327b 1386 }
edce4d98 1387}
1388
de31d06f 1389static void
2efeb0b7 1390checkNoCacheDoneWrapper(allow_t answer, void *data)
edce4d98 1391{
de31d06f 1392 ClientRequestContext *calloutContext = (ClientRequestContext *) data;
e4a67a80 1393
de31d06f 1394 if (!calloutContext->httpStateIsValid())
1395 return;
1396
1397 calloutContext->checkNoCacheDone(answer);
8e2745f4 1398}
4fb35c3c 1399
8e2745f4 1400void
2efeb0b7 1401ClientRequestContext::checkNoCacheDone(const allow_t &answer)
62e76326 1402{
8e2745f4 1403 acl_checklist = NULL;
45e5102d 1404 http->request->flags.cachable = (answer == ACCESS_ALLOWED);
de31d06f 1405 http->doCallouts();
edce4d98 1406}
1407
cb4f4424 1408#if USE_OPENSSL
e0c0d54c
CT
1409bool
1410ClientRequestContext::sslBumpAccessCheck()
1411{
08097970
AR
1412 // If SSL connection tunneling or bumping decision has been made, obey it.
1413 const Ssl::BumpMode bumpMode = http->getConn()->sslBumpMode;
1414 if (bumpMode != Ssl::bumpEnd) {
1415 debugs(85, 5, HERE << "SslBump already decided (" << bumpMode <<
1416 "), " << "ignoring ssl_bump for " << http->getConn());
b4049e38
CT
1417 if (!http->getConn()->serverBump())
1418 http->sslBumpNeed(bumpMode); // for processRequest() to bump if needed and not already bumped
71cae389 1419 http->al->ssl.bumpMode = bumpMode; // inherited from bumped connection
08097970
AR
1420 return false;
1421 }
e0c0d54c 1422
08097970
AR
1423 // If we have not decided yet, decide whether to bump now.
1424
1425 // Bumping here can only start with a CONNECT request on a bumping port
1426 // (bumping of intercepted SSL conns is decided before we get 1st request).
1427 // We also do not bump redirected CONNECT requests.
c2a7cefd 1428 if (http->request->method != Http::METHOD_CONNECT || http->redirect.status ||
6a25a046
FC
1429 !Config.accessList.ssl_bump ||
1430 !http->getConn()->port->flags.tunnelSslBumping) {
71cae389 1431 http->al->ssl.bumpMode = Ssl::bumpEnd; // SslBump does not apply; log -
08097970 1432 debugs(85, 5, HERE << "cannot SslBump this request");
e0c0d54c
CT
1433 return false;
1434 }
08097970
AR
1435
1436 // Do not bump during authentication: clients would not proxy-authenticate
1437 // if we delay a 407 response and respond with 200 OK to CONNECT.
955394ce 1438 if (error && error->httpStatus == Http::scProxyAuthenticationRequired) {
71cae389 1439 http->al->ssl.bumpMode = Ssl::bumpEnd; // SslBump does not apply; log -
08097970
AR
1440 debugs(85, 5, HERE << "no SslBump during proxy authentication");
1441 return false;
1442 }
1443
1444 debugs(85, 5, HERE << "SslBump possible, checking ACL");
1445
eb898410
AJ
1446 ACLFilledChecklist *aclChecklist = clientAclChecklistCreate(Config.accessList.ssl_bump, http);
1447 aclChecklist->nonBlockingCheck(sslBumpAccessCheckDoneWrapper, this);
08097970 1448 return true;
e0c0d54c
CT
1449}
1450
f8901ea9 1451/**
e0c0d54c
CT
1452 * A wrapper function to use the ClientRequestContext::sslBumpAccessCheckDone method
1453 * as ACLFilledChecklist callback
1454 */
1455static void
2efeb0b7 1456sslBumpAccessCheckDoneWrapper(allow_t answer, void *data)
e0c0d54c
CT
1457{
1458 ClientRequestContext *calloutContext = static_cast<ClientRequestContext *>(data);
9d5e7196
AJ
1459
1460 if (!calloutContext->httpStateIsValid())
1461 return;
ed6163ef 1462 calloutContext->sslBumpAccessCheckDone(answer);
e0c0d54c
CT
1463}
1464
1465void
ed6163ef 1466ClientRequestContext::sslBumpAccessCheckDone(const allow_t &answer)
e0c0d54c 1467{
ed6163ef
AJ
1468 if (!httpStateIsValid())
1469 return;
1470
08097970 1471 const Ssl::BumpMode bumpMode = answer == ACCESS_ALLOWED ?
87f237a9 1472 static_cast<Ssl::BumpMode>(answer.kind) : Ssl::bumpNone;
08097970 1473 http->sslBumpNeed(bumpMode); // for processRequest() to bump if needed
71cae389 1474 http->al->ssl.bumpMode = bumpMode; // for logging
caf3666d 1475
e0c0d54c
CT
1476 http->doCallouts();
1477}
1478#endif
1479
69660be0 1480/*
1481 * Identify requests that do not go through the store and client side stream
1482 * and forward them to the appropriate location. All other requests, request
1483 * them.
edce4d98 1484 */
1485void
8e2745f4 1486ClientHttpRequest::processRequest()
edce4d98 1487{
7f06a3d8 1488 debugs(85, 4, request->method << ' ' << uri);
62e76326 1489
c2a7cefd 1490 if (request->method == Http::METHOD_CONNECT && !redirect.status) {
cb4f4424 1491#if USE_OPENSSL
31281814
AJ
1492 if (sslBumpNeeded()) {
1493 sslBumpStart();
1494 return;
1495 }
3712be3f 1496#endif
f84dd7eb 1497 getConn()->stopReading(); // tunnels read for themselves
ac9f46af 1498 tunnelStart(this);
62e76326 1499 return;
edce4d98 1500 }
62e76326 1501
8e2745f4 1502 httpStart();
1503}
1504
1505void
1506ClientHttpRequest::httpStart()
1507{
559da936 1508 PROF_start(httpStart);
8e2745f4 1509 logType = LOG_TAG_NONE;
91369933 1510 debugs(85, 4, logType.c_str() << " for '" << uri << "'");
bf8fe701 1511
edce4d98 1512 /* no one should have touched this */
8e2745f4 1513 assert(out.offset == 0);
edce4d98 1514 /* Use the Stream Luke */
8e2745f4 1515 clientStreamNode *node = (clientStreamNode *)client_stream.tail->data;
1516 clientStreamRead(node, this, node->readBuffer);
559da936 1517 PROF_stop(httpStart);
edce4d98 1518}
0655fa4d 1519
cb4f4424 1520#if USE_OPENSSL
3712be3f 1521
e0c0d54c 1522void
08097970 1523ClientHttpRequest::sslBumpNeed(Ssl::BumpMode mode)
e0c0d54c 1524{
caf3666d 1525 debugs(83, 3, HERE << "sslBump required: "<< Ssl::bumpMode(mode));
08097970 1526 sslBumpNeed_ = mode;
3712be3f 1527}
1528
1529// called when comm_write has completed
1530static void
c8407295 1531SslBumpEstablish(const Comm::ConnectionPointer &, char *, size_t, Comm::Flag errflag, int, void *data)
3712be3f 1532{
1533 ClientHttpRequest *r = static_cast<ClientHttpRequest*>(data);
1534 debugs(85, 5, HERE << "responded to CONNECT: " << r << " ? " << errflag);
1535
1536 assert(r && cbdataReferenceValid(r));
1537 r->sslBumpEstablish(errflag);
1538}
1539
1540void
c8407295 1541ClientHttpRequest::sslBumpEstablish(Comm::Flag errflag)
3712be3f 1542{
c8407295
AJ
1543 // Bail out quickly on Comm::ERR_CLOSING - close handlers will tidy up
1544 if (errflag == Comm::ERR_CLOSING)
3712be3f 1545 return;
1546
1547 if (errflag) {
1fa35be8 1548 debugs(85, 3, HERE << "CONNECT response failure in SslBump: " << errflag);
bbc83914 1549 getConn()->clientConnection->close();
3712be3f 1550 return;
1551 }
1552
40d8be97
AR
1553 // We lack HttpReply which logRequest() uses to log the status code.
1554 // TODO: Use HttpReply instead of the "200 Connection established" string.
71cae389 1555 al->http.code = 200;
40d8be97 1556
21512911
CT
1557#if USE_AUTH
1558 // Preserve authentication info for the ssl-bumped request
1559 if (request->auth_user_request != NULL)
cc1e110a 1560 getConn()->setAuth(request->auth_user_request, "SSL-bumped CONNECT");
21512911 1561#endif
03f00a11 1562
08097970
AR
1563 assert(sslBumpNeeded());
1564 getConn()->switchToHttps(request, sslBumpNeed_);
3712be3f 1565}
1566
1567void
1568ClientHttpRequest::sslBumpStart()
1569{
08097970
AR
1570 debugs(85, 5, HERE << "Confirming " << Ssl::bumpMode(sslBumpNeed_) <<
1571 "-bumped CONNECT tunnel on FD " << getConn()->clientConnection);
1572 getConn()->sslBumpMode = sslBumpNeed_;
3712be3f 1573
9e104535 1574 AsyncCall::Pointer bumpCall = commCbCall(85, 5, "ClientSocketContext::sslBumpEstablish",
f53969cc 1575 CommIoCbPtrFun(&SslBumpEstablish, this));
9e104535
CT
1576
1577 if (request->flags.interceptTproxy || request->flags.intercepted) {
1578 CommIoCbParams &params = GetCommParams<CommIoCbParams>(bumpCall);
1579 params.flag = Comm::OK;
1580 params.conn = getConn()->clientConnection;
1581 ScheduleCallHere(bumpCall);
1582 return;
1583 }
1584
08097970 1585 // send an HTTP 200 response to kick client SSL negotiation
3712be3f 1586 // TODO: Unify with tunnel.cc and add a Server(?) header
b0388924 1587 static const char *const conn_established = "HTTP/1.1 200 Connection established\r\n\r\n";
9e104535 1588 Comm::Write(getConn()->clientConnection, conn_established, strlen(conn_established), bumpCall, NULL);
3712be3f 1589}
1590
1591#endif
1592
0655fa4d 1593bool
1594ClientHttpRequest::gotEnough() const
1595{
86a2f789 1596 /** TODO: should be querying the stream. */
7173d5b0 1597 int64_t contentLength =
06a5ae20 1598 memObject()->getReply()->bodySize(request->method);
0655fa4d 1599 assert(contentLength >= 0);
1600
1601 if (out.offset < contentLength)
1602 return false;
1603
1604 return true;
1605}
1606
86a2f789 1607void
1608ClientHttpRequest::storeEntry(StoreEntry *newEntry)
1609{
1610 entry_ = newEntry;
1611}
1612
0976f8db 1613void
1614ClientHttpRequest::loggingEntry(StoreEntry *newEntry)
1615{
1616 if (loggingEntry_)
1bfe9ade 1617 loggingEntry_->unlock("ClientHttpRequest::loggingEntry");
0976f8db 1618
1619 loggingEntry_ = newEntry;
1620
1621 if (loggingEntry_)
1bfe9ade 1622 loggingEntry_->lock("ClientHttpRequest::loggingEntry");
0976f8db 1623}
86a2f789 1624
de31d06f 1625/*
1626 * doCallouts() - This function controls the order of "callout"
1627 * executions, including non-blocking access control checks, the
1628 * redirector, and ICAP. Previously, these callouts were chained
1629 * together such that "clientAccessCheckDone()" would call
1630 * "clientRedirectStart()" and so on.
1631 *
1632 * The ClientRequestContext (aka calloutContext) class holds certain
1633 * state data for the callout/callback operations. Previously
1634 * ClientHttpRequest would sort of hand off control to ClientRequestContext
1635 * for a short time. ClientRequestContext would then delete itself
1636 * and pass control back to ClientHttpRequest when all callouts
1637 * were finished.
1638 *
1639 * This caused some problems for ICAP because we want to make the
1640 * ICAP callout after checking ACLs, but before checking the no_cache
1641 * list. We can't stuff the ICAP state into the ClientRequestContext
1642 * class because we still need the ICAP state after ClientRequestContext
1643 * goes away.
1644 *
1645 * Note that ClientRequestContext is created before the first call
1646 * to doCallouts().
1647 *
1648 * If one of the callouts notices that ClientHttpRequest is no
1649 * longer valid, it should call cbdataReferenceDone() so that
1650 * ClientHttpRequest's reference count goes to zero and it will get
1651 * deleted. ClientHttpRequest will then delete ClientRequestContext.
1652 *
1653 * Note that we set the _done flags here before actually starting
1654 * the callout. This is strictly for convenience.
1655 */
1656
82afb125
FC
1657tos_t aclMapTOS (acl_tos * head, ACLChecklist * ch);
1658nfmark_t aclMapNfmark (acl_nfmark * head, ACLChecklist * ch);
057f5854 1659
de31d06f 1660void
1661ClientHttpRequest::doCallouts()
1662{
1663 assert(calloutContext);
1664
6fca33e0 1665 /*Save the original request for logging purposes*/
b248c2a3
AJ
1666 if (!calloutContext->http->al->request) {
1667 calloutContext->http->al->request = request;
1668 HTTPMSGLOCK(calloutContext->http->al->request);
457857fe
CT
1669
1670 NotePairs &notes = SyncNotes(*calloutContext->http->al, *calloutContext->http->request);
1671 // Make the previously set client connection ID available as annotation.
1672 if (ConnStateData *csd = calloutContext->http->getConn()) {
1673 if (!csd->connectionTag().isEmpty())
1674 notes.add("clt_conn_tag", SBuf(csd->connectionTag()).c_str());
1675 }
b248c2a3 1676 }
6fca33e0 1677
38450a50 1678 if (!calloutContext->error) {
87f237a9 1679 // CVE-2009-0801: verify the Host: header is consistent with other known details.
38450a50
CT
1680 if (!calloutContext->host_header_verify_done) {
1681 debugs(83, 3, HERE << "Doing calloutContext->hostHeaderVerify()");
1682 calloutContext->host_header_verify_done = true;
1683 calloutContext->hostHeaderVerify();
1684 return;
1685 }
fe97983f 1686
38450a50
CT
1687 if (!calloutContext->http_access_done) {
1688 debugs(83, 3, HERE << "Doing calloutContext->clientAccessCheck()");
1689 calloutContext->http_access_done = true;
1690 calloutContext->clientAccessCheck();
1691 return;
1692 }
de31d06f 1693
a83c6ed6 1694#if USE_ADAPTATION
38450a50
CT
1695 if (!calloutContext->adaptation_acl_check_done) {
1696 calloutContext->adaptation_acl_check_done = true;
1697 if (Adaptation::AccessCheck::Start(
87f237a9 1698 Adaptation::methodReqmod, Adaptation::pointPreCache,
af0ded40 1699 request, NULL, calloutContext->http->al, this))
38450a50
CT
1700 return; // will call callback
1701 }
de31d06f 1702#endif
1703
38450a50
CT
1704 if (!calloutContext->redirect_done) {
1705 calloutContext->redirect_done = true;
de31d06f 1706
38450a50
CT
1707 if (Config.Program.redirect) {
1708 debugs(83, 3, HERE << "Doing calloutContext->clientRedirectStart()");
1709 calloutContext->redirect_state = REDIRECT_PENDING;
1710 calloutContext->clientRedirectStart();
1711 return;
1712 }
de31d06f 1713 }
de31d06f 1714
38450a50
CT
1715 if (!calloutContext->adapted_http_access_done) {
1716 debugs(83, 3, HERE << "Doing calloutContext->clientAccessCheck2()");
1717 calloutContext->adapted_http_access_done = true;
1718 calloutContext->clientAccessCheck2();
1719 return;
1720 }
533493da 1721
a8a0b1c2
EC
1722 if (!calloutContext->store_id_done) {
1723 calloutContext->store_id_done = true;
a8a0b1c2
EC
1724
1725 if (Config.Program.store_id) {
1726 debugs(83, 3,"Doing calloutContext->clientStoreIdStart()");
1727 calloutContext->store_id_state = REDIRECT_PENDING;
1728 calloutContext->clientStoreIdStart();
1729 return;
1730 }
1731 }
1732
38450a50
CT
1733 if (!calloutContext->interpreted_req_hdrs) {
1734 debugs(83, 3, HERE << "Doing clientInterpretRequestHeaders()");
1735 calloutContext->interpreted_req_hdrs = 1;
1736 clientInterpretRequestHeaders(this);
1737 }
57abaac0 1738
38450a50
CT
1739 if (!calloutContext->no_cache_done) {
1740 calloutContext->no_cache_done = true;
de31d06f 1741
45e5102d 1742 if (Config.accessList.noCache && request->flags.cachable) {
38450a50
CT
1743 debugs(83, 3, HERE << "Doing calloutContext->checkNoCache()");
1744 calloutContext->checkNoCache();
1745 return;
1746 }
de31d06f 1747 }
38450a50 1748 } // if !calloutContext->error
de31d06f 1749
425de4c8
AJ
1750 if (!calloutContext->tosToClientDone) {
1751 calloutContext->tosToClientDone = true;
73c36fd9 1752 if (getConn() != NULL && Comm::IsConnOpen(getConn()->clientConnection)) {
c0941a6a 1753 ACLFilledChecklist ch(NULL, request, NULL);
057f5854 1754 ch.src_addr = request->client_addr;
1755 ch.my_addr = request->my_addr;
425de4c8 1756 tos_t tos = aclMapTOS(Ip::Qos::TheConfig.tosToClient, &ch);
3712be3f 1757 if (tos)
73c36fd9 1758 Ip::Qos::setSockTos(getConn()->clientConnection, tos);
425de4c8
AJ
1759 }
1760 }
1761
1762 if (!calloutContext->nfmarkToClientDone) {
1763 calloutContext->nfmarkToClientDone = true;
73c36fd9 1764 if (getConn() != NULL && Comm::IsConnOpen(getConn()->clientConnection)) {
425de4c8
AJ
1765 ACLFilledChecklist ch(NULL, request, NULL);
1766 ch.src_addr = request->client_addr;
1767 ch.my_addr = request->my_addr;
1768 nfmark_t mark = aclMapNfmark(Ip::Qos::TheConfig.nfmarkToClient, &ch);
1769 if (mark)
73c36fd9 1770 Ip::Qos::setSockNfmark(getConn()->clientConnection, mark);
3712be3f 1771 }
057f5854 1772 }
1773
cb4f4424 1774#if USE_OPENSSL
7a957a93
AR
1775 // We need to check for SslBump even if the calloutContext->error is set
1776 // because bumping may require delaying the error until after CONNECT.
e0c0d54c
CT
1777 if (!calloutContext->sslBumpCheckDone) {
1778 calloutContext->sslBumpCheckDone = true;
1779 if (calloutContext->sslBumpAccessCheck())
1780 return;
1781 /* else no ssl bump required*/
1782 }
d2565320 1783#endif
e0c0d54c 1784
2bd84e5f 1785 if (calloutContext->error) {
851feda6
AJ
1786 // XXX: prformance regression. c_str() reallocates
1787 SBuf storeUri(request->storeId());
1788 StoreEntry *e = storeCreateEntry(storeUri.c_str(), storeUri.c_str(), request->flags, request->method);
cb4f4424 1789#if USE_OPENSSL
08097970 1790 if (sslBumpNeeded()) {
9e104535
CT
1791 // We have to serve an error, so bump the client first.
1792 sslBumpNeed(Ssl::bumpClientFirst);
2bd84e5f
CT
1793 // set final error but delay sending until we bump
1794 Ssl::ServerBump *srvBump = new Ssl::ServerBump(request, e);
1795 errorAppendEntry(e, calloutContext->error);
1796 calloutContext->error = NULL;
1797 getConn()->setServerBump(srvBump);
1bfe9ade 1798 e->unlock("ClientHttpRequest::doCallouts+sslBumpNeeded");
87f237a9 1799 } else
2bd84e5f
CT
1800#endif
1801 {
7a957a93 1802 // send the error to the client now
2bd84e5f
CT
1803 clientStreamNode *node = (clientStreamNode *)client_stream.tail->prev->data;
1804 clientReplyContext *repContext = dynamic_cast<clientReplyContext *>(node->data.getRaw());
1805 assert (repContext);
f0baf149 1806 repContext->setReplyToStoreEntry(e, "immediate SslBump error");
2bd84e5f
CT
1807 errorAppendEntry(e, calloutContext->error);
1808 calloutContext->error = NULL;
1809 if (calloutContext->readNextRequest)
1810 getConn()->flags.readMore = true; // resume any pipeline reads.
1811 node = (clientStreamNode *)client_stream.tail->data;
1812 clientStreamRead(node, this, node->readBuffer);
1bfe9ade 1813 e->unlock("ClientHttpRequest::doCallouts-sslBumpNeeded");
2bd84e5f
CT
1814 return;
1815 }
1816 }
1817
de31d06f 1818 cbdataReferenceDone(calloutContext->http);
1819 delete calloutContext;
1820 calloutContext = NULL;
de31d06f 1821#if HEADERS_LOG
1822
1823 headersLog(0, 1, request->method, request);
1824#endif
1825
58d7150d 1826 debugs(83, 3, HERE << "calling processRequest()");
de31d06f 1827 processRequest();
3ff65596
AR
1828
1829#if ICAP_CLIENT
1830 Adaptation::Icap::History::Pointer ih = request->icapHistory();
1831 if (ih != NULL)
1832 ih->logType = logType;
1833#endif
de31d06f 1834}
1835
32d002cb 1836#if !_USE_INLINE_
86a2f789 1837#include "client_side_request.cci"
1838#endif
de31d06f 1839
a83c6ed6 1840#if USE_ADAPTATION
a22e6cd3
AR
1841/// Initiate an asynchronous adaptation transaction which will call us back.
1842void
1843ClientHttpRequest::startAdaptation(const Adaptation::ServiceGroupPointer &g)
3b299123 1844{
a22e6cd3 1845 debugs(85, 3, HERE << "adaptation needed for " << this);
a83c6ed6
AR
1846 assert(!virginHeadSource);
1847 assert(!adaptedBodySource);
a22e6cd3 1848 virginHeadSource = initiateAdaptation(
af0ded40 1849 new Adaptation::Iterator(request, NULL, al, g));
a83c6ed6 1850
e1381638 1851 // we could try to guess whether we can bypass this adaptation
a22e6cd3 1852 // initiation failure, but it should not really happen
4299f876 1853 Must(initiated(virginHeadSource));
de31d06f 1854}
1855
1856void
3af10ac0 1857ClientHttpRequest::noteAdaptationAnswer(const Adaptation::Answer &answer)
de31d06f 1858{
f53969cc 1859 assert(cbdataReferenceValid(this)); // indicates bug
3af10ac0
AR
1860 clearAdaptation(virginHeadSource);
1861 assert(!adaptedBodySource);
1862
1863 switch (answer.kind) {
1864 case Adaptation::Answer::akForward:
b248c2a3 1865 handleAdaptedHeader(const_cast<HttpMsg*>(answer.message.getRaw()));
3af10ac0
AR
1866 break;
1867
1868 case Adaptation::Answer::akBlock:
1869 handleAdaptationBlock(answer);
1870 break;
1871
1872 case Adaptation::Answer::akError:
1873 handleAdaptationFailure(ERR_DETAIL_CLT_REQMOD_ABORT, !answer.final);
1874 break;
1875 }
1876}
1877
1878void
ec4d1a1d 1879ClientHttpRequest::handleAdaptedHeader(HttpMsg *msg)
3af10ac0 1880{
5f8252d2 1881 assert(msg);
1882
b044675d 1883 if (HttpRequest *new_req = dynamic_cast<HttpRequest*>(msg)) {
200ac359 1884 /*
5f8252d2 1885 * Replace the old request with the new request.
200ac359 1886 */
6dd9f4bd 1887 HTTPMSGUNLOCK(request);
b248c2a3
AJ
1888 request = new_req;
1889 HTTPMSGLOCK(request);
11f62bfb
AJ
1890
1891 // update the new message to flag whether URL re-writing was done on it
851feda6 1892 if (request->effectiveRequestUri().cmp(uri) != 0)
11f62bfb
AJ
1893 request->flags.redirected = 1;
1894
200ac359 1895 /*
1896 * Store the new URI for logging
1897 */
1898 xfree(uri);
3f0e38d6 1899 uri = SBufToCstring(request->effectiveRequestUri());
200ac359 1900 setLogUri(this, urlCanonicalClean(request));
914b89a2 1901 assert(request->method.id());
b044675d 1902 } else if (HttpReply *new_rep = dynamic_cast<HttpReply*>(msg)) {
1903 debugs(85,3,HERE << "REQMOD reply is HTTP reply");
1904
5f8252d2 1905 // subscribe to receive reply body
1906 if (new_rep->body_pipe != NULL) {
a83c6ed6 1907 adaptedBodySource = new_rep->body_pipe;
d222a56c
HN
1908 int consumer_ok = adaptedBodySource->setConsumerIfNotLate(this);
1909 assert(consumer_ok);
5f8252d2 1910 }
1911
b044675d 1912 clientStreamNode *node = (clientStreamNode *)client_stream.tail->prev->data;
1913 clientReplyContext *repContext = dynamic_cast<clientReplyContext *>(node->data.getRaw());
ea25a575 1914 assert(repContext);
b044675d 1915 repContext->createStoreEntry(request->method, request->flags);
1916
1917 EBIT_CLR(storeEntry()->flags, ENTRY_FWD_HDR_WAIT);
1918 request_satisfaction_mode = true;
1919 request_satisfaction_offset = 0;
1920 storeEntry()->replaceHttpReply(new_rep);
97ae5196 1921 storeEntry()->timestampsSet();
cb4c4288 1922
a83c6ed6 1923 if (!adaptedBodySource) // no body
cb4c4288 1924 storeEntry()->complete();
b044675d 1925 clientGetMoreData(node, this);
200ac359 1926 }
de31d06f 1927
5f8252d2 1928 // we are done with getting headers (but may be receiving body)
a83c6ed6 1929 clearAdaptation(virginHeadSource);
5f8252d2 1930
b044675d 1931 if (!request_satisfaction_mode)
1932 doCallouts();
de31d06f 1933}
1934
1935void
3af10ac0 1936ClientHttpRequest::handleAdaptationBlock(const Adaptation::Answer &answer)
de31d06f 1937{
3af10ac0
AR
1938 request->detailError(ERR_ACCESS_DENIED, ERR_DETAIL_REQMOD_BLOCK);
1939 AclMatchedName = answer.ruleId.termedBuf();
1940 assert(calloutContext);
1941 calloutContext->clientAccessCheckDone(ACCESS_DENIED);
1942 AclMatchedName = NULL;
de31d06f 1943}
1944
0ad2b63b
CT
1945void
1946ClientHttpRequest::resumeBodyStorage()
1947{
e83cdc25 1948 if (!adaptedBodySource)
0ad2b63b
CT
1949 return;
1950
1951 noteMoreBodyDataAvailable(adaptedBodySource);
1952}
1953
de31d06f 1954void
1cf238db 1955ClientHttpRequest::noteMoreBodyDataAvailable(BodyPipe::Pointer)
de31d06f 1956{
5f8252d2 1957 assert(request_satisfaction_mode);
a83c6ed6 1958 assert(adaptedBodySource != NULL);
5f8252d2 1959
0ad2b63b 1960 if (size_t contentSize = adaptedBodySource->buf().contentSize()) {
4dc2b072 1961 const size_t spaceAvailable = storeEntry()->bytesWanted(Range<size_t>(0,contentSize));
0ad2b63b
CT
1962
1963 if (spaceAvailable < contentSize ) {
1964 // No or partial body data consuming
1965 typedef NullaryMemFunT<ClientHttpRequest> Dialer;
1966 AsyncCall::Pointer call = asyncCall(93, 5, "ClientHttpRequest::resumeBodyStorage",
1967 Dialer(this, &ClientHttpRequest::resumeBodyStorage));
1968 storeEntry()->deferProducer(call);
1969 }
1970
4dc2b072 1971 if (!spaceAvailable)
0ad2b63b
CT
1972 return;
1973
1974 if (spaceAvailable < contentSize )
1975 contentSize = spaceAvailable;
1976
a83c6ed6 1977 BodyPipeCheckout bpc(*adaptedBodySource);
0ad2b63b 1978 const StoreIOBuffer ioBuf(&bpc.buf, request_satisfaction_offset, contentSize);
5f8252d2 1979 storeEntry()->write(ioBuf);
0ad2b63b
CT
1980 // assume StoreEntry::write() writes the entire ioBuf
1981 request_satisfaction_offset += ioBuf.length;
4ce0e99b 1982 bpc.buf.consume(contentSize);
5f8252d2 1983 bpc.checkIn();
1984 }
1985
a83c6ed6 1986 if (adaptedBodySource->exhausted())
5f8252d2 1987 endRequestSatisfaction();
1988 // else wait for more body data
de31d06f 1989}
1990
1991void
1cf238db 1992ClientHttpRequest::noteBodyProductionEnded(BodyPipe::Pointer)
de31d06f 1993{
a83c6ed6 1994 assert(!virginHeadSource);
0ad2b63b
CT
1995 // should we end request satisfaction now?
1996 if (adaptedBodySource != NULL && adaptedBodySource->exhausted())
5f8252d2 1997 endRequestSatisfaction();
5f8252d2 1998}
3b299123 1999
5f8252d2 2000void
26ac0430
AJ
2001ClientHttpRequest::endRequestSatisfaction()
2002{
5f8252d2 2003 debugs(85,4, HERE << this << " ends request satisfaction");
2004 assert(request_satisfaction_mode);
a83c6ed6 2005 stopConsumingFrom(adaptedBodySource);
3b299123 2006
5f8252d2 2007 // TODO: anything else needed to end store entry formation correctly?
2008 storeEntry()->complete();
2009}
de31d06f 2010
5f8252d2 2011void
1cf238db 2012ClientHttpRequest::noteBodyProducerAborted(BodyPipe::Pointer)
5f8252d2 2013{
a83c6ed6
AR
2014 assert(!virginHeadSource);
2015 stopConsumingFrom(adaptedBodySource);
eae3a9a6
AR
2016
2017 debugs(85,3, HERE << "REQMOD body production failed");
2018 if (request_satisfaction_mode) { // too late to recover or serve an error
2019 request->detailError(ERR_ICAP_FAILURE, ERR_DETAIL_CLT_REQMOD_RESP_BODY);
73c36fd9 2020 const Comm::ConnectionPointer c = getConn()->clientConnection;
e7cea0ed
AJ
2021 Must(Comm::IsConnOpen(c));
2022 c->close(); // drastic, but we may be writing a response already
eae3a9a6
AR
2023 } else {
2024 handleAdaptationFailure(ERR_DETAIL_CLT_REQMOD_REQ_BODY);
2025 }
5f8252d2 2026}
3b299123 2027
5f8252d2 2028void
64b66b76 2029ClientHttpRequest::handleAdaptationFailure(int errDetail, bool bypassable)
5f8252d2 2030{
a83c6ed6 2031 debugs(85,3, HERE << "handleAdaptationFailure(" << bypassable << ")");
3b299123 2032
5f8252d2 2033 const bool usedStore = storeEntry() && !storeEntry()->isEmpty();
2034 const bool usedPipe = request->body_pipe != NULL &&
26ac0430 2035 request->body_pipe->consumedSize() > 0;
3b299123 2036
9d4d7c5e 2037 if (bypassable && !usedStore && !usedPipe) {
2038 debugs(85,3, HERE << "ICAP REQMOD callout failed, bypassing: " << calloutContext);
5f8252d2 2039 if (calloutContext)
2040 doCallouts();
2041 return;
2042 }
3b299123 2043
5f8252d2 2044 debugs(85,3, HERE << "ICAP REQMOD callout failed, responding with error");
3b299123 2045
5f8252d2 2046 clientStreamNode *node = (clientStreamNode *)client_stream.tail->prev->data;
2047 clientReplyContext *repContext = dynamic_cast<clientReplyContext *>(node->data.getRaw());
2048 assert(repContext);
de31d06f 2049
32fd6d8a
CT
2050 calloutsError(ERR_ICAP_FAILURE, errDetail);
2051
2052 if (calloutContext)
2053 doCallouts();
2054}
2055
5f1d7e48
CT
2056#endif
2057
32fd6d8a
CT
2058// XXX: modify and use with ClientRequestContext::clientAccessCheckDone too.
2059void
2060ClientHttpRequest::calloutsError(const err_type error, const int errDetail)
2061{
26ac0430 2062 // The original author of the code also wanted to pass an errno to
5f8252d2 2063 // setReplyToError, but it seems unlikely that the errno reflects the
2064 // true cause of the error at this point, so I did not pass it.
2bd84e5f
CT
2065 if (calloutContext) {
2066 Ip::Address noAddr;
4dd643d5 2067 noAddr.setNoAddr();
2bd84e5f 2068 ConnStateData * c = getConn();
32fd6d8a 2069 calloutContext->error = clientBuildError(error, Http::scInternalServerError,
87f237a9
A
2070 NULL,
2071 c != NULL ? c->clientConnection->remote : noAddr,
2072 request
2073 );
79fc6915 2074#if USE_AUTH
87f237a9 2075 calloutContext->error->auth_user_request =
cc1e110a 2076 c != NULL && c->getAuth() != NULL ? c->getAuth() : request->auth_user_request;
79fc6915 2077#endif
129fe2a1 2078 calloutContext->error->detailError(errDetail);
2bd84e5f 2079 calloutContext->readNextRequest = true;
7830d88a
FC
2080 if (c != NULL)
2081 c->expectNoForwarding();
2bd84e5f
CT
2082 }
2083 //else if(calloutContext == NULL) is it possible?
de31d06f 2084}
2085