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