You are viewing a plain text version of this content. The canonical link for it is here.
Posted to modperl@perl.apache.org by Dermot Paikkos <de...@sciencephoto.com> on 2005/09/01 15:49:49 UTC

Re: Suggestions for creating an archive

On 31 Aug 2005 at 13:48, Michael Peters wrote:

> > There is a way to do it, defined as part of HTTP or MIME -- I can't
> > quite remember.  If you do an external redirect you won't have to bother
> > figuring it out.
> 
> If you are generating your own content headers you use the
> Content-Disposition header.
> 
> Something like:
>     $r->header_out(
>         'Content-Disposition' => 'inline; filename=my_cool_stuff.zip'
>     );


I really hoped that this would have nailed it but alas, no. I am getting 
a download dialogue prompt but I'm not able to configure a filename 
for the download.

I tried a few variations with header_out. Specifying a location rather 
than a internal_redirect to see if that would ensure I was setting the 
headers. 

I tried to end the handler with a REDIRECT rather than an OK 
status, thinking that this was a really a redirect. I also tried to pass 
the handler to another but that didn't work either. I also had a look at 
RFC 2183 which refers mostly to MTUs but seems to suggest thst 
content-disposition is the correct header.

Content does appear to be set, the value of $content below is 
content = inline;filename=Myzip.zip. I have tried attachment as well 
out of sheer desperation.

...
print STDERR "redirecting, length=$length, ";
$r->header_out(
        'Content-Disposition' => 'inline;filename=Myzip.zip',
        'Location' => 'http://austin/Myzip.zip'
        );
my $content = $r->header_out('Content-Disposition');
print STDERR "content = $content\n";

# $r->internal_redirect("http://austin/Myzip.zip");

return REDIRECT;
}
1;

If anyone has any pointers, I'd be grateful.
Thanx.
Dp.



Re: Suggestions for creating an archive

Posted by Dermot Paikkos <de...@sciencephoto.com>.
On 2 Sep 2005 at 10:20, Perrin Harkins wrote:

> On Fri, 2005-09-02 at 11:34 +0100, Dermot Paikkos wrote:

> I don't really understand why you have two scripts.  You should just let
> apache handle serving the zip as a static file.  It's much better at
> that than any script you write will be, since it handles If-Modified-
> Since, range requests, and all the other HTTP goodies.

Another good point because I did notice during testing that I had to 
completely shut the browser (FF and IE) to see get the browser 
make the request again. I would make a little change to the handler, 
restart apache but the messages I printed to STDERR weren't going 
to the log. 

I suspected that as the uri /file_export wasn't changed the browser 
just tried to download the static page/file again. I might need to read 
the doc on the issuing correct headers.

> Anyway, glad to hear you persevered and got it working.  Congrats!

I have to fight other fires now but I will look at what you've sent when 
I return to that part of the project again. I have a lot of tiding up to do 
to it and I will see if I can use one handler instead of 2.

Thanx again.
Dp.


> 
> - Perrin
> 
> 


~~
Dermot Paikkos * dermot@sciencephoto.com
Network Administrator @ Science Photo Library
Phone: 0207 432 1100 * Fax: 0207 286 8668


Re: Suggestions for creating an archive

Posted by Perrin Harkins <pe...@elem.com>.
On Fri, 2005-09-02 at 11:34 +0100, Dermot Paikkos wrote:
> I did get carried away abit with the redirection, I was thrahing around 
> by that time. Interestingly you haven't use content-dispostion either.

It has no effect on a redirect.

> In the end I created 2 scripts, one to archive and dump the file 
> somewhere there server could see it before handing it to another to 
> redirect. The redirect I practically lift out of Chp 4 of the Eagle book. 
> 
> The first script ends with a return REDIRECT; and the second ends 
> with an return OK; I have a sneaky feeling that I may be doing that 
> wrong and should return OK with both and set the status as you 
> have done.

Your suspicion is right -- that return code is for internal apache
purposes, and is not sent to the client.  Return OK.

I don't really understand why you have two scripts.  You should just let
apache handle serving the zip as a static file.  It's much better at
that than any script you write will be, since it handles If-Modified-
Since, range requests, and all the other HTTP goodies.

Anyway, glad to hear you persevered and got it working.  Congrats!

- Perrin


Re: Suggestions for creating an archive

Posted by Dermot Paikkos <de...@sciencephoto.com>.
On 1 Sep 2005 at 12:40, Perrin Harkins wrote:
> 
> The Location header is for redirects, not for internal redirects.
> You're doing too many things at once here.  Just drop all of this and do
> a normal redirect to the file.  You can use CGI.pm's redirect()
> function, or do something like this (mod_perl 1.x code):
> 
>   use Apache::Constants qw(REDIRECT OK);
>   my $r = shift;
>   my $location = 'http://example.com/Myzip.zip';
>   $r->headers_out->set(Location => $location);
>   $r->status(REDIRECT);
>   $r->send_http_header;
>   return OK;
> 
> - Perrin

