On Nov 22, 2010, at 5:47 PM, Bruno Rocha wrote:
> Keep in mind that routes.py doesn't enter the picture for anything being
> served directly by the host server (I see you're using nginx).
>
> Aside from figuring out how to serve the images directly, I see a couple of
> other problems. Here's the header from one of the dogs:
>
> HTTP/1.1 200 OK
> Server: nginx
> Date: Tue, 23 Nov 2010 01:13:44 GMT
> Content-Type: image/jpeg
> Connection: keep-alive
> Set-Cookie:
> session_id_init=174-144-113-160-a877555e-5e01-4be1-ab2e-21a592878bb9; Path=/
> Expires: Tue, 23 Nov 2010 01:13:44 GMT
> Pragma: no-cache
> Cache-Control: no-store, no-cache, must-revalidate, post-check=0, pre-check=0
> Content-Length: 38773
>
> Notice the no-cache pragma: that doesn't make any sense, unless you're
> setting no-cache just for debugging.
>
> This website is based on e-store appliance, and I did not change anything on
> headers, no-cache is not being set on application (I made a search on this).
>
> Also, the image for Gabby (this is the headers we're looking at) is served as
> 480x393, and 38KB. But you're displaying it as 160x122. So you're sending 10
> times as many pixels as you're going to display.
>
> Yes, this is a problem and I have a solution now, I will use PIL to create
> small thumbs (just have to figure out how to process every image on /uploads,
> create the thumb and insert this path do db)
>
> You really want to shrink your images on the server, and not at the browser.
> (Also, fwiw, your width shrink isn't proportional here, which is a minor
> problem.)
>
>
> Thank you for the help.
>
> BTW: Do you know how can I see if the image is served by apache/nginx or by
> web2py function?
That's what I was trying to see when I collected the headers above. Here's what
you can do for static files (it's a bit of a hack, but what the hell?):
In gluon/main.py, you'll see this:
static_file = parse_url(request, environ)
if static_file:
if request.env.get('query_string', '')[:10] == 'attachment':
response.headers['Content-Disposition'] = 'attachment'
response.stream(static_file, request=request)
Add a line to add a header line:
static_file = parse_url(request, environ)
if static_file:
if request.env.get('query_string', '')[:10] == 'attachment':
response.headers['Content-Disposition'] = 'attachment'
response.headers['X-Bruno-Rocha'] = 'static'
response.stream(static_file, request=request)
Then you should see the X-Bruno-Rocha header on static files served by web2py,
but not directly by the host server. Alternatively, do this:
static_file = parse_url(request, environ)
response.headers['X-Bruno-Rocha'] = 'web2py'
if static_file:
if request.env.get('query_string', '')[:10] == 'attachment':
response.headers['Content-Disposition'] = 'attachment'
response.stream(static_file, request=request)
to add the header to all your responses.