Permalink
Browse files

Set :input-line-separator instead of chomping and handle undef return…

… from IO::Socket::INET.get
  • Loading branch information...
1 parent d347fdc commit f855e6b0cf50b1d23c55d18e4d1b446f2f8c10ad @gerdr gerdr committed Mar 12, 2013
Showing with 9 additions and 2 deletions.
  1. +9 −2 lib/HTTP/Easy.pm6
View
@@ -35,7 +35,8 @@ method connect (:$port=$.port, :$host=$.host)
$!listener = IO::Socket::INET.new(
:localhost($host),
:localport($port),
- :listen(1)
+ :listen(1),
+ :input-line-separator("\r\n")
);
}
@@ -53,12 +54,18 @@ method run
if $.debug { message("Client connection received."); }
self.on-connection;
my $request = $!connection.get;
+ unless defined $request
+ {
+ if $.debug { message("Client connection lost."); }
+ $!connection.close;
+ next;
+ }
message($request);
my @headers;
my $in-headers = True;
while $in-headers
{
- my $line = $!connection.get.chomp;
+ my $line = $!connection.get;
if ! $line { $in-headers = False; }
if $.debug { $*ERR.say: " $line"; }
@headers.push($line);

0 comments on commit f855e6b

Please sign in to comment.