Hi, I'm trying to create a proxy to edit images.

The problem is, the images comes in chunks and can't be worked with that way, not that I know of anyway.

I've tried setting the protocol to HTTP/1.0 in filters, but in wireshar I see the request still go as HTTP/1.1.(as do the responses)

I suspect that it is the proxies UA that is using HTTP/1.1 and the only way I found to change it is through environment variables, which didn't work.

Using the filter HTTP::Proxy::BodyFilter::Complete, I can access the whole image, not just chunks, but I can't edit it.

#!/usr/bin/perl use strict; use warnings; use Env qw(PERL_LWP_USE_HTTP_10); use HTTP::Proxy qw/:log/; use HTTP::Headers; use HTTP::Proxy::BodyFilter::complete; use HTTP::Proxy::HeaderFilter::simple; use HTTP::Proxy::BodyFilter::simple; use String::Random; #configuration my $port = 8080; my $proxyLogFile = "/tmp/sampleProxy.pl.log"; my $logMask = PROXY | STATUS | HEADERS | FILTERS | CONNECT; #logging open(LOG ,'>>'.$proxyLogFile); my $bodyFilter = HTTP::Proxy::BodyFilter::simple->new( sub { my ( $self, $dataref, $message, $protocol, $buffer ) = @_; $message->protocol("HTTP/1.0"); print "BODYFILTER\n"; #print "Protocol: '".$protocol."'\n"; print "MESSAGE:\n-------\n"; print $message->as_string."-------\n"; print "\n"; } ); my $imgFilter = HTTP::Proxy::BodyFilter::simple->new( sub { my ( $self, $dataref, $message, $protocol, $buffer ) = @_; my $rand = new String::Random; print "IMAGEFILTER\n"; print $message->as_string."\n"; print "--------\n\n"; if(length($$dataref)){ print "Image length is not 0, there is a image!\n"; my $name = $message->header('Content-Type'); $name =~ s/image\/(.+)$/$1/gi; $name = $rand->randregex('\d\d\d').'.'.$name; print "SAving image as $name\n"; open IMAGE, ">>".$name or die "erro:$!\n"; print IMAGE $$dataref; close IMAGE; print "Flipping Image\n"; system("convert $name -flip $name"); print "Sending Image\n"; open IMAGE, $name or die "erro:$!\n"; my $newImage = <IMAGE>; $$dataref = $newImage; } } ); my $proxy = HTTP::Proxy->new; $proxy->port($port); $proxy->logfh(*LOG); $proxy->logmask( $logMask ); #debug #push filters $proxy->push_filter( request => $bodyFilter ); $proxy->push_filter( mime => 'image/*', response => HTTP::Proxy::BodyFilter::complete->new, response=>$imgFilter); $proxy->agent->env_proxy; $proxy->start; close(LOG);
Any insight is appreciated.

In reply to Chunk problem in HTTP::Proxy by snakerdlk

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.