Hi, I’m trying to parse a request in a perl handler, extract a value
from it and use that to set a variable for use in a proxy_pass mapping.
GET requests work fine, but POST’s fail. I suspect that the proxy_pass
is trying re-read the request body. Is there a better way to
accomplish do this?
location ^~ /@map/ {
internal;
perl ProxyMap::handler;
}
location ^~ /@backend/ {
internal;
proxy_pass http://backend/;
}
package ProxyMap;
sub handler {
my $r = shift;
return OK if $r->has_request_body(&handle_request);
return handle_request($r);
}
this is reduced to the simplest example I could make
sub handle_request {
my $r = shift;
my $backend = ‘backend’;
my $uri = $r->uri;
$uri =~ s/@map/@$backend/;
$r->internal_redirect($uri);
return OK;
}
1;