[OpenWrt-Devel] uhttpd2: Set HTTPS environment variable
diff mbox

Message ID 548A1C84.6080404@opentechinstitute.org
State Changes Requested
Headers show

Commit Message

Dan Staples Dec. 11, 2014, 10:36 p.m. UTC
Currently, the only way for cgi scripts to determine if the request was made over SSL seems to be to check if the SERVER_PORT environment variable is set to 443, which is less than ideal. This sets the HTTPS environment variable, like the first version of uhttpd.

Signed-off-by: Dan Staples <danstaples at opentechinstitute.org>
---
 proc.c | 3 +++
 1 file changed, 3 insertions(+)

Comments

Felix Fietkau Dec. 12, 2014, 5:06 p.m. UTC | #1
On 2014-12-11 23:36, Dan Staples wrote:
> Currently, the only way for cgi scripts to determine if the request
> was made over SSL seems to be to check if the SERVER_PORT environment
> variable is set to 443, which is less than ideal. This sets the HTTPS
> environment variable, like the first version of uhttpd.
> 
> Signed-off-by: Dan Staples <danstaples at opentechinstitute.org>
The patch has been whitespace mangled. Please fix and resend.

Thanks,

- Felix

Patch
diff mbox

diff --git a/proc.c b/proc.c
index 9c4b685..b520b91 100644
--- a/proc.c
+++ b/proc.c
@@ -81,6 +81,7 @@  enum extra_vars {
        VAR_METHOD,
        VAR_PATH_INFO,
        VAR_USER,
+       VAR_TLS,
        VAR_REDIRECT,
        VAR_SERVER_NAME,
        VAR_SERVER_ADDR,
@@ -108,6 +109,7 @@  static struct env_var extra_vars[] = {
        [VAR_METHOD] = { "REQUEST_METHOD" },
        [VAR_PATH_INFO] = { "PATH_INFO" },
        [VAR_USER] = { "REMOTE_USER" },
+       [VAR_TLS] = { "HTTPS" },
        [VAR_REDIRECT] = { "REDIRECT_STATUS", redirect_status },
        [VAR_SERVER_NAME] = { "SERVER_NAME", local_addr },
        [VAR_SERVER_ADDR] = { "SERVER_ADDR", local_addr },
@@ -143,6 +145,7 @@  struct env_var *uh_get_process_vars(struct client *cl, struct path_info *pi)
        extra_vars[VAR_METHOD].value = http_methods[req->method];
        extra_vars[VAR_PATH_INFO].value = pi->info;
        extra_vars[VAR_USER].value = req->realm ? req->realm->user : NULL;
+       extra_vars[VAR_TLS].value = cl->tls ? "on" : NULL;
 
        snprintf(redirect_status, sizeof(redirect_status),
                 "%d", req->redirect_status);