Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add scheme hook to detect X-Forwarded-Proto request header #33

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions mod_auth_mellon.c
Original file line number Diff line number Diff line change
Expand Up @@ -204,6 +204,21 @@ static int am_create_request(request_rec *r)
return OK;
}

static const char *am_hook_http_scheme(const request_rec *r)
{
/*
* If X-Forwarded-Proto header is set then we will use that as the scheme
*/
const char *value = apr_table_get(r->headers_in, "X-Forwarded-Proto");
char *last = NULL;
if (value) {
value = apr_strtok(apr_pstrdup(r->pool, value), ", ", &last);
if (value && (apr_strnatcmp(value, "https") == 0)) {
return "https";
}
}
return NULL;
}

static void register_hooks(apr_pool_t *p)
{
Expand All @@ -218,6 +233,7 @@ static void register_hooks(apr_pool_t *p)
ap_hook_post_config(am_global_init, NULL, NULL, APR_HOOK_MIDDLE);
ap_hook_child_init(am_child_init, NULL, NULL, APR_HOOK_MIDDLE);
ap_hook_create_request(am_create_request, NULL, NULL, APR_HOOK_MIDDLE);
ap_hook_http_scheme(am_hook_http_scheme, NULL, NULL, APR_HOOK_MIDDLE);

/* Add the hook to handle requests to the mod_auth_mellon endpoint.
*
Expand Down