NAME

Any::Daemon::HTTP::Source - source of information

INHERITANCE

 Any::Daemon::HTTP::Source is extended by
   Any::Daemon::HTTP::Directory
   Any::Daemon::HTTP::Proxy

SYNOPSIS

DESCRIPTION

Each Any::Daemon::HTTP::VirtualHost will define where the files are located. Parts of the URI path can map on different (virtual) resources, with different access rights.

METHODS

Constructors

Any::Daemon::HTTP::Source->new(%options|\%options)
 -Option--Default
  allow   <undef>
  deny    <undef>
  name    path
  path    '/'
allow => CIDR|HOSTNAME|DOMAIN|CODE|ARRAY

Allow all requests which pass any of these parameters, and none of the deny parameters. See "Allow access". Be warned that the access rights are not inherited from directory configurations encapsulating this one.

deny => CIDR|HOSTNAME|DOMAIN|CODE|ARRAY

See allow and "Allow access"

name => STRING
path => PATH

If the directory PATH (relative to the document root location) is not trailed by a '/', it will be made so.

Attributes

$obj->name()
$obj->path()

Permissions

$obj->allow($session, $request, $uri)

BE WARNED that the $uri is the rewrite of the $request uri, and therefore you should use that $uri. The $session represents a user.

See "Allow access".

$obj->collect($vhost, $session, $request, $uri)

Try to produce a response (HTTP::Response) for something inside this directory structure. undef is returned if nothing useful is found.

Actions

DETAILS

Resource restrictions

Allow access

The allow() method handles access rights. When a trueth value is produced, then access is permitted.

The base class implements access rules via the allow or deny option of new(). These parameters are exclusive (which is slightly different from Apache); you can either allow or deny, but not both at the same time. Be warned that the access rights are also not inherited from directory configurations encapsulating this one.

The parameters to allow or deny are an ARRAY with any combination of

IPv4 and IPv6 address ranges in CIDR notation
hostname
domain name (leading dot)
your own CODE reference, which will be called with the IP address,
  the hostname, the session, and the rewritten URI.

. Example: new(allow) parameters

 my $vhost = My::VHOST::Class->new( allow =>
    [ '192.168.2.1/32         # IPv4 CIDR, single address
    , '10/8'                  # IPv4 CIDR
    , '10.0.0.0-10.3.255.255' # IPv4 range
    , '::dead:beef:0:0/110'   # IPv6 range
    , 'www.example.com'       # hostname
    , '.example.com'          # domain and subdomains
    , 'example.com'           # only this domain
    ], ...

. Example: create own access rules

If you have an ::VirtualHost extension class, you do this:

 sub allow($$$)
 {   my ($self, $session, $request, $uri) = @_;

     # General rules may refuse access already
     $self->SUPER::allow($session, $request, $uri)
         or return 0;

     # here your own checks
     # $session is a Any::Daemon::HTTP::Session
     # $request is a HTTP::Request
     # $uri     is a URI::

     1;
 }

You may also pass a code-ref to new(allow):

 my $vhost = Any::Daemon::HTTP::VirtualHost
     ->new(allow => \&my_rules, ...);

 sub my_rules($$$$)   # called before each request
 {   my ($ip, $host, $session, $uri) = @_;
     # return true if access is permitted
 }

SEE ALSO

This module is part of Any-Daemon-HTTP distribution version 0.29, built on November 04, 2019. Website: http://perl.overmeer.net/any-daemon/

LICENSE

Copyrights 2013-2019 by [Mark Overmeer]. For other contributors see ChangeLog.

This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself. See http://dev.perl.org/licenses/