Vibe-D File Question

Daniel Kozak kozzi11 at gmail.com
Fri Sep 11 11:28:45 UTC 2020


On Fri, Sep 11, 2020 at 1:15 PM Daniel Kozak <kozzi11 at gmail.com> wrote:

> On Fri, Sep 11, 2020 at 1:10 PM Selim Ozel via Digitalmars-d-learn <
> digitalmars-d-learn at puremagic.com> wrote:
>
>> It seems like rejected-software forum is flooded with spam, so I
>> decided to ask it here. Is there a way to generate a file -csv
>> for example- on the back-end and serve it to the front-end as a
>> file.
>>
>> Serve static file [1] function does this for files saved on the
>> disk. I want to be able to generate a file during runtime and
>> serve it to the client. Is this possible?
>>
>> Thanks,
>> S
>>
>>
>> [1] https://vibed.org/api/vibe.http.fileserver/serveStaticFile
>>
>>
>>
> https://vibed.org/api/vibe.http.server/HTTPServerResponse.writeBody
>

import vibe.core.core;
import vibe.http.server;


void main()
{
runWorkerTaskDist(&wrap);
    runApplication();
}

void wrap()
{
auto settings = new HTTPServerSettings(":8080");
settings.options |= HTTPServerOption.reusePort;
listenHTTP(settings, &fun);
}

void fun(HTTPServerRequest req, HTTPServerResponse res) nothrow
{
try
{
res.headers["Content-Disposition"] = "filename=\"muj.csv\"";
res.writeBody("some;csv;data", "text/csv");
}
catch (Exception e)
{}
}
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.puremagic.com/pipermail/digitalmars-d-learn/attachments/20200911/18b66abe/attachment.htm>


More information about the Digitalmars-d-learn mailing list