in reply to Help building response headers for HTTP proxy request

A quick check of the docs makes me believe that HTTP::Headers (which is the type of object HTTP::Proxy is using together with the response) simply doesn't allow to init headers en bloc from a file.  So, I'm afraid you'll have to split them up and set them on a field by field basis...

  • Comment on Re: Help building response headers for HTTP proxy request

Replies are listed 'Best First'.
Re^2: Help building response headers for HTTP proxy request
by r1n0 (Beadle) on Feb 24, 2010 at 16:50 UTC
    Almut,

    You are right. I ended up reading in the header file, line by line and splitting on the first colon ':'. Then, I use the take the info left of the colon and pair it with the info to the right. I build a HTTP::Headers object, and assign each left/right pair to the object via:

    if ( -f $file_hdr_raw ){ open(RAW, "<$file_hdr_raw") or plog("Can NOT open <$SHA1_file_hdr_r +aw> for reading\n"); my(@lines) = <RAW>; close(RAW); while ( @lines ){ my $line = shift(@lines); my ($key, $value) = split(/:/, $line, 2); $headers->header( $key => $value ); } } # create response my $res = HTTP::Response->new($status_code, $status, $headers, $co +ntent); # send back (short-circuit normal content fetching) $self->proxy()->response($res);

    At least I have tested the above, mixed with other code, and it works, well. I turned on the proxy use with Firefox and used a FF plugin to verify I was receiving the complete content of a past header saved off.

    Thank you to everyone for their help.