get_url (and maybe later uri): honor content-disposition

Hi,

oh cool, a new list.

The get_url and uri modules don’t respect file names from content disposition headers. While creating a playbook for deploying Maven artifacts from our Nexus instance today I wished they did. :slight_smile:

Both modules clearly state:

If I(dest) is a directory, the basename of the file on the remote server will be used.

I’m willing to put in some effort to make get_url (and later maybe uri) respect the content disposition header for determining the resulting filename.

What I’m proposing is:

  • If you specify a filename for the destination, the file goes to that file name, no questions asked (just like now)
  • If you specify a directory, and the response contains a content disposition header of the form ‘Content-Disposition: attachment; filename=“fname.ext”’, a file named ‘fname.ext’ is created in the directory you specified, with the content from the URL
  • If you specify a directory and there is no content disposition header with the given format in the response, we fall back to the current behavior

If I wrote this, could I get it merged?

Cheers

If I wrote this, could I get it merged?

Sounds good to me.

        -JP

Yes, this seems totally reasonable. Look forward to your pull request :slight_smile:

The get_url and uri modules don't respect file names from content
disposition headers. While creating a playbook for deploying Maven
artifacts from our Nexus instance today I wished they did. :slight_smile:

The uri module will check for redirects and look at the Location Header
though​​, and download from that if follow_redirects = True, or you can
register the redirected url from there and download it with get_url (if the
artifact is too big memory-wise for uri)

I actually wrote that feature especially for using with Nexus, which yields
a 302 when downloading through the rest interface.

Serge

Here we go: https://github.com/ansible/ansible/pull/4785.

If I can get this merged, I’ll do the uri module next.

Cheers

Can someone take a look at this? I’ve included some test scenarios for verification in the comments.

you have a ticket filed, it’s in queue – no reason to email the entire list.

Support customers will of course get higher priority but we are attacking lots of different things for everyone.

All priority bugs were closed down to 0 last week and we are focusing on pull requests for a while.

– Michael