Beefy Boxes and Bandwidth Generously Provided by pair Networks
Keep It Simple, Stupid
 
PerlMonks  

Re: A Picture A Day

by mortis (Pilgrim)
on Dec 19, 2001 at 20:43 UTC ( [id://133160]=note: print w/replies, xml ) Need Help??


in reply to A Picture A Day

Is a Location header ok without the HTTP status line? Do you need an HTTP 302 Redirect (or 303) status line before the location for a redirect? Or will most browsers handle the naked Location as a valid header?

Replies are listed 'Best First'.
Re: Re: A Picture A Day
by merlyn (Sage) on Dec 19, 2001 at 20:45 UTC
    The browser never sees it. This is a CGI header. The server interprets it as a request to go to that URL and start over. Thus, it'll even handle if-modified-since and last-modified correctly.

    -- Randal L. Schwartz, Perl hacker

      Thanks for the clarification -- even CGI.pm's redirect() method doesn't print the status line:
      perl -MCGI -e 'print CGI->new({})->redirect("/foo/b ar.cgi");'
      gives:
      Status: 302 Moved
      location: /foo/bar.cgi
      
      
      This doesn't apply to nph CGI's, correct?

      I didn't know that. Thanks

        For nph (non-parsable-headers, or something like that) CGI's, you need to construct all headers yourself, giving full freedom over what is being sent. With normal CGI, the _server_ interprets your Status-header, and will use it instead of its default "200" (OK) status => the Status header is not sent to the user agent.
        With a nph CGI, you need to construct the first line of the response yourself.

        # Normal CGI (The Status line is optional, the server will try to be i +ntelligent and guess it) Status: 302 Found Location: foo <blank line> # NPH CGI HTTP/1.1 302 Found Location: foo <blank line>

        2;0 juerd@ouranos:~$ perl -e'undef christmas' Segmentation fault 2;139 juerd@ouranos:~$

      The browser DOES see it. The webserver will add the status by itself, or takes it from the Status header.
      This means there'll be _two_ requests, one'll hit the request, one'll hit the image. If everything's fast enough, the user will never notice.

      a251111.upc-a.chello.nl - - [19/Dec/2001:16:55:17 +0100] "GET /test/te +st.cgi HTTP/1.1" 302 286 "-" "Mozilla/5.0 (compatible; Konqueror/2.2. +2; Linux 2.4.10-ac12; X11; i686; en)" a251111.upc-a.chello.nl - - [19/Dec/2001:16:55:18 +0100] "GET /test/te +st.txt HTTP/1.1" 304 - "-" "Mozilla/5.0 (compatible; Konqueror/2.2.2; + Linux 2.4.10-ac12; X11; i686; en)"
      The 302 status is "Found", which tells the browser to re-request using the URL in the Location-header.
      The 304 is "Not modified", telling my browser to use the cached version.

      2;0 juerd@serv:~/juerd.nl/juerd.nl/test$ cat test.cgi #!/usr/bin/perl print "Location: test.txt\n\n"; 2;0 juerd@serv:~/juerd.nl/juerd.nl/test$ cat test.txt; echo Hello world
      merlyn, perhaps you meant s/browser/user/; s/CGI/HTTP/; s/server/browser/?

      2;0 juerd@ouranos:~$ perl -e'undef christmas' Segmentation fault 2;139 juerd@ouranos:~$

        Not with Apache, CGI, and a proper absolute path that begins with a slash. The browser will never know it happens. There's something broken in your test.

        -- Randal L. Schwartz, Perl hacker

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://133160]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others chanting in the Monastery: (4)
As of 2024-04-19 05:41 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found