244
253
VRT_DO_HDR(req, request, sp->http, HTTP_HDR_REQ)
245
254
VRT_DO_HDR(req, url, sp->http, HTTP_HDR_URL)
246
255
VRT_DO_HDR(req, proto, sp->http, HTTP_HDR_PROTO)
247
VRT_DO_HDR(bereq, request, sp->bereq->http, HTTP_HDR_REQ)
248
VRT_DO_HDR(bereq, url, sp->bereq->http, HTTP_HDR_URL)
249
VRT_DO_HDR(bereq, proto, sp->bereq->http, HTTP_HDR_PROTO)
256
VRT_DO_HDR(bereq, request, sp->wrk->bereq, HTTP_HDR_REQ)
257
VRT_DO_HDR(bereq, url, sp->wrk->bereq, HTTP_HDR_URL)
258
VRT_DO_HDR(bereq, proto, sp->wrk->bereq, HTTP_HDR_PROTO)
250
259
VRT_DO_HDR(obj, proto, sp->obj->http, HTTP_HDR_PROTO)
251
260
VRT_DO_HDR(obj, response, sp->obj->http, HTTP_HDR_RESPONSE)
252
VRT_DO_HDR(resp, proto, sp->http, HTTP_HDR_PROTO)
253
VRT_DO_HDR(resp, response, sp->http, HTTP_HDR_RESPONSE)
261
VRT_DO_HDR(resp, proto, sp->wrk->resp, HTTP_HDR_PROTO)
262
VRT_DO_HDR(resp, response, sp->wrk->resp, HTTP_HDR_RESPONSE)
263
VRT_DO_HDR(beresp, proto, sp->wrk->beresp, HTTP_HDR_PROTO)
264
VRT_DO_HDR(beresp, response, sp->wrk->beresp, HTTP_HDR_RESPONSE)
255
266
/*--------------------------------------------------------------------*/
270
281
http_SetH(sp->obj->http, HTTP_HDR_STATUS, p);
284
/* Add an objecthead to the saintmode list for the (hopefully) relevant
285
* backend. Some double-up asserting here to avoid assert-errors when there
289
VRT_l_beresp_saintmode(const struct sess *sp, double a)
295
CHECK_OBJ_NOTNULL(sp, SESS_MAGIC);
298
CHECK_OBJ_NOTNULL(sp->vbe, VBE_CONN_MAGIC);
299
if (!sp->vbe->backend)
301
CHECK_OBJ_NOTNULL(sp->vbe->backend, BACKEND_MAGIC);
304
CHECK_OBJ_NOTNULL(sp->objhead, OBJHEAD_MAGIC);
306
/* Setting a negative holdoff period is a mistake. Detecting this
307
* when compiling the VCL would be better.
311
ALLOC_OBJ(new, TROUBLE_MAGIC);
313
new->target = (uintptr_t)sp->objhead;
314
new->timeout = sp->t_req + a;
316
/* Insert the new item on the list before the first item with a
317
* timeout at a later date (ie: sort by which entry will time out
320
Lck_Lock(&sp->vbe->backend->mtx);
321
VTAILQ_FOREACH_SAFE(tr, &sp->vbe->backend->troublelist, list, tr2) {
322
if (tr->timeout < new->timeout) {
323
VTAILQ_INSERT_BEFORE(tr, new, list);
329
/* Insert the item at the end if the list is empty or all other
330
* items have a longer timeout.
333
VTAILQ_INSERT_TAIL(&sp->vbe->backend->troublelist, new, list);
335
Lck_Unlock(&sp->vbe->backend->mtx);
274
339
VRT_r_obj_status(const struct sess *sp)
289
355
assert(num >= 100 && num <= 999);
290
p = WS_Alloc(sp->http->ws, 4);
356
p = WS_Alloc(sp->wrk->ws, 4);
292
358
WSP(sp, SLT_LostHeader, "%s", "resp.status");
294
360
sprintf(p, "%d", num);
295
http_SetH(sp->http, HTTP_HDR_STATUS, p);
361
http_SetH(sp->wrk->resp, HTTP_HDR_STATUS, p);
299
365
VRT_r_resp_status(const struct sess *sp)
301
367
CHECK_OBJ_NOTNULL(sp, SESS_MAGIC);
302
CHECK_OBJ_NOTNULL(sp->http, HTTP_MAGIC);
303
return (atoi(sp->http->hd[HTTP_HDR_STATUS].b));
368
CHECK_OBJ_NOTNULL(sp->wrk->resp, HTTP_MAGIC);
369
return (atoi(sp->wrk->resp->hd[HTTP_HDR_STATUS].b));
372
/*--------------------------------------------------------------------*/
374
#define VBEREQ(dir, type,onm,field) \
376
VRT_l_##dir##_##onm(const struct sess *sp, type a) \
378
CHECK_OBJ_NOTNULL(sp, SESS_MAGIC); \
379
sp->wrk->field = a; \
383
VRT_r_##dir##_##onm(const struct sess *sp) \
385
CHECK_OBJ_NOTNULL(sp, SESS_MAGIC); \
386
return (sp->wrk->field); \
389
VBEREQ(beresp, unsigned, cacheable, cacheable)
390
VBEREQ(beresp, double, grace, grace)
392
/*--------------------------------------------------------------------
393
* XXX: Working relative to t_req is maybe not the right thing, we could
394
* XXX: have spent a long time talking to the backend since then.
395
* XXX: It might make sense to cache a timestamp as "current time"
396
* XXX: before vcl_recv (== t_req) and vcl_fetch.
397
* XXX: On the other hand, that might lead to inconsistent behaviour
398
* XXX: where an object expires while we are running VCL code, and
399
* XXX: and that may not be a good idea either.
400
* XXX: See also related t_req use in cache_hash.c
404
VRT_l_beresp_ttl(const struct sess *sp, double a)
407
CHECK_OBJ_NOTNULL(sp, SESS_MAGIC);
408
WSP(sp, SLT_TTL, "%u VCL %.0f %.0f", sp->xid, a, sp->t_req);
410
* If people set obj.ttl = 0s, they don't expect it to be cacheable
411
* any longer, but it will still be for up to 1s - epsilon because
412
* of the rounding to seconds.
413
* We special case and make sure that rounding does not surprise.
416
sp->wrk->ttl = sp->t_req - 1;
418
sp->wrk->ttl = sp->t_req + a;
422
VRT_r_beresp_ttl(const struct sess *sp)
424
CHECK_OBJ_NOTNULL(sp, SESS_MAGIC);
425
return (sp->wrk->ttl - sp->t_req);
429
VRT_l_beresp_status(const struct sess *sp, int num)
433
assert(num >= 100 && num <= 999);
434
p = WS_Alloc(sp->wrk->beresp->ws, 4);
436
WSP(sp, SLT_LostHeader, "%s", "obj.status");
438
sprintf(p, "%d", num);
439
http_SetH(sp->wrk->beresp, HTTP_HDR_STATUS, p);
443
VRT_r_beresp_status(const struct sess *sp)
445
CHECK_OBJ_NOTNULL(sp, SESS_MAGIC);
446
/* XXX: use http_GetStatus() */
447
if (sp->wrk->beresp->status)
448
return (sp->wrk->beresp->status);
449
AN(sp->wrk->beresp->hd[HTTP_HDR_STATUS].b);
450
return (atoi(sp->wrk->beresp->hd[HTTP_HDR_STATUS].b));
307
455
VRT_l_bereq_connect_timeout(struct sess *sp, double num)
309
457
CHECK_OBJ_NOTNULL(sp, SESS_MAGIC);
310
sp->connect_timeout = (num > 0 ? num : 0);
458
sp->wrk->connect_timeout = (num > 0 ? num : 0);
314
462
VRT_r_bereq_connect_timeout(struct sess *sp)
316
464
CHECK_OBJ_NOTNULL(sp, SESS_MAGIC);
317
return sp->connect_timeout;
465
return (sp->wrk->connect_timeout);
321
469
VRT_l_bereq_first_byte_timeout(struct sess *sp, double num)
323
471
CHECK_OBJ_NOTNULL(sp, SESS_MAGIC);
324
sp->first_byte_timeout = (num > 0 ? num : 0);
472
sp->wrk->first_byte_timeout = (num > 0 ? num : 0);
328
476
VRT_r_bereq_first_byte_timeout(struct sess *sp)
330
478
CHECK_OBJ_NOTNULL(sp, SESS_MAGIC);
331
return sp->first_byte_timeout;
479
return (sp->wrk->first_byte_timeout);
335
483
VRT_l_bereq_between_bytes_timeout(struct sess *sp, double num)
337
485
CHECK_OBJ_NOTNULL(sp, SESS_MAGIC);
338
sp->between_bytes_timeout = (num > 0 ? num : 0);
486
sp->wrk->between_bytes_timeout = (num > 0 ? num : 0);
342
490
VRT_r_bereq_between_bytes_timeout(struct sess *sp)
344
492
CHECK_OBJ_NOTNULL(sp, SESS_MAGIC);
345
return sp->between_bytes_timeout;
493
return (sp->wrk->between_bytes_timeout);
348
496
/*--------------------------------------------------------------------*/
425
577
/*--------------------------------------------------------------------*/
427
/* XXX: the VCL_info messages has unexpected fractions on the ttl */
430
VRT_l_obj_prefetch(const struct sess *sp, double a)
433
CHECK_OBJ_NOTNULL(sp, SESS_MAGIC);
434
CHECK_OBJ_NOTNULL(sp->obj, OBJECT_MAGIC); /* XXX */
435
sp->obj->prefetch = 0.0;
437
sp->obj->prefetch = a;
438
else if (a > 0.0 && a + sp->t_req <= sp->obj->ttl)
439
sp->obj->prefetch = a + sp->t_req;
440
else if (a < 0.0 && a + sp->obj->ttl > sp->t_req)
441
sp->obj->prefetch = a;
443
WSL(sp->wrk, SLT_VCL_info, sp->id,
444
"XID %u: obj.prefetch (%g) after TTL (%g), ignored.",
445
sp->obj->xid, a, sp->obj->ttl - sp->t_req);
446
else /* if (a < 0.0) */
447
WSL(sp->wrk, SLT_VCL_info, sp->id,
448
"XID %u: obj.prefetch (%g) less than ttl (%g), ignored.",
449
sp->obj->xid, a, sp->obj->ttl - sp->t_req);
454
VRT_r_obj_prefetch(const struct sess *sp)
456
CHECK_OBJ_NOTNULL(sp, SESS_MAGIC);
457
CHECK_OBJ_NOTNULL(sp->obj, OBJECT_MAGIC); /* XXX */
458
return (sp->obj->prefetch - sp->t_req);
461
/*--------------------------------------------------------------------*/
463
579
#define VOBJ(type,onm,field) \
465
581
VRT_l_obj_##onm(const struct sess *sp, type a) \