proxy_pass fails after calling $r->has_request_body()
Igor Sysoev
is at rambler-co.ru
Thu Dec 20 10:18:11 MSK 2007
On Thu, Dec 20, 2007 at 05:58:43AM +0100, Ben Grimm wrote:
> 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;
No, proxy_pass should not read the body in this case. I will look.
Other ways:
1) You have not to check $r->has_request_body(): you may call
$r->internal_redirect at once.
2) in 0.6.21+ you may use a variable in proxy_pass:
location ^~ /@map/ {
proxy_pass http://$backend;
}
and set the variable using perl_set.
--
Igor Sysoev
http://sysoev.ru/en/
More information about the nginx
mailing list