Re: Header formats in get.pl

Roy T. Fielding (fielding@avron.ICS.UCI.EDU)
Mon, 08 May 1995 18:59:29 -0700


> What is the significance of the block
> 
> [snip]
> 
>         if ($headers)
>         {
>             print($Out $headers);
>         }
>         else
>         {
>             print($Out "HTTP/1.0 $response $wwwerror'RespMessage{$response}\n");
>             foreach $hd (keys(%headers))
>             {
>                 next if ($hd =~ m#^[A-Z]#);
>                 print($Out "$hd: $headers{$hd}\n");
>             }
>         }
>         print($Out "\n");
> 
> [snip]
> 
> in the get.pl example?
> 
> i.e.
> 
> When will the headers come back in the associative array rather than the
> string? (When I test it with the GET method, they always come back as
> $headers)

$headers stores the actual (unparsed) headers when a server response is
received -- it remains empty if the request did not get a response.

%headers always contains the parsed headers as an associative array.
If no response is received, it contains the canned headers generated by the
internal error reporting routine.

> Is there a routine in the libraries somewhere for parsing this string back
> into an associative array anyway, as the string version isn't much use for
> anything...or am I missing the point?

The parsed ones are in %headers.  The reason for the conditional above
is because the get script is used for debugging purposes -- when the original,
unparsed headers are available, I'd prefer to see them in the original form.

 ....Roy T. Fielding  Department of ICS, University of California, Irvine USA
                                       <fielding@ics.uci.edu>
                      <URL:http://www.ics.uci.edu/dir/grad/Software/fielding>