How do I access HTTP request headers in HTTP::Server::Simple::CGI?

杀马特。学长 韩版系。学妹 提交于 2019-12-11 10:12:14

问题


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";
    }
}


来源:https://stackoverflow.com/questions/3093160/how-do-i-access-http-request-headers-in-httpserversimplecgi

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!