]> git.kaiwu.me - nginx.git/commitdiff
$scheme variable
authorIgor Sysoev <igor@sysoev.ru>
Mon, 2 Oct 2006 11:07:36 +0000 (11:07 +0000)
committerIgor Sysoev <igor@sysoev.ru>
Mon, 2 Oct 2006 11:07:36 +0000 (11:07 +0000)
src/http/ngx_http_variables.c

index d5fbfc9b70a8ff975339dc30f906876a92bcf740..7dc9cc1460bb22c477945caf45be949c659e8a9c 100644 (file)
@@ -36,6 +36,8 @@ static ngx_int_t ngx_http_variable_server_addr(ngx_http_request_t *r,
     ngx_http_variable_value_t *v, uintptr_t data);
 static ngx_int_t ngx_http_variable_server_port(ngx_http_request_t *r,
     ngx_http_variable_value_t *v, uintptr_t data);
+static ngx_int_t ngx_http_variable_scheme(ngx_http_request_t *r,
+    ngx_http_variable_value_t *v, uintptr_t data);
 static ngx_int_t ngx_http_variable_document_root(ngx_http_request_t *r,
     ngx_http_variable_value_t *v, uintptr_t data);
 static ngx_int_t ngx_http_variable_request_filename(ngx_http_request_t *r,
@@ -122,6 +124,8 @@ static ngx_http_variable_t  ngx_http_core_variables[] = {
     { ngx_string("server_protocol"), NULL, ngx_http_variable_request,
       offsetof(ngx_http_request_t, http_protocol), 0, 0 },
 
+    { ngx_string("scheme"), NULL, ngx_http_variable_scheme, 0, 0, 0 },
+
     { ngx_string("request_uri"), NULL, ngx_http_variable_request,
       offsetof(ngx_http_request_t, unparsed_uri), 0, 0 },
 
@@ -771,6 +775,34 @@ ngx_http_variable_server_port(ngx_http_request_t *r,
 }
 
 
+static ngx_int_t
+ngx_http_variable_scheme(ngx_http_request_t *r,
+    ngx_http_variable_value_t *v, uintptr_t data)
+{
+#if (NGX_HTTP_SSL)
+
+    if (r->connection->ssl) {
+        v->len = sizeof("https") - 1;
+        v->valid = 1;
+        v->no_cachable = 0;
+        v->not_found = 0;
+        v->data = "https";
+
+        return NGX_OK;
+    }
+
+#endif
+
+    v->len = sizeof("http") - 1;
+    v->valid = 1;
+    v->no_cachable = 0;
+    v->not_found = 0;
+    v->data = "http";
+
+    return NGX_OK;
+}
+
+
 static ngx_int_t
 ngx_http_variable_document_root(ngx_http_request_t *r,
     ngx_http_variable_value_t *v, uintptr_t data)