apache – How to make sure that a CGI script changes the name of the file that it returns

I have some scripts in / cgi-bin that filter various types of data from documents and return CSV. The scripts themselves (the actual executable files in / cgi-bin) have names ending in .csv. Thus, when called from a page, the returned data is viewed by the user's browser as a CSV file.

This was not a problem when each document class had only one location where this facility was linked. Now I have documents with a lot of these points, which means that everyone will download a .csv file of the same name each time.

How can I get (? Apache) to change the file name that the browser sees? I can pass the desired name as a parameter in the call, but I do not see a simple way to do (for example) /cgi-bin/script1.csv?name=foobar change its own name to foobar. csv the one opportunity and something-else.csv on another (the possible names are arbitrary).

Could it be done in a RewriteRule? By hanging the name parameter and aliasing the call? I do not know enough Rewrite to judge.