-
-
-
-sub build_cgi_env {
- my %args = ( query_string => '',
- path => '',
- port => undef,
- protocol => undef,
- localname => undef,
- method => undef,
- remote_name => undef,
-
-
- @_);
-
- foreach my $var qw(USER_AGENT CONTENT_LENGTH CONTENT_TYPE
- COOKIE SERVER_PORT SERVER_PROTOCOL SERVER_NAME
- PATH_INFO REQUEST_URI REQUEST_METHOD REMOTE_ADDR
- REMOTE_HOST QUERY_STRING SERVER_SOFTWARE) {
- delete $ENV{$var};
- }
- while (<STDIN>) {
- s/[\r\l\n\s]+$//;
- if( /^([\w\-]+): (.+)/i) {
- my $tag = uc($1);
- $tag =~ s/^COOKIES$/COOKIE/;
- my $val = $2;
- $tag =~ s/-/_/g;
- $tag = "HTTP_".$tag unless (grep /^$tag$/, qw(CONTENT_LENGTH CONTENT_TYPE COOKIE));
- if ($ENV{$tag}) {
- $ENV{$tag} .= "; $val";
- }
- else {
- $ENV{$tag} = $val;
- }
- }
- last if (/^$/);
- }
-
-
- $ENV{SERVER_PROTOCOL} = $args{protocol};
- $ENV{SERVER_PORT} = $args{port};
- $ENV{SERVER_NAME} = $args{'localname'};
- $ENV{SERVER_URL} = "http://".$args{'localname'}.":".$args{'port'}."/";
- $ENV{PATH_INFO} = $args{'path'};
- $ENV{REQUEST_URI} = $args{'request_uri'};
- $ENV{REQUEST_METHOD} = $args{method};
- $ENV{REMOTE_ADDR} = $args{'peeraddr'};
- $ENV{REMOTE_HOST} = $args{'peername'};
- $ENV{QUERY_STRING} = $args{'query_string'};
- $ENV{SERVER_SOFTWARE} = "rt-standalone/$RT::VERSION";
-
- CGI::initialize_globals();
-}