I did get carried away abit with the redirection, I was thrahing around 
by that time. Interestingly you haven't use content-dispostion either.

In the end I created 2 scripts, one to archive and dump the file 
somewhere there server could see it before handing it to another to 
redirect. The redirect I practically lift out of Chp 4 of the Eagle book. 

The first script ends with a return REDIRECT; and the second ends 
with an return OK; I have a sneaky feeling that I may be doing that 
wrong and should return OK with both and set the status as you 
have done.

I too read soemwhere that the content-dispostion wasn't always 
correctly implemented. MS do have a doc on their knowledge base 
(q260519) about content-dispostion so they seem to think they 
implement it correctly.

Thanx Perrin. You have been v. patient.
Dp.







~~
Dermot Paikkos * dermot@sciencephoto.com
Network Administrator @ Science Photo Library
Phone: 0207 432 1100 * Fax: 0207 286 8668


Re: Suggestions for creating an archive

Posted by colin_e <co...@bigfoot.com>.
I've read in at least one place (a PHP book I think) that browsers are 
very inconsistent in their
handling of  the content-disposition header. Some will "believe" the 
suggested filename, but
ignore the extension, and implied file type.

Have you considered looping back to your own script with a redirect, 
something like-

a) User invokes script as "script.pl"

b) Script redirects to "script_downloader.zip"
   (But configure Apache to pass this back to the original script).

c) Script picks up the original session state and emits the zip 
filestream to the browser,
   which is now expecting a downloadable file type.

May be worth a try.

Regards: Colin

Dermot Paikkos wrote:

>On 31 Aug 2005 at 13:48, Michael Peters wrote:
>
>  
>
>>>There is a way to do it, defined as part of HTTP or MIME -- I can't
>>>quite remember.  If you do an external redirect you won't have to bother
>>>figuring it out.
>>>      
>>>
>>If you are generating your own content headers you use the
>>Content-Disposition header.
>>
>>Something like:
>>    $r->header_out(
>>        'Content-Disposition' => 'inline; filename=my_cool_stuff.zip'
>>    );
>>    
>>
>
>
>I really hoped that this would have nailed it but alas, no. I am getting 
>a download dialogue prompt but I'm not able to configure a filename 
>for the download.
>
>I tried a few variations with header_out. Specifying a location rather 
>than a internal_redirect to see if that would ensure I was setting the 
>headers. 
>
>I tried to end the handler with a REDIRECT rather than an OK 
>status, thinking that this was a really a redirect. I also tried to pass 
>the handler to another but that didn't work either. I also had a look at 
>RFC 2183 which refers mostly to MTUs but seems to suggest thst 
>content-disposition is the correct header.
>
>Content does appear to be set, the value of $content below is 
>content = inline;filename=Myzip.zip. I have tried attachment as well 
>out of sheer desperation.
>
>...
>print STDERR "redirecting, length=$length, ";
>$r->header_out(
>        'Content-Disposition' => 'inline;filename=Myzip.zip',
>        'Location' => 'http://austin/Myzip.zip'
>        );
>my $content = $r->header_out('Content-Disposition');
>print STDERR "content = $content\n";
>
># $r->internal_redirect("http://austin/Myzip.zip");
>
>return REDIRECT;
>}
>1;
>
>If anyone has any pointers, I'd be grateful.
>Thanx.
>Dp.
>
>
>
>  
>


Re: Suggestions for creating an archive

Posted by Perrin Harkins <pe...@elem.com>.
On Thu, 2005-09-01 at 14:49 +0100, Dermot Paikkos wrote:
> I tried to end the handler with a REDIRECT rather than an OK 
> status, thinking that this was a really a redirect.

Nope, that's for internal redirects.

> print STDERR "redirecting, length=$length, ";
> $r->header_out(
>         'Content-Disposition' => 'inline;filename=Myzip.zip',
>         'Location' => 'http://austin/Myzip.zip'
>         );
> my $content = $r->header_out('Content-Disposition');
> print STDERR "content = $content\n";
> 
> # $r->internal_redirect("http://austin/Myzip.zip");
> 
> return REDIRECT;
> }
> 1;

The Location header is for redirects, not for internal redirects.
You're doing too many things at once here.  Just drop all of this and do
a normal redirect to the file.  You can use CGI.pm's redirect()
function, or do something like this (mod_perl 1.x code):

  use Apache::Constants qw(REDIRECT OK);
  my $r = shift;
  my $location = 'http://example.com/Myzip.zip';
  $r->headers_out->set(Location => $location);
  $r->status(REDIRECT);
  $r->send_http_header;
  return OK;

- Perrin