Skip to content

Net::HTTP does not allow buffer size to be overridden in subclass [rt.cpan.org #25069] #38

@oalders

Description

@oalders

Migrated from rt.cpan.org#25069 (status was 'open')

Requestors:

From dpisoni@cpan.org on 2007-02-21 22:00:19:

In Net::HTTP, read_response_headers() uses the function my_readline() to do it's dirty-work.  
Under the hood, my_readline() calls sysread() with a HARD-CODED size of 1024.  Ideally, this 
should be an option, or otherwise parameterized.  Alternately, it would make sense to 
replace my_readline() in a subclass, but this is impossible since it is called as a function.  One 
would need to replace read_response_headers() entirely in a subclass if one wanted to 
change the behavior here (to capture a larger buffer in the first read, cutting down on 
latency.) Alternately, one could redefine the my_readline() function.  The last two options are 
terrible designs, since they involve cloning the existing code and replacing only a small bit, 
and may result in future incompatibilities.

	    my $n = $self->sysread($_, 1024, length);

I suggest you expose or otherwise parameterize this currently hard-coded value.

Here is my current (nasty) workaround in a subclass:
package MyNetHTTP;
use base 'Net::HTTP';
sub my_sysread {
    my $self = shift;
    $_[1] = $READ_BUFFER_LENGTH;
    $self->SUPER::sysread(@_);
}

sub read_response_headers {
    my $self = shift;
    local *sysread = *my_sysread;
    $self->SUPER::read_response_headers( @_ );
}

From ether@cpan.org on 2017-01-25 21:40:44:

migrated queues: libwww-perl -> Net-HTTP

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions