Search code examples
apacheperl-moduleapache2.2

Apache give HTTP 404 error for all request when use custom perl module


I have to create the go remote-import server for my project using by apache and I try to create perl module for handler the go get request from user.

The perl module (RemoteImport.pm) was show in below:

sub handler{
    my $r = shift;

    # check if request is from "go"
    return Apache2::Const::DECLINED if ($r->args() !~ /go\-get=1$/);

    // Code for provide necessary http body data for go get request and return OK.
}

Apache config:

PerlModule Gerrit::Go::RemoteImport
<Location />
    SetHandler perl-script
    PerlResponseHandler Gerrit::Go::RemoteImport
</Location>

The go get request can be use normally but I found problem in another http request that have path begin with "/", the Apache does not continue to serve the request as it normally and give not-found page.

Please help me to solve this problem.


Solution

  • I get solution from my team as bellow:

    sub go_remote_import_response {
        my $r = shift;
    
        # Code for provide necessary http body data for go get request and return OK.
    }
    
    sub handler {
        my $r = shift;
    
        # check if request is from "go"
        return Apache2::Const::OK if ($r->args() !~ /go\-get=1$/);
    
        # change the response handler to our handler if the request are from "go"
        $r->handler('perl-script');
        $r->set_handlers(PerlResponseHandler => \&go_remote_import_response);
    
        return Apache2::Const::OK;
    }