[PATCH 1 of 1 RFC] login: add login-required Pragma to HTTP headers
Thomas De Schampheleire
patrickdepinguin at gmail.com
Thu Mar 19 17:07:47 EDT 2015
On Thu, Mar 19, 2015 at 9:34 PM, Thomas De Schampheleire
<patrickdepinguin at gmail.com> wrote:
> # HG changeset patch
> # User Thomas De Schampheleire <thomas.de.schampheleire at gmail.com>
> # Date 1426796699 -3600
> # Thu Mar 19 21:24:59 2015 +0100
> # Node ID a9f2e162a9ecad5d13ee44848a73b64cc3de3285
> # Parent cf8eab44c6ec583f7a0642b7274d2222a30d15e3
> login: add login-required Pragma to HTTP headers
>
> To make it easier for automated scripts to detect a login failure, add a
> Pragma 'login-required' in the HTTP headers.
> As existing pragmas, like no-cache, may be present, extend the original one
> instead of overwriting.
>
> diff --git a/kallithea/controllers/login.py b/kallithea/controllers/login.py
> --- a/kallithea/controllers/login.py
> +++ b/kallithea/controllers/login.py
> @@ -35,7 +35,7 @@
> from webob.exc import HTTPFound
> from pylons.i18n.translation import _
> from pylons.controllers.util import redirect
> -from pylons import request, session, tmpl_context as c, url
> +from pylons import request, response, session, tmpl_context as c, url
>
> import kallithea.lib.helpers as h
> from kallithea.lib.auth import AuthUser, HasPermissionAnyDecorator
> @@ -157,6 +157,13 @@
> if auth_info:
> headers = self._store_user_in_session(auth_info.get('username'))
> raise HTTPFound(location=c.came_from, headers=headers)
> +
> + if 'Pragma' in response.headers:
> + current_pragma = '%s,' % response.headers['Pragma']
> + else:
> + current_pragma = ''
> + response.headers['Pragma'] = '%slogin-required' % current_pragma
> +
Note: I'm not sure what to do when an external authentication plugin
is used: can we pass headers to it as well?
More information about the kallithea-general
mailing list