This module implements basic HTTP authentication against the password file created with the  htpasswd(1) utility.

It provides a single function:

bool match(string file, string auth)

The first argument(file) gives the full pathname of the htpasswd fileThe second argument is the value of the Authorization: HTTP header.

Example usage (VCL 3.0):

import basicauth;

sub vcl_recv {
        if (!basicauth.match("/var/www/.htpasswd",  req.http.Authorization)) {
                error(401, "Authentication required");

For VCL 4.0, replace error with return(synth(401, "Authentication required")).

Notice, that this module uses different approach than the Authentication module, which requires username and password to be hardcoded in the VCL script.

This module is free software and is available under the terms of GNU General Public License version 3 or (at your option) any later version.

Used in production
Varnish version supported: 
Commercial support: 
NXC International