NanoHttpd / nanohttpd

Tiny, easily embeddable HTTP server in Java.
http://nanohttpd.org
BSD 3-Clause "New" or "Revised" License
6.92k stars 1.69k forks source link

Content-Disposition: attachment not work for txt file in Kindle #526

Closed ChenZhongPu closed 5 years ago

ChenZhongPu commented 5 years ago

I am using nanohttpd in Android as a http server.

     Response response = NanoHTTPD.newChunkedResponse(Response.Status.OK, mime, fis);
     response.addHeader("Content-Disposition", "attachment; filename=\"" + WebUtil.localFileName +"\"");
     return response;

When the file mime is application/x-mobipocket-ebook (I have updated the mimetypes file), it can download directly in Kindle. But when it is plain/txt, it will display it inline.

ChenZhongPu commented 5 years ago

I would like to force it to download instead of displaying.

LordFokas commented 5 years ago

The mime is the Content-Type response header. That should be enough to force a download, since it's a mime browsers don't typically know how to display.