Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Skip dumping the buffer in STARMAN_DEBUG=1 #129

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 13 additions & 4 deletions lib/Starman/Server.pm
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ package Starman::Server;
use strict;
use base 'Net::Server::PreFork';

use Data::Dump qw(dump);
use Data::Dump;
use Socket qw(IPPROTO_TCP TCP_NODELAY);
use IO::Socket qw(:crlf);
use HTTP::Parser::XS qw(parse_http_request);
Expand All @@ -15,12 +15,21 @@ use Plack::Util;
use Plack::TempBuffer;

use constant DEBUG => $ENV{STARMAN_DEBUG} || 0;
use constant DEBUG_BUF => (DEBUG >= 2);
use constant CHUNKSIZE => 64 * 1024;

my $null_io = do { open my $io, "<", \""; $io };

use Net::Server::SIG qw(register_sig);

sub dump_buffer($) {
if (DEBUG_BUF) {
Data::Dump::dump($_[0]);
} else {
return "(" . length($_[0]) . " bytes of data)";
}
}

# Override Net::Server's HUP handling - just restart all the workers and that's about it
sub sig_hup {
my $self = shift;
Expand Down Expand Up @@ -305,7 +314,7 @@ sub process_request {
if ( $self->{client}->{inputbuf} =~ /^(?:GET|HEAD)/ ) {
if ( DEBUG ) {
warn "Pipelined GET/HEAD request in input buffer: "
. dump( $self->{client}->{inputbuf} ) . "\n";
. dump_buffer( $self->{client}->{inputbuf} ) . "\n";
}

# Continue processing the input buffer
Expand All @@ -315,7 +324,7 @@ sub process_request {
# Input buffer just has junk, clear it
if ( DEBUG ) {
warn "Clearing junk from input buffer: "
. dump( $self->{client}->{inputbuf} ) . "\n";
. dump_buffer( $self->{client}->{inputbuf} ) . "\n";
}

$self->{client}->{inputbuf} = '';
Expand Down Expand Up @@ -354,7 +363,7 @@ sub _read_headers {
}

if ( DEBUG ) {
warn "[$$] Read $read bytes: " . dump($buf) . "\n";
warn "[$$] Read $read bytes: " . dump_buffer($buf) . "\n";
}

$self->{client}->{inputbuf} .= $buf;
Expand Down
8 changes: 6 additions & 2 deletions script/starman
Original file line number Diff line number Diff line change
Expand Up @@ -230,8 +230,12 @@ common backend that L<plackup> uses, so the most options explained in
C<plackup -h> such as C<--access-log> or C<--daemonize> works fine in
starman too.

Setting the environment variable C<STARMAN_DEBUG> to 1 makes the
Starman server running in the debug mode.
Setting the environment variable C<STARMAN_DEBUG> to 1 or larger makes
the Starman server running in the debug mode.

Since version 0.4015, setting C<STARMAN_DEBUG> to 1 will not dump the
content of the request buffer besides its size information. To get the
full dump output, you have to set the value to 2 or larger.

=cut

Expand Down