Hi there. 

I've got a question for the mod_perl world about the behavior of the 
$r->headers_in->do(sub {...some code...}) method.

I'm writing a proxy handler, and am getting strange results when trying to
pass headers from the initial request to the proxied request. The problem
is that the two blocks of code below are supposed to do the same
thing, and look as though they definitely should do the same thing, but
don't.

If anyone has any answers or suggestions, I'd love to hear them.

Thanks in advance for any advice you might have.

-mike styer


<code extract> =========================================================

## initial header printout

    my @headers = $r->headers_in;
    print STDERR "original headers: \n";
    while (my ($f, $v) = each %headers) { print STDERR "$f: $v\n"; }

## block (1)

    print STDERR "\nPassing headers: ...\n";
    $r->headers_in->do(sub {
        $request->header(@_);
        #print STDERR "header passed: (@_)\n";
        });
    print STDERR "\nPROXY request:\n".$request->as_string."\n";

## block (2)

    print STDERR "\nPassing headers: ...\n";
    $r->headers_in->do(sub {
        $request->header(@_);
        print STDERR "header passed: (@_)\n";
        });
    print STDERR "\nPROXY request:\n".$request->as_string."\n";

<end code extract> =====================================================

The only difference between those two blocks is the fact that the print
STDERR "header passed: (@_)\n"; line is commented out in the second block.
But they produce significantly different output, for no reason that's
apparent to me.

The output from these blocks is (formatted for easier reading):

<error log extract> ====================================================

original headers: 
Connection: Keep-Alive
Accept: image/gif, image/x-xbitmap, image/jpeg, image/pjpeg, image/png, */*
Accept-Language: en
Accept-Encoding: gzip
Accept-Charset: iso-8859-1,*,utf-8
Cookie: visited=yes
User-Agent: Mozilla/4.75 [en] (X11; U; Linux 2.2.14-5.0 i686)
Host: proxy.server.net


Passing headers: ...

PROXY request:
GET http://proxied.site.com/
Accept: image/gif, image/x-xbitmap, image/jpeg, image/pjpeg, image/png, */*




Passing headers: ...
header passed: (Accept image/gif, image/x-xbitmap, image/jpeg, 
    image/pjpeg, image/png, */*)
header passed: (Accept-Charset iso-8859-1,*,utf-8)
header passed: (Accept-Encoding gzip)
header passed: (Accept-Language en)
header passed: (Connection Keep-Alive)
header passed: (Cookie visited=yes)
header passed: (Host proxy.server.net)
header passed: (User-Agent Mozilla/4.75 [en] (X11; U; Linux 2.2.14-5.0 i686))

PROXY request:
GET http://proxied.site.com/
Connection: Keep-Alive
Accept: image/gif, image/x-xbitmap, image/jpeg, image/pjpeg, image/png, */*
Accept-Charset: iso-8859-1,*,utf-8
Accept-Encoding: gzip
Accept-Language: en
Host: proxy.server.net
User-Agent: Mozilla/4.75 [en] (X11; U; Linux 2.2.14-5.0 i686)
Cookie: visited=yes

<end error log extract> ================================================

As you can see, the headers don't get passed on the first try, without the
print STDERR statement. As far as I can tell, there's NO reason why
printing the values to STDERR should affect whether they get passed on,
but it seems to be having that affect.

I'm stumped, so like I said, any help would be most appreciated.


-- 
Michael Styer           [EMAIL PROTECTED]
phone: 020 7603 5723    107 Shepherd's Bush Rd
fax: 020 7603 2504      London W6 7LP


Reply via email to