in reply to Re: How to display an image on a webpage with minimal code
in thread How to display an image on a webpage with minimal code

Hmm, URI works v. nicely, but Ihad some problems implementing a 307.

My code was:

print "HTTP/1.1 307 temporary redirect\n"; print "Location: " . URI->new_abs($files[int(rand @files)], "http://bu +gzilla") . "\n\n";

But this didn't redirect me unless I removed the 307 line...

Tom Melly, tom@tomandlu.co.uk

Replies are listed 'Best First'.
Re^3: How to display an image on a webpage with minimal code
by bart (Canon) on Nov 16, 2006 at 19:59 UTC
    n.b. I finally got around to test this. Hence the belated reply.

    Wow, hold it, you're doing this too low level. You're not supposed to be doing this the NPH way, there's still a webserver between the CGI scripts and the web browser, and that one is still postprocessing the headers that the CGI script sent to it — for example, adding a content-length header for plain pages. And there's a special pseudo-header for status codes: Status:.

    When I did this on Apache 2 on my laptop:

    print "Status: 307 Temporary redirect\n"; print "Location: " . URI->new_abs($files[int(rand @files)], "http://lo +calhost/") . "\n\n";
    then the headers that Live HTTP Headers displayed were:
    HTTP/1.x 307 Temporary redirect Date: Thu, 16 Nov 2006 19:55:06 GMT Server: Apache/2.0.50 (Win32) mod_perl/1.99_16 Perl/v5.8.8 PHP/4.3.8 Location: http://localhost/images/060210-leaf.jpg Content-Length: 0 Keep-Alive: timeout=15, max=100 Connection: Keep-Alive Content-Type: text/plain; charset=ISO-8859-1
    So the headers that got sent to the browser, are looking fine to me.

      Ah, many thanks, that makes sense... btw even with the temporary redirect, I still see some caching (either that, or perls rand is hosed;). Still, I guess that could be any number of misbehaving services (and, given that this is all taking place within an intranet, I suppose there may be any number of factors).

      Many thanks again.

      Tom Melly, tom@tomandlu.co.uk