I think it would be very beneficial to support the option for POST requests and not just the use of 'get' via wget. Currently drupal has the function to handle http POST requests via drupal_http_request(). I think using this function or similar in drush make would allow for downloading libraries that may not necessarily be available via a direct url.

Example: shadowbox.js library is only available from http://www.shadowbox-js.com/download.html. That is a form that performs a POST to http://www.shadowbox-js.com/download. Now if I did the following from drupal I could download a fresh copy of that library, but with drush make there is no way to do this. Could drush make be altered to support something similar?

$data = 'format=tar&adapter=jquery&players[]=img&players[]=iframe&players[]=html&players[]=swf&players[]=flv&players[]=qt&players[]=wmp&language=en&css_support=on';

$sbfile = drupal_http_request('http://www.shadowbox-js.com/download', array(), 'POST', $data, 3);
if ($sbfile->code == 200) {
  $filepath = file_save_data($sbfile->data, file_directory_path() . '/sb.tar.gz', FILE_EXISTS_REPLACE);
}

Comments

nicholas.alipaz’s picture

StatusFileSize
new2.15 KB

Actually, after more investigation I determined we could just continue to use wget/curl for the post requests since they both support it. Attached is a patch and below is a make file to test it out.

The issues I found when using post-data was that the filename returned by the post will be whatever the name of the basename of the url is, so this causes issues if it is a directory or a php file even. That being said I added options for [filetype] and [postdata] to make files. This allows us to specify a file extension if we know the returned filename will not include it.

Here is an example make file that would download the shadowbox library from www.shadowbox-js.com

core = 6.x

libraries[shadowbox][download][type] = "get"
libraries[shadowbox][download][postdata] = "format=tar&adapter=jquery&players[]=img&players[]=iframe&players[]=html&players[]=swf&players[]=flv&players[]=qt&players[]=wmp&language=en&css_support=on"
libraries[shadowbox][download][filetype] = "tar.gz"
libraries[shadowbox][download][url] = "http://www.shadowbox-js.com/download"
libraries[shadowbox][directory_name] = "shadowbox"
libraries[shadowbox][destination] = "libraries"

This could however be expanded on by perhaps allowing specification of each of the querystring's parameters like so:

libraries[shadowbox][download][postdata][format] = "tar"
libraries[shadowbox][download][postdata][adapter] = "jquery"
...

But you might notice the dilemma in this example players[]=img&players[]=iframe, how to handle this sort of thing?

Lastly, it may be better to change the type to 'post' but I am not completely convinced. Can anyone give input on all this?

nicholas.alipaz’s picture

StatusFileSize
new2.15 KB

Here is an update of the patch. It changes a little bit. postdata becomes post_data and filetype becomes file_type. It also fixes curl which may not be working in the prior patch. Here is an updated make:

core = 6.x

libraries[shadowbox][download][type] = "get"
libraries[shadowbox][download][post_data] = "format=tar&adapter=jquery&players[]=img&players[]=iframe&players[]=html&players[]=swf&players[]=flv&players[]=qt&players[]=wmp&language=en&css_support=on"
libraries[shadowbox][download][file_type] = "tar.gz"
libraries[shadowbox][download][url] = "http://www.shadowbox-js.com/download"
libraries[shadowbox][directory_name] = "shadowbox"
libraries[shadowbox][destination] = "libraries"
nicholas.alipaz’s picture

Status: Active » Needs review
dmitrig01’s picture

Let's split this into another download method called POST.

nicholas.alipaz’s picture

StatusFileSize
new2.43 KB

perhaps something like this?

nicholas.alipaz’s picture

StatusFileSize
new2.43 KB

here is a fixed version of last patch, noticed a misdeclared variable or two.

nicholas.alipaz’s picture

StatusFileSize
new2.43 KB

gosh, one more. I don't have time to test now, but this should work in theory. Let me know if this is the direction the patch should go or how you would like to proceed.

dmitrig01’s picture

Sort of. This won't actually work because drush make looks for a class called DrushMakeDownload_{type}, so get won't trigger if you put post in - we need a new class. It could extend the get class if you wanted to go that route.

nicholas.alipaz’s picture

StatusFileSize
new1.67 KB

maybe more like this then...?

nicholas.alipaz’s picture

I will try to give this a test today to see if it is working or not.

nicholas.alipaz’s picture

StatusFileSize
new1.72 KB

OK, I did some pretty heavy testing on this. And it is working. This patch will allow make files to contain a new type called "post" like so:

core = 6.x

libraries[shadowbox][download][type] = "post"
libraries[shadowbox][download][post_data] = "format=tar&adapter=jquery&players[]=img&players[]=iframe&players[]=html&players[]=swf&players[]=flv&players[]=qt&players[]=wmp&language=en&css_support=on"
libraries[shadowbox][download][file_type] = "tar.gz"
libraries[shadowbox][download][url] = "http://www.shadowbox-js.com/download"
libraries[shadowbox][directory_name] = "shadowbox"
libraries[shadowbox][destination] = "libraries"

The above is a working make file for downloading the shadowbox library. This will be ported to shadowbox once the attached patch gets committed to drush_make.

Let me know if there is anything else I can do to aid in getting this added/completed.

pcambra’s picture

suscribe

dmitrig01’s picture

Status: Needs review » Reviewed & tested by the community
nicholas.alipaz’s picture

Glad to see some movement on this. ;)

yhahn’s picture

Status: Reviewed & tested by the community » Fixed

Committed: http://drupal.org/cvs?commit=379332

I've added a basic GET/POST test and docs for the post request method in README.txt.

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for 2 weeks with no activity.