[mod_python] ReportLab integration

Colin Bean ccbean at gmail.com
Tue Oct 17 12:16:16 EDT 2006


Great!  Glad to hear it finally worked out.  Another illogical IE
behavior has been (further) documented.
After some thought, it seems like clobbering the cache control header
would allow pages to be cached with the authentication headers intact,
so in a few situations (proxy-cache?) a user could possibly get ahold
of someone else's session if it's still valid (I haven't actually
tested this).  Hopefully this won't affect what you're doing, if your
main goal is to serve up pdfs and have it work.

-Colin

On 10/16/06, Jim Steil <jim at qlf.com> wrote:
>
> Hey, that did it!
>
> I changed the Cache-Control header to '' and now it works.  I will run it
> through more tests tomorrow, but for now it appears to be working.  Also, if
> I set the Content-Disposition to attachment, I get the filename that I
> specify in the filename parameter.  The filename doesn't seem to come
> through if I specify inline.
>
> Colin, I can't thank you enough for the help.  This will make it really easy
> to build dynamic pdf's and get them out to our users, and now I don't have
> to have them all pre-generated and stored on our servers.
>
>         -Jim
>
> -----Original Message-----
> From: Colin Bean [mailto:ccbean at gmail.com]
> Sent: Monday, October 16, 2006 6:52 PM
> To: Jim Steil
> Subject: Re: [mod_python] ReportLab integration
>
> Hi Jim,
>
> Well, I uncovered some weird behavior within IE, and I think I found
> part of the problem.  I wrote a standalone module (without publisher)
> that read a pdf off disk and sent the string value to the request, to
> try to simulate your module's behavior.  This is on Apache 2.2.0,
> mod_python 3.2.10 on Fedora Core 5, tested with IE 6 and firefox.
>
> It basically goes back to that comment in Graham's code about how
> setting the cache-control header caused IE to not display the PDF.
> While you never set these by hand, you do use a session cookie, which
> sets the Cache-Control header to 'no-cache="set-cookie"', and
> apparently this is enough to break IE.  In my test handler, the pdf
> displayed fine in the browser when I didn't use a session, but would
> only give me a "save to disk" dialog when I did.
>
> So you might try removing any session code from your example to see if
> it would work (I'm guessing you'll need some kind of authentication in
> the future so this is probably not going to be a long-term solution,
> but it should at least confirm that this is the problem).  Forgive my
> ignorance of publisher; I forget if it automatically creates a
> session.  If it does, the only way to get this to work would be as a
> standalone handler.
>
> Another option I found, which worked but seems sketchy was to set the
> Cache-Control header to an empty string right before sending the
> headers.  When I did this, the PDF displayed fine, and the pysid
> headers where still there, but I'd image that the cache-control header
> was there for a reason and I'm sure this could break in unexpected
> ways.
>
> Finally, the content-dispositon thing doesn't really matter -- it does
> give you a nice filename when you choose "save as", but it didn't
> affect whether or not IE would display the pdf right.  So sorry to put
> you through all that other stuff ;)
>
> Hopefully some of that made sense, let me know if you get this working.
>
> -Colin
>
>
> On 10/16/06, Jim Steil <jim at qlf.com> wrote:
> >
> >
> >
> >
> > Here is the latest:  But, same result on IE 7 and IE 6.
> >
> >
> >
> >             -Jim
> >
> >
> >
> > HTTP/1.1 200 OK
> >
> > Date: Mon, 16 Oct 2006 21:49:27 GMT
> >
> > Server: Apache/2.0.55 (Win32) mod_python/3.2.2b Python/2.4.3 PHP/5.1.6
> >
> > Cache-Control: no-cache="set-cookie"
> >
> > Set-Cookie: pysid=37d5aa6545f4c7595fcdd2c315b4a70f; path=/
> >
> > Set-Cookie: pysid=00ce18b00a3f3ea621ed5ac955c7aed7; path=/
> >
> > Content-length: 81355
> >
> > Content-Disposition: inline;filename="optimizer.pdf"
> >
> > Connection: close
> >
> > Content-Type: application/pdf
> >
> >
> >
> >
> > Jim Steil
> >  IT Manager
> >  Quality Liquid Feeds
> >  (608) 935-2345
> >
> > (608) 341-9896 cell
> >
> >  ________________________________
> >
> >
> > From: Colin Bean [mailto:ccbean at gmail.com]
> >  Sent: Monday, October 16, 2006 4:47 PM
> >  To: Jim Steil
> >  Cc: mod_python at modpython.org
> >  Subject: Re: [mod_python] ReportLab integration
> >
> >
> >
> >
> > Also, try putting the file name in quotes.  I think this is needed per the
> > RFC.
> >  I just checked an example where the Content-Disposition header was set
> to:
> >  attachment; filename="foo.dwf"
> >  which worked.  That wasn't done in mod_python, however; I'm still looking
> > at a mod_python example.
> >
> >  -Colin
> >
> >
>
>
>


More information about the Mod_python mailing list