Fellow monks,

I'm asking for your advice.

My company proxy likes to break HTTP protocol and insists repeatedly to deploy full content instead of content-ranged, as requested.

Up to now, everything OK, the problem comes when its time to yum install anything.

Yum asks for package headers using content-range to a server that support that and proxy returns full. Expect a header and receive a full rpm. Result is wrong checksum, no deal.

Having some experience with HTTP::Proxy, I am thinking of writing a BodyFilter to throw away content out of the range. Do you, dear monks, think is wise to use HTTP::Proxy to do this? Is there any other tool capable of doing this?

Sample, untested, non functional code follows

The new Proxy Class
{package HTTP::Proxy::ContentRange; use base HTTP::Proxy; use HTTP::Proxy::HeaderFilter::contentrange; use HTTP::Proxy::BodyFilter::complete; use HTTP::Proxy::BodyFilter::contentRange; use strict; sub new { my $class = shift; my $self = SUPER::new(@_); # Whe depend on HPB::complete. $self->push_filter( response => HTTP::Proxy::HeaderFilter::contentrange->new, response => HTTP::Proxy::BodyFilter::complete->new, response => HTTP::Proxy::BodyFilter::contentRange->new); return $self; }
The Header Filter:
{package HTTP::Proxy::HeaderFilter::contentrange; use HTTP::Proxy; use base HTTP::Proxy::HeaderFilter; use strict; sub filter(){ my ( $self, $headers, $message) = @_; if ( $message->isa('HTTP::Response') and $message->code == 200 and $range = $message->request->header('Content-Range') ){ #Let's fix that nasty behaviour! ;-) $message->code(206); $message->header('Content-Range' => $range); #XXX: Find a way to calc content-lenght $message->remove_header('Content-Length'); #Mark this for body processing! $self->SUPER::proxy->stash($message->uri => 1); } } 1; }
The Body Filter:
{package HTTP::Proxy::BodyFilter::contentRange; use HTTP::Proxy; use base HTTP::Proxy::BodyFilter; use strict; use base HTTP::Proxy::BodyFilter; } sub filter{ my ($self, $dataref, $message, $protocol, $buffer) = @_; #Was this response marked for processing? if ( SUPER::proxy->stash($message->uri) == 1 ){ ###### # TO IMPLEMENT # Parse Content-Range and select data to send. ###### #XXX: Wouldn't be wise to save content to a temp file and avo +id # filling up memory. Maybe use HPB::save? #Delete entry from process table delete SUPER->proxy->stash{$message->uri}; } } 1; }
Thank you in advance for any commentary.

In reply to Is wise to use HTTP::Proxy to enforce correct Content-Range responses? by motobói

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.