Skip to content

Commit

Permalink
Support ChunkedInput in HTTP::Request->to_psgi
Browse files Browse the repository at this point in the history
  • Loading branch information
miyagawa committed Feb 9, 2010
1 parent 0dade34 commit 185e1e9
Showing 1 changed file with 27 additions and 1 deletion.
28 changes: 27 additions & 1 deletion lib/HTTP/Message/PSGI.pm
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,13 @@ sub req_to_psgi {
# Plack::Request :/
utf8::downgrade $$uri;

open my $input, "<", \do { $req->content };
my $input;
my $content = $req->content;
if (ref $content eq 'CODE') {
$input = HTTP::Message::PSGI::ChunkedInput->new($content);
} else {
open $input, "<", \$content;
}

my $env = {
PATH_INFO => URI::Escape::uri_unescape($uri->path),
Expand Down Expand Up @@ -138,6 +144,26 @@ sub HTTP::Response::from_psgi {
res_from_psgi(@_);
}

package
HTTP::Message::PSGI::ChunkedInput;

sub new {
my($class, $content) = @_;
bless { content => $content }, $class;
}

sub read {
my $self = shift;
my $chunk = $self->{content}->();
return 0 unless defined $chunk;
$_[0] = $chunk;
return length $chunk;
}

sub close { }

package HTTP::Message::PSGI;

1;

__END__
Expand Down

0 comments on commit 185e1e9

Please sign in to comment.