Skip to content
Browse files

We support Buf body segments now, and handle them appropriately.

  • Loading branch information...
1 parent 1e0fda3 commit ce1a6fb92c0d06af27d3a0702a13683e8e215826 Timothy Totten committed Oct 24, 2012
Showing with 48 additions and 6 deletions.
  1. +16 −4 lib/HTTP/Easy.pm6
  2. +32 −2 lib/HTTP/Easy/PSGI.pm6
View
20 lib/HTTP/Easy.pm6
@@ -119,13 +119,25 @@ method run
}
}
- ## Call the handler. If it returns a string, it is assumed to be a valid
- ## HTTP response. If it returns an undefined value, we assume the handler
+ ## Call the handler.
+ ##
+ ## If it returns a defined value, it is assumed to be a valid HTTP
+ ## response, in the form of a Str(ing), a Buf, or an object that
+ ## can be stringified.
+ ##
+ ## If it returns an undefined value, we assume the handler
## sent the response to the client directly, and end the session.
my $res = self.handler;
if defined $res
- {
- $!connection.send($res);
+ {
+ if $res ~~ Buf
+ {
+ $!connection.write($res);
+ }
+ else
+ {
+ $!connection.send(~$str);
+ }
}
$!connection.close;
self.closed-connection;
View
34 lib/HTTP/Easy/PSGI.pm6
@@ -47,8 +47,38 @@ method handler
{
$output ~= $header.key ~ ': ' ~ $header.value ~ $CRLF;
}
- my $body = $result[2].join;
- $output ~= $CRLF ~ $body;
+ my @body = $result[2];
+ my $body;
+ for @body -> $segment
+ {
+ if ! $body.defined
+ {
+ $body = $segment;
+ }
+ elsif $body ~~ Buf
+ {
+ if $segment ~~ Buf
+ {
+ $body ~= $segment;
+ }
+ else
+ {
+ $body ~= $segment.Str.encode;
+ }
+ }
+ else
+ {
+ $body ~= $segment;
+ }
+ }
+ if $body ~~ Buf
+ {
+ $output = ($output~$CRLF).encode ~ $body;
+ }
+ else
+ {
+ $output ~= $CRLF ~ $body;
+ }
return $output;
}

1 comment on commit ce1a6fb

@azawawi
Collaborator

Syntax error at line 139

: ~$str -> $res

Please sign in to comment.
Something went wrong with that request. Please try again.