diff src/http/modules/perl/nginx.xs @ 254:f3ec44f4a53b NGINX_0_4_12

nginx 0.4.12 *) Feature: the ngx_http_perl_module supports the $r->variable method. *) Bugfix: if a big static file was included using SSI in a response, then the response may be transferred incomplete. *) Bugfix: nginx did not omit the "#fragment" part in URI.
author Igor Sysoev <http://sysoev.ru>
date Tue, 31 Oct 2006 00:00:00 +0300
parents 644510700914
children 6ae1357b7b7c
line wrap: on
line diff
--- a/src/http/modules/perl/nginx.xs
+++ b/src/http/modules/perl/nginx.xs
@@ -763,3 +763,86 @@ unescape(r, text, type = 0)
     ngx_http_perl_set_targ(p, dst - p, 1);
 
     ST(0) = TARG;
+
+
+void
+variable(r, name, value = NULL)
+    CODE:
+
+    dXSTARG;
+    ngx_http_request_t         *r;
+    SV                         *name, *value;
+    u_char                     *p, *lowcase;
+    STRLEN                      len;
+    ngx_str_t                   var, val;
+    ngx_uint_t                  i, hash;
+    ngx_http_variable_value_t  *vv;
+
+    ngx_http_perl_set_request(r);
+
+    name = ST(1);
+
+    if (SvROK(name) && SvTYPE(SvRV(name)) == SVt_PV) {
+        name = SvRV(name);
+    }
+
+    if (items == 2) {
+        value = NULL;
+
+    } else {
+        value = ST(2);
+
+        if (SvROK(value) && SvTYPE(SvRV(value)) == SVt_PV) {
+            value = SvRV(value);
+        }
+
+        if (ngx_http_perl_sv2str(aTHX_ r, &val, value) != NGX_OK) {
+            XSRETURN_UNDEF;
+        }
+    }
+
+    p = (u_char *) SvPV(name, len);
+
+    lowcase = ngx_palloc(r->pool, len);
+    if (lowcase == NULL) {
+        XSRETURN_UNDEF;
+    }
+
+    hash = 0;
+    for (i = 0; i < len; i++) {
+        lowcase[i] = ngx_tolower(p[i]);
+        hash = ngx_hash(hash, lowcase[i]);
+    }
+
+    var.len = len;
+    var.data = lowcase;
+
+    vv = ngx_http_get_variable(r, &var, hash, 1);
+    if (vv == NULL) {
+        XSRETURN_UNDEF;
+    }
+
+    if (vv->not_found) {
+        if (value == NULL) {
+            XSRETURN_UNDEF;
+        }
+
+        ngx_log_error(NGX_LOG_ERR, r->connection->log, 0,
+                      "variable \"%V\" not found", &var);
+
+        XSRETURN_UNDEF;
+    }
+
+    if (value) {
+        vv->len = val.len;
+        vv->valid = 1;
+        vv->no_cachable = 0;
+        vv->not_found = 0;
+        vv->data = val.data;
+
+        XSRETURN_UNDEF;
+    }
+
+    ngx_http_perl_set_targ(vv->data, vv->len, 0);
+
+    ST(0) = TARG;