Skip to content

Instantly share code, notes, and snippets.

@jesusbagpuss
Created February 27, 2024 15:18
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jesusbagpuss/fb4c01825f5da53ac5ddb2d6a6fa69d3 to your computer and use it in GitHub Desktop.
Save jesusbagpuss/fb4c01825f5da53ac5ddb2d6a6fa69d3 to your computer and use it in GitHub Desktop.
EPrints: Add user to Apache request object so it gets logged in Apache access logfile (as %u).
# ADD THIS FILE TO e.g. [EPRINT_ROOT]/archives/[ARCHIVE_ID]/cfg/cfg.d/
#
# Add username to Apache Request object so it gets added to Apache access.log file
# NB This will not cause the username to be logged in the EPrints access dataset.
use EPrints::Const;
$c->add_trigger( EP_TRIGGER_URL_REWRITE, sub {
my( %args ) = @_;
my( $r, $repo ) = @args{qw( request repository )};
if( defined $repo->current_user && !defined $r->user )
{
$r->user( $repo->current_user->get_value( "username" ) );
}
# No return value - so next URL_REWRITE trigger will be run
}, priority => 50);
# priority needs to be lower than other REWRITE triggers so it gets run sooner in the request handling.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment