diff --git a/src/http/ngx_http_variables.c b/src/http/ngx_http_variables.c
index 2deb9689..261117f1 100644
--- a/src/http/ngx_http_variables.c
+++ b/src/http/ngx_http_variables.c
@@ -1422,7 +1422,7 @@ ngx_http_variable_scheme(ngx_http_request_t *r,
 {
 #if (NGX_HTTP_SSL)
 
-    if (r->connection->ssl) {
+    if (r->schema_end == r->schema_start + 5) {
         v->len = sizeof("https") - 1;
         v->valid = 1;
         v->no_cacheable = 0;
@@ -1450,7 +1450,7 @@ ngx_http_variable_https(ngx_http_request_t *r,
 {
 #if (NGX_HTTP_SSL)
 
-    if (r->connection->ssl) {
+    if (r->schema_end == r->schema_start + 5) {
         v->len = sizeof("on") - 1;
         v->valid = 1;
         v->no_cacheable = 0;
