Received: by 10.86.51.10 with SMTP id y10mr79695fgy.14.1216816940669; Wed, 23 Jul 2008 05:42:20 -0700 (PDT) Return-Path: Received: from yx-out-1718.google.com ([172.21.6.34]) by mx.google.com with ESMTP id 39si9079437yxd.0.2008.07.23.05.42.19; Wed, 23 Jul 2008 05:42:20 -0700 (PDT) Received-SPF: neutral (google.com: 172.21.6.34 is neither permitted nor denied by domain of graham.dumple...@gmail.com) client-ip=172.21.6.34; Authentication-Results: mx.google.com; spf=neutral (google.com: 172.21.6.34 is neither permitted nor denied by domain of graham.dumple...@gmail.com) smtp.mail=graham.dumple...@gmail.com; dkim=pass (test mode) header...@gmail.com Received: by yx-out-1718.google.com with SMTP id 34so919851yxf.74 for ; Wed, 23 Jul 2008 05:42:19 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:received:received:message-id:date:from:to :subject:in-reply-to:mime-version:content-type :content-transfer-encoding:content-disposition:references; bh=TVM/F3IdGsIDXcOLBcnLcS6G8WOvSril3Uar3i04t9Q=; b=rVfV+9OlpFPBv+pOTSCp4okzr1gmucamzoJ8Yy68xYJHVakhmtZA9CSNB4ckOFSPgX 7eoCbK4T1mpC+yKnylPquXjYa9v6mM3x5XTYcDAZai0O1LOTconnk3igoP4y/fsYdIRg C0BTrEu/9WXPODBMMddMDShQ3apIBHIj+XugQ= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=message-id:date:from:to:subject:in-reply-to:mime-version :content-type:content-transfer-encoding:content-disposition :references; b=DINpZBoaZpwglbaPZywXPkJsN2sUndyty61bZ8lXWFXPzhNlEeNILBxcb0b2p5k5HY xBWluKcsePIpiJh8XNJU+E0ElTdrXggFPpKQaW/1g/gBILfJdIRjCoNhJpl4pb7qdaj1 h65Culxj+U1pSd68O/om3OemHGcD8fyKJpamM= Received: by 10.150.54.6 with SMTP id c6mr50253yba.107.1216816939375; Wed, 23 Jul 2008 05:42:19 -0700 (PDT) Received: by 10.150.181.20 with HTTP; Wed, 23 Jul 2008 05:42:19 -0700 (PDT) Message-ID: <88e286470807230542g36a81818yd1eaf8f7ece49b5c@mail.gmail.com> Date: Wed, 23 Jul 2008 22:42:19 +1000 From: "Graham Dumpleton" To: modwsgi@googlegroups.com Subject: Re: [modwsgi] wsgi.file_wrapper and range headers In-Reply-To: <4505ad26-38f8-4ce8-a013-86c71c41d...@l64g2000hse.googlegroups.com> MIME-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit Content-Disposition: inline References: <4505ad26-38f8-4ce8-a013-86c71c41d...@l64g2000hse.googlegroups.com> 2008/7/23 Graham Carlyle : > > Hi > > I'm using django with mod_wsgi to dynamically serve some PDFs from a > website. I'm patching django in order to utilise the file_wrapper > speedup... > > http://code.djangoproject.com/ticket/7894 > > So my question is .. how can i support range headers with the > file_wrapper speedup? My tests suggest that the range header is being > ignored with the whole file being returned. > > I'm trying to get this to work as it seems the Adobe Acrobat 7.0 PDF > plug-in on Windows causes Firefox to fail downloading the PDF unless > it can retrieve the file using range headers. > > I'm guessing that mod_wsgi isn't trying to support the range header > and so I either have to deal with it in my webapp which seems a shame > as apache already has the functionality, or I have to use something > like a caching proxy infront of apache (say squid). You would have to handle range headers yourself in application that is just how WSGI is. That is, WSGI expects everything to be done in application. For it to work, just open file in 'rb' mode, seek to appropriate position in file, set Content-Length for how much you want sent and then wrap it in wsgi.file_wrapper and return it. Note that mod_wsgi is however probably the only WSGI hosting mechanism available which will actually look at the Content-Length returned for wsgi.file_wrapper and only send that much of the file from the current seek position. All other WSGI hosting adapters I have seen will just return from current seek position to end of file. Thus the others could return much more data than necessary and it would be up to client to ignore what was returned in excess of the content length. Even the FileWrapper example in WSGI PEP explaining what to use when wsgi.file_wrapper isn't supported by WSGI adapter doesn't look at Content-Length. Thus, if using FileWrapper to support other WSGI adapters without wsgi.file_wrapper extension, you may want to modify the FileWrapper example from WSGI PEP to honour Content-Length. That all said, you may thus have problems adding this support in Django if mod_wsgi which handles it properly. Graham