Database Reference
In-Depth Information
The cache-control headers suppress caching for links to banner.py that occur over the
course of successive page requests. Another complication occurs if multiple links to the
script occur within the same page. The following page illustrates what happens:
<!-- bannertest2.html: page with multiple links to banner-ad script -->
<html>
<head><title> Banner Ad Test Page 2 </title></head>
<body>
<p> You should see two images below this paragraph,
and they probably will be the same. </p>
<img src= "/cgi-bin/banner.py" />
<img src= "/cgi-bin/banner.py" />
<p> You should see two images below this paragraph,
and they probably will be different. </p>
<img src= "/cgi-bin/banner.py?image1" />
<img src= "/cgi-bin/banner.py?image2" />
</body>
</html>
The first pair of links to banner.py are identical. What you'll probably find when you
request this page is that your browser notices that fact, sends only a single request to
the web server, and uses the image that is returned where both links appear in the page.
As a result, the first pair of images displayed in the page will be identical. The second
pair of links to banner.py show how to solve this problem. The links include some extra
fluff at the end of the URLs that make them look different. banner.py doesn't use that
information at all, but making the links look different fools the browser into sending
two image requests. The result is that the second pair of images differ from each other,
unless banner.py happens to randomly select the same image both times.
19.9. Serving Query Results for Download
Problem
You want to send database information to a browser for downloading rather than for
display.
Solution
Unfortunately, there's no good way to force a download. A browser processes informa‐
tion sent to it according to the Content-Type: header value, and if it has a handler for
that value, it treats the information accordingly. However, you may be able to trick the
browser by using a “generic” content type for which it's unlikely to have a handler.
Search WWH ::




Custom Search