Skip to content

Commit

Permalink
fixed small CGI bug
Browse files Browse the repository at this point in the history
  • Loading branch information
kraih committed Sep 12, 2011
1 parent 6ad59ed commit 164701e
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 7 deletions.
4 changes: 3 additions & 1 deletion lib/Mojo/Server/CGI.pm
Expand Up @@ -21,6 +21,7 @@ sub run {
$tx->local_port($ENV{SERVER_PORT});

# Request body
binmode STDIN;
while (!$req->is_done) {
my $read = STDIN->read(my $buffer, CHUNK_SIZE, 0);
last unless $read;
Expand All @@ -29,9 +30,10 @@ sub run {

# Handle
$self->on_request->($self, $tx);
STDOUT->autoflush(1);

# Response start line
STDOUT->autoflush(1);
binmode STDOUT;
my $res = $tx->res;
my $offset = 0;
if ($self->nph) {
Expand Down
7 changes: 1 addition & 6 deletions t/mojo/cgi.t
@@ -1,7 +1,7 @@
#!/usr/bin/env perl
use Mojo::Base -strict;

use Test::More tests => 17;
use Test::More tests => 16;

use Mojo::Message::Response;

Expand Down Expand Up @@ -98,8 +98,3 @@ is $res->headers->content_type, 'application/json',
is $res->headers->content_length, 27, 'right "Content-Length" value';
is $res->json->{lalala}, 23, 'right value';
is $res->json->{bar}, 'baz', 'right value';

# Test closed STDOUT
my $cgi = Mojo::Server::CGI->new;
close(STDOUT);
ok((not defined $cgi->run), 'working with closed STDOUT');

0 comments on commit 164701e

Please sign in to comment.