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 Header Filter:{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 Body 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; }
Thank you in advance for any commentary.{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; }
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |