How do I access HTTP request headers in HTTP::Serv

2019-07-26 06:04发布

问题:

I'm using HTTP::Server::Simple::CGI for a light-weight HTTP server. That gives me a CGI object in a callback function when a HTTP request is accepted.

How can I access the incoming HTTP headers, especially non-standard headers? The environment variables are only the standard ones.

cgi->param gives me only the form parameters.

Thanks! chris

回答1:

It says in the documentation:

You can, if you really want, define parse_headers() and parse them raw yourself.



回答2:

Define the headers method to receive the headers.

sub headers
{
    my $self = shift;
    my $headers = shift;
    my @h = @{$headers};

    while (0 + @h)
    {
        my $k = shift @h;
        my $v = shift @h;

        print STDERR "header >> $k: $v\n";
    }
}


标签: perl http cgi