Skip to main content
Deno 2 is finally here 🎉️
Learn more
Module

x/ayonli_jsext/esm/workerd/http.js>setFilename

A JavaScript extension package for building strong and modern applications.
Latest
function setFilename
import { setFilename } from "https://deno.land/x/ayonli_jsext@v0.9.72/esm/workerd/http.js";

Sets the Content-Disposition header with the given filename when the response is intended to be downloaded.

This function encodes the filename with encodeURIComponent and sets both the filename and the filename* parameters in the header for maximum compatibility.

NOTE: This function can be used with both Response and Headers objects. However, when using with a Headers instance, make sure to set the filename before the headers instance is used by the response object.

Examples

Example 1

import { setFilename } from "@ayonli/jsext/http";

export default {
    fetch(req: Request) {
        const res = new Response("Hello, World!");
        setFilename(res, "hello.txt");

       return res;
    }
}

Parameters

res
filename