以下は、Net::Server::HTTP の簡単なスクリプトです。
#!/usr/bin/env perl
use strict;
use warnings;
use v5.12;
use HTTP::Headers;
use base qw(Net::Server::HTTP);
__PACKAGE__->run(port => 'localhost:8421');
sub process_http_request
{
my ($self) = @_;
my $header = HTTP::Headers->new();
$header->content_type('text/html');
print $header->as_string() . "\n"; # <- this works
# say $header->as_string() . "\n"; # <- this doesn't work and I still have to add a newline
say "<!doctype html>";
say "<html>";
say "<head>";
say " <title>Test</title>";
say "</head>";
say "<body>";
say "<h1>Test</h1>";
say "</body>";
say "</html>";
}
使用say
することで改行を追加できると思いましたが、それを追加する必要があり、HTTP::Header
各HTTPフィールドに別の改行を追加するas_string
ことで. 誰かがここで実際に何が起こっているのか説明してもらえますか?