question on downloading CGI - modperl

This is a discussion on question on downloading CGI - modperl ; Hello, I want to generate a data file which should be downloaded by clients. Rather than generate this file and put it in a web dir and tell clients to download it, is there any way to generate the content ...

+ Reply to Thread
Results 1 to 5 of 5

Thread: question on downloading CGI

  1. question on downloading CGI

    Hello,

    I want to generate a data file which should be downloaded by clients.
    Rather than generate this file and put it in a web dir and tell
    clients to download it, is there any way to generate the content
    dynamicly and put it to cients? I mean I don't want to generate the
    temporary file. Thanks.


    Jen.


  2. Re: question on downloading CGI

    On Fri, Sep 5, 2008 at 12:09 PM, wrote:
    > Hello,
    >
    > I want to generate a data file which should be downloaded by clients.
    > Rather than generate this file and put it in a web dir and tell
    > clients to download it, is there any way to generate the content
    > dynamicly and put it to cients? I mean I don't want to generate the
    > temporary file. Thanks.


    Hi, Jen. This list is for mod_perl users. It sounds like you are new
    to web programming, but I could be wrong. I would suggest with a
    google search for "perl cgi tutorial" and go from there. There is
    also a beginners-cgi mailing list (not this) and perlmonks.org is a
    great site for general perl knowledge.

    Sean


  3. Re: question on downloading CGI

    On Fri 05 Sep 2008, practicalperl@gmail.com wrote:
    > I want to generate a data file which should be downloaded by clients.
    > Rather than generate this file and put it in a web dir and tell
    > clients to download it, is there any way to generate the content
    > dynamicly and put it to cients? I mean I don't want to generate the
    > temporary file.


    Plenty.

    For example in your httpd.conf


    SetHandler modperl
    PerlResponseHandler "sub { \
    use Apache2::RequestRec (); \
    use Apache2::RequestIO (); \
    use Apache2::Connection (); \
    $_[0]->content_type('application/octet-stream'); \
    until($_[0]->connection->aborted) { \
    $_[0]->print(rand); \
    } \
    return 0; \
    }"


    Now restart your server and then

    curl -v http://server/download

    And you'll get never ending randomness.

    You can also write a little shell script and use it via mod_cgi:

    >>>>>>>>>>>>>>>>>> the shell script

    #!/bin/bash
    echo Content-Type: application/octet-stream
    echo
    cat /dev/urandom
    <<<<<<<<<<<<<<<<<< end of shell script

    Now fetch the Apache docs and configure your server to execute the
    script as CGI program.

    Remember it is not necessarily faster to send dynamic content this way.
    Sometimes it is faster to write a temporary file sometime before the
    response phase and let the default handler send it. If you decide to
    send the content on the fly try to figure out the content length and
    set the Content-Length header. This can also improve your performance.

    Torsten

    --
    Need professional mod_perl support?
    Just hire me: torsten.foertsch@gmx.net


  4. Re: question on downloading CGI

    Quoting practicalperl@gmail.com:

    > Hello,
    >
    > I want to generate a data file which should be downloaded by clients.
    > Rather than generate this file and put it in a web dir and tell
    > clients to download it, is there any way to generate the content
    > dynamicly and put it to cients? I mean I don't want to generate the
    > temporary file. Thanks.


    This reads to me like you just want to cause the browser to prompt the
    user to save the file to disk instead of render the content you are
    generating in which case you should read about the Content-Disposition
    header:

    http://www.ietf.org/rfc/rfc1806.txt

    The quick summary of which is to add a header to your response that
    looks like this:

    Content-Disposition: attachment; filename=filename.extention

    Adam


  5. Re: question on downloading CGI

    Thank you all so much. I have resolved the problems.

    On Sat, Sep 6, 2008 at 3:51 AM, wrote:
    > Quoting practicalperl@gmail.com:
    >
    >> Hello,
    >>
    >> I want to generate a data file which should be downloaded by clients.
    >> Rather than generate this file and put it in a web dir and tell
    >> clients to download it, is there any way to generate the content
    >> dynamicly and put it to cients? I mean I don't want to generate the
    >> temporary file. Thanks.

    >
    > This reads to me like you just want to cause the browser to prompt the user
    > to save the file to disk instead of render the content you are generating in
    > which case you should read about the Content-Disposition header:
    >
    > http://www.ietf.org/rfc/rfc1806.txt
    >
    > The quick summary of which is to add a header to your response that looks
    > like this:
    >
    > Content-Disposition: attachment; filename=filename.extention
    >
    > Adam
    >
    >
    >
    >
    >
    >



+ Reply to Thread