On Wed, 11 May 2016 06:30:16 GMT, mauricio wrote:
Good morning, i need some help, i�m noob for vibe.d. My problem is in download csv file, set headers Content-Type and Content-Disposition, also writing in the body text I needed, but at the time of the post, not download any files. Deputy code:
void postdownload(scope HTTPServerRequest req, scope HTTPServerResponse res)
{Json j = ...; auto response = serialize!JsonSerializer(this.makeRequest(anythingUrl, "POST", serialize!JsonSerializer(j))); res.headers["Content-Disposition"] = "attachment; filename=Reporte.txt"; res.headers["Cache-Control"] = "no-cache"; //res.headers["Expires"] = "-1"; res.headers["Content-Description"] = "File Transfer"; //res.headers["Content-Encoding"] = "UTF-8"; //res.headers["Pragma"] = "no-cache"; string csvFile = response.rbody.toString(); res.writeBody(csvFile,"text/csv");
}
This generally looks right. As a side note, I'd just recommend to serialize to a JSON string directly for efficiency reasons:
auto response = this.makeRequest(anythingUrl, "POST", serializeToJson(j));
...
res.writeBody(serializeToJsonString(response.rbody), "text/csv");
// or, using chunked transfer, but avoiding the dynamic memory allocation:
// auto dst = StreamOutputRange(res.bodyWriter);
// dst.serializeToJson(response.rbody);
But regarding the actual problem, which client do you use for downloading? What are the exact symptoms? Does the request stall, or does it download an empty file?