Gossamer Forum
Home : General : Perl Programming :

Non-parsed headers

Quote Reply
Non-parsed headers
Pirate My eyes have glazed over and I still can't seem to get this simple multi-page nonparsed header script to work. If anyone could take a look at it, I'd appreciate it.

Code:
#!/usr/local/bin/perl
# NPH scripts requires that all scripts begin with the characters nph-
$| = 1;
print <<EOF ;
$ENV{'SERVER_PROTOCOL'} 200 OK
Server: $ENV{'SERVER_SOFTWARE'}
Content-type: multipart/x-mixed-replace; boundary=End
EOF

for ($loop = 0; $loop < 4; $loop++) {
print "--End\n";
print "Content-type: text/plain\n\n";
print "time=".time."\n";
if ($loop==3) {
print "--End--\n";
}
sleep (2);
}

exit (0);

Here's what it's returning...
Code:
time=1021881038
--End
Content-type: text/plain

time=1021881040
--End
Content-type: text/plain

time=1021881042
--End
Content-type: text/plain

time=1021881044
--End--

Last edited by:

oldmoney: May 20, 2002, 1:02 AM
Quote Reply
Re: [oldmoney] Non-parsed headers In reply to
Yep.. That makes perfect sense because that's exactly what you're outputting.

What did you expect?

If you only expected time=xxxx then get rid of these lines:

print "--End\n";
print "Content-type: text/plain\n\n";

They're redundant anyway as you've already printed a header.

- wil

Last edited by:

Wil: May 20, 2002, 1:47 AM
Quote Reply
Re: [Wil] Non-parsed headers In reply to
I expected with Content-type: multipart/x-mixed-replace; boundary=End for the page to be redisplayed from the top at each -end break. Is that not correct?
Quote Reply
Re: [oldmoney] Non-parsed headers In reply to
Hm. I don't know nothing about nph- scripts, but I'll give a shot at cleaning up your code from bits and bobs I've read on the web. I've come up with this (untested):

Code:
#!/usr/local/bin/perl

$| = 1;

print qq|$ENV{'SERVER_PROTOCOL'} 200 OK\n|;
print qq|Server: $ENV{'SERVER_SOFTWARE'}\n|;
print qq|Content-type: multipart/x-mixed-replace; boundary=End\n\n|;

print qq|--End\n|;

for ($loop = 0; $loop < 4; $loop++) {

print qq|Content-type: text/plain\n\n|;
print qq|time=".time."\n|;
sleep (2);
print qq|\n--End\n|;

}

exit (0);

- wil
Quote Reply
Re: [Wil] Non-parsed headers In reply to
Strange. It works using Mozilla but IE seems to choke on the headers. Reason being that IE doesn't support multipart MIME headers. Marvellous browser that IE, you know ;-)

- wil

Last edited by:

Wil: May 20, 2002, 3:45 AM
Quote Reply
Re: [Wil] Non-parsed headers In reply to
Hm. This seems to work for me in Mozilla, too, but again Microsoft's IE just doesn't understand the header being sent to it. Can you run this OK?

Code:
#!/usr/local/bin/perl

$| = 1;

print qq|HTTP/1.1 200\n|;
print qq|Content-type: multipart/x-mixed-replace; boundary=End\n\n|;

print qq|--End\n|;

$i = 0;
while ($i < 4) {
$i++;
print qq|Content-type: text/plain\n\n|;
print qq|time="time"\n|;
print qq|--End\n|;
sleep 2;
}

- wil

Last edited by:

Wil: May 20, 2002, 3:50 AM
Quote Reply
Re: [Wil] Non-parsed headers In reply to
Yup, can confirm it works in Navigator but not IE for me either. Shocked

Thanks for looking at it... but it's back to the drawing board for another way to do server push to accomodate IE.
Quote Reply
Re: [oldmoney] Non-parsed headers In reply to
There is an example in the CGI docs on how to use push to do this. Look here:

http://stein.cshl.org/...I/cgi_docs.html#push

- wil
Quote Reply
Re: [Wil] Non-parsed headers In reply to
Thanks, Wil... should of consulted those documents first. The last line says IE does not support server-push. Time to breakout the fork. Smile

Last edited by:

oldmoney: May 20, 2002, 5:41 AM
Quote Reply
Re: [oldmoney] Non-parsed headers In reply to
Check out the article than Randall Schwartz (veteran Perl hacker) is currently writing for next month's Perl Journal magazine. This could be of help to you:

http://www.stonehenge.com/pic/col39.pod

- wil
Quote Reply
Re: [Wil] Non-parsed headers In reply to
Thanks, Wil... bookmarked Shwartz's site as it has some excellent examples. The reference you pointed me to gets me part way to a solution, but it is still pretty cludgy. I'll start a new topic since this one no longer has anything to do with nph. :)