Hi,
been trying to create Route that downloads a file. here is the class:
public class MyRoute
implements Route
{
@Override
public Object handle(Request request, Response response) throws Exception {
HttpServletResponse httpResponse = response.raw();
httpResponse.addHeader("Cache-Control", "no-cache");
httpResponse.setContentType("text/plain");
httpResponse.addHeader("Content-Disposition", "attachment; filename=\"abc.txt\"");
ServletOutputStream outputStream = httpResponse.getOutputStream();
outputStream.write("hello\n".getBytes());
return httpResponse;
}
}
when I requested for the URL it downloaded a file named abc.txt (as expected) but the look at the content:
hello
HTTP/1.1 200
Date: Mon, 30 Jan 2017 12:04:17 GMT
Cache-Control: no-cache
Content-Type: text/plain
Content-Disposition: attachment; filename="abc.txt"
it contains the printed hello, but has trailing (http header???) info.
looks like a bug?
or Am I doing something wrong?
I use version 2.5.4 via maven:
<dependency>
<groupId>com.sparkjava</groupId>
<artifactId>spark-core</artifactId>
<version>2.5.4</version>
</dependency>
please help.
Thanks,
Arik