[Date Prev][Date Next][Thread Prev][Thread Next] [Search] [Date Index] [Thread Index]

[MacPerl] full HTTP header wackiness




There was a thread a few weeks back about HTTP headers. Somebody had asked
about how to generate a redirect header, and Matthias had this to say:

+-Paul Hofmann's approach (giving full headers) is probably the preferred
+-one. The CGI glue actually also handles minimalist headers, so you can simply
+-write:
+-print "Location: http://www.microsoft.com/\n\n"
+-And the glue will translate the \n's to CRLF and the Location header to a full
+-blown redirect.

What the glue doesn't do, apparently, is generate the "Server: " line that
identifies the HTTP server software. (As you said, Matthias, "minimalist.")
Compare the following two headers... (output from EtherPeek demo, which is
available at <URL:ftp://ftp.aggroup.com/Public/demos/EtherPeek_Demo.sea.hqx>)

stock HTML document returned by Webstar:

  HTTP/1.0 304 Not   48 54 54 50 2f 31 2e 30 20 33 30 34 20 4e 6f 74
   Modified--MIME-   20 4d 6f 64 69 66 69 65 64 0d 0a 4d 49 4d 45 2d
  Version: 1.0--Se   56 65 72 73 69 6f 6e 3a 20 31 2e 30 0d 0a 53 65
  rver: WebSTAR/1.   72 76 65 72 3a 20 57 65 62 53 54 41 52 2f 31 2e
  2.4 ID/4745--Mes   32 2e 34 20 49 44 2f 34 37 34 35 0d 0a 4d 65 73
  sage-ID: <ad2e7d   73 61 67 65 2d 49 44 3a 20 3c 61 64 32 65 37 64
  48.596@www.senti   34 38 2e 35 39 36 40 77 77 77 2e 73 65 6e 74 69
  us.com>--Date: F   75 73 2e 63 6f 6d 3e 0d 0a 44 61 74 65 3a 20 46
  riday, 26-Jan-96   72 69 64 61 79 2c 20 32 36 2d 4a 61 6e 2d 39 36
   20:44:56 GMT--L   20 32 30 3a 34 34 3a 35 36 20 47 4d 54 0d 0a 4c
  ast-Modified: Fr   61 73 74 2d 4d 6f 64 69 66 69 65 64 3a 20 46 72
  iday, 26-Jan-96    69 64 61 79 2c 20 32 36 2d 4a 61 6e 2d 39 36 20
  00:36:16 GMT--Co   30 30 3a 33 36 3a 31 36 20 47 4d 54 0d 0a 43 6f
  ntent-type: text   6e 74 65 6e 74 2d 74 79 70 65 3a 20 74 65 78 74
  /html--Content-l   2f 68 74 6d 6c 0d 0a 43 6f 6e 74 65 6e 74 2d 6c
  ength: 109----     65 6e 67 74 68 3a 20 31 30 39 0d 0a 0d 0a

HTML generated by Perl script, which generated only the Content-type line:

  HTTP/1.0 200 OK-   48 54 54 50 2f 31 2e 30 20 32 30 30 20 4f 4b 0d
  -Content-type: t   0a 43 6f 6e 74 65 6e 74 2d 74 79 70 65 3a 20 74
  ext/html----<htm   65 78 74 2f 68 74 6d 6c 0d 0a 0d 0a 3c 68 74 6d
  l><head><title>Q   6c 3e 3c 68 65 61 64 3e 3c 74 69 74 6c 65 3e 51

(The HTTP/1.0 200 OK must have been inserted by the PCGI glue.)

So I did some digging, and found (in a post from Paul Hoffman)
that there is an environment variable that should hold the server's ID
string: $ENV{SERVER_SOFTWARE}

I coded this into a new MacPerl script as a header line, e.g.
                print "HTTP/1.0 200 OK\n";
                print "MIME-Version: 1.0\n";
                print "Server: $ENV{SERVER_SOFTWARE}\n";
                print "Location: $RefURL\n";
                print "Content-Type: text/html\n\n";
and then used EtherPeek again to see if the header matched what
WebSTAR would generate on its own (as shown in the first example, above)...

but this is what I got:

   HTTP/1.0 200 OK-   48 54 54 50 2f 31 2e 30 20 32 30 30 20 4f 4b 0d
  -MIME-Version: 1   0a 4d 49 4d 45 2d 56 65 72 73 69 6f 6e 3a 20 31
  .0--Server: MacH   2e 30 0d 0a 53 65 72 76 65 72 3a 20 4d 61 63 48
  TTP/2.0--Locatio   54 54 50 2f 32 2e 30 0d 0a 4c 6f 63 61 74 69 6f
  n: --Content-Typ   6e 3a 20 0d 0a 43 6f 6e 74 65 6e 74 2d 54 79 70
  e: text/html----   65 3a 20 74 65 78 74 2f 68 74 6d 6c 0d 0a 0d 0a
  <HTML><HEAD><TIT   3c 48 54 4d 4c 3e 3c 48 45 41 44 3e 3c 54 49 54

[Note that $RefURL hadn't been defined, whoops, and so had no value on output.]

Where did MacHTTP/2.0 come from?! Is the glue not getting the right
data? As I understand it, WebSTAR sends this info as part of the "svnm"
parameter of the Apple Event that contains the CGI request. Anybody
have any ideas?

--
matt.
mcglynn@sentius.com