Commit c52117a2 authored by Nils Goroll's avatar Nils Goroll

1e3 status codes #1

parent ea1da86f
...@@ -160,7 +160,7 @@ cnt_synth(struct worker *wrk, struct req *req) ...@@ -160,7 +160,7 @@ cnt_synth(struct worker *wrk, struct req *req)
now = W_TIM_real(wrk); now = W_TIM_real(wrk);
VSLb_ts_req(req, "Process", now); VSLb_ts_req(req, "Process", now);
if (req->err_code < 100 || req->err_code > 999) if (req->err_code < 100)
req->err_code = 501; req->err_code = 501;
HTTP_Setup(req->resp, req->ws, req->vsl, SLT_RespMethod); HTTP_Setup(req->resp, req->ws, req->vsl, SLT_RespMethod);
......
...@@ -54,11 +54,11 @@ VRT_synth(VRT_CTX, unsigned code, const char *reason) ...@@ -54,11 +54,11 @@ VRT_synth(VRT_CTX, unsigned code, const char *reason)
CHECK_OBJ_NOTNULL(ctx, VRT_CTX_MAGIC); CHECK_OBJ_NOTNULL(ctx, VRT_CTX_MAGIC);
CHECK_OBJ_NOTNULL(ctx->req, REQ_MAGIC); CHECK_OBJ_NOTNULL(ctx->req, REQ_MAGIC);
if (code < 100 || code > 999) if (code < 100)
code = 503; code = 503;
ctx->req->err_code = (uint16_t)code; ctx->req->err_code = (uint16_t)code;
ctx->req->err_reason = ctx->req->err_reason = reason ? reason
reason ? reason : http_Status2Reason(ctx->req->err_code, NULL); : http_Status2Reason(ctx->req->err_code % 1000, NULL);
} }
/*--------------------------------------------------------------------*/ /*--------------------------------------------------------------------*/
......
...@@ -20,14 +20,17 @@ varnish v1 -vcl+backend { ...@@ -20,14 +20,17 @@ varnish v1 -vcl+backend {
if (req.url == "/332") { if (req.url == "/332") {
return (synth(332, "FOO")); return (synth(332, "FOO"));
} else if (req.url == "/333") { } else if (req.url == "/333") {
return (synth(resp.status, resp.reason)); return (synth(resp.status + 1000,
resp.reason));
} else { } else {
return (synth(334, "BAR")); return (synth(334, "BAR"));
} }
} }
sub vcl_synth { sub vcl_synth {
if (resp.status == 333) { # internal response status >1000 will be taken modulo
# 1000 when sent
if (resp.status == 1333) {
set resp.http.connection = "close"; set resp.http.connection = "close";
} else if (resp.status == 332) { } else if (resp.status == 332) {
if (req.restarts == 0) { if (req.restarts == 0) {
......
...@@ -492,6 +492,9 @@ sp_variables = [ ...@@ -492,6 +492,9 @@ sp_variables = [
('backend_response', 'backend_error'), ('backend_response', 'backend_error'),
('backend_response', 'backend_error'), """ ('backend_response', 'backend_error'), """
The HTTP status code returned by the server. The HTTP status code returned by the server.
Status codes >1000 can be set for vcl-internal
purposes and will be taken modulo 1000 on delivery.
""" """
), ),
('beresp.reason', ('beresp.reason',
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment