diff --git a/include/lighttpd/condition.h b/include/lighttpd/condition.h index c923c17..bf9fe4d 100644 --- a/include/lighttpd/condition.h +++ b/include/lighttpd/condition.h @@ -54,7 +54,8 @@ typedef enum { /* needs a key */ LI_COMP_REQUEST_HEADER, /**< needs lowercase key, enforced by li_condition_lvalue_new */ - LI_COMP_RESPONSE_HEADER, /**< needs lowercase key, enforced by li_condition_lvalue_new */ + LI_COMP_RESPONSE_HEADER, /**< needs lowercase key, enforced by li_condition_lvalue_new */ + LI_COMP_ENVIRONMENT, LI_COMP_UNKNOWN } liCondLValue; diff --git a/src/main/condition.c b/src/main/condition.c index f3a1e02..1d6bed4 100644 --- a/src/main/condition.c +++ b/src/main/condition.c @@ -262,6 +262,7 @@ const char* li_cond_lvalue_to_string(liCondLValue t) { case LI_COMP_RESPONSE_STATUS: return "response.status"; case LI_COMP_REQUEST_HEADER: return "request.header"; case LI_COMP_RESPONSE_HEADER: return "response.header"; + case LI_COMP_ENVIRONMENT: return "request.environment"; case LI_COMP_UNKNOWN: return ""; } @@ -293,6 +294,8 @@ liCondLValue li_cond_lvalue_from_string(const gchar *str, guint len) { return LI_COMP_REQUEST_CONTENT_LENGTH; else if (strncmp(c, "header", len) == 0) return LI_COMP_REQUEST_HEADER; + else if (strncmp(c, "environment", len) == 0 || strncmp(c, "env", len) == 0) + return LI_COMP_ENVIRONMENT; else if (strncmp(c, "is_handled", len) == 0) return LI_COMP_REQUEST_IS_HANDLED; } else if (g_str_has_prefix(c, "physical.")) { @@ -412,6 +415,9 @@ static liHandlerResult li_condition_check_eval_string(liVRequest *vr, liConditio li_http_header_get_all(con->wrk->tmp_str, vr->response.headers, GSTR_LEN(cond->lvalue->key)); val = con->wrk->tmp_str->str; break; + case LI_COMP_ENVIRONMENT: + val = li_environment_get(&vr->env, GSTR_LEN(cond->lvalue->key)); + break; case LI_COMP_REQUEST_CONTENT_LENGTH: g_string_printf(con->wrk->tmp_str, "%"L_GOFFSET_FORMAT, vr->request.content_length); val = con->wrk->tmp_str->str; @@ -600,6 +606,9 @@ static liHandlerResult li_condition_check_eval_ip(liVRequest *vr, liCondition *c li_http_header_get_all(con->wrk->tmp_str, vr->response.headers, GSTR_LEN(cond->lvalue->key)); val = con->wrk->tmp_str->str; break; + case LI_COMP_ENVIRONMENT: + val = li_environment_get(&vr->env, GSTR_LEN(cond->lvalue->key))->str; + break; case LI_COMP_PHYSICAL_SIZE: case LI_COMP_REQUEST_CONTENT_LENGTH: case LI_COMP_RESPONSE_STATUS: diff --git a/src/main/config_parser.rl b/src/main/config_parser.rl index d231356..a847d69 100644 --- a/src/main/config_parser.rl +++ b/src/main/config_parser.rl @@ -866,6 +866,13 @@ } lvalue = li_condition_lvalue_new(LI_COMP_REQUEST_HEADER, li_value_extract(k).string); } + else if (g_str_equal(str, "environment") || g_str_equal(str, "env")) { + if (k == NULL) { + WARNING(srv, "%s", "environment conditional needs a key"); + return FALSE; + } + lvalue = li_condition_lvalue_new(LI_COMP_ENVIRONMENT, li_value_extract(k).string); + } else { WARNING(srv, "unkown lvalue for condition: %s", n->data.string->str); return FALSE;