Skip to content

Instantly share code, notes, and snippets.

@mateu
Created January 22, 2015 18:14
Show Gist options
  • Save mateu/c08f6084c8d1516166b6 to your computer and use it in GitHub Desktop.
Save mateu/c08f6084c8d1516166b6 to your computer and use it in GitHub Desktop.
generate a warning for an incorrect Content-Length header
#!/usr/bin/env perl
use strict 'vars';
use warnings;
use Plack;
use Plack::Test::Agent;
use Socket;
my $server = 'Standalone';
my $app = sub { [ 200, [], ['hello, world'] ] };
my $agent = Plack::Test::Agent->new(
app => $app,
server => $server,
);
# contact the server
open_tcp( F, $agent->host, $agent->port )
or die 'Could not connect to server';
# Send request data
while ( my $request = <DATA> ) {
print F $request;
}
# Get Response
while ( my $response = <F> ) {
print "Response:> $response";
}
close( F );
# TCP Helper
sub open_tcp {
# get parameters
my ( $FS, $dest, $port ) = @_;
my $proto = getprotobyname( 'tcp' );
socket( $FS, PF_INET, SOCK_STREAM, $proto );
my $sin = sockaddr_in( $port, inet_aton( $dest ) );
connect( $FS, $sin );
my $old_fh = select( $FS );
$| = 1; # don't buffer output
select( $old_fh );
}
__DATA__
POST / HTTP/1.1
Content-Length: 10, 10
Foo Bar Baz
-END-
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment