Opened 8 years ago
Last modified 4 months ago
#40153 new enhancement
Filter for wp_safe_remote_get in download_url
Reported by: |
|
Owned by: | |
---|---|---|---|
Milestone: | Awaiting Review | Priority: | normal |
Severity: | normal | Version: | 4.8 |
Component: | General | Keywords: | has-patch |
Focuses: | Cc: |
Description
I had to deal with images on a server that has basic authentication active. There is no filter in download_url that would give me the chance to add the header authentication that I needed in this case.
Attachments (2)
Change History (4)
#2
@
4 months ago
I also stumbled across this today because I want to access an Auth Basic protected URL. My solution:
add_filter( 'http_request_args', array( $this, 'set_download_url_header' ) ); $file = download_url( $this->get_url() ); remove_filter( 'http_request_args', array( $this, 'set_download_url_header' ) );
In set_download_url_header()
I add the Auth Basic header, which then works without any problems:
public function set_download_url_header( array $parsed_args ): array { return array_merge( $parsed_args, array( 'header' => array( 'Authorization' => 'Basic ...' ) ) ); }
Note: See
TracTickets for help on using
tickets.
I added a new patch for this issue.
Here are some key points about the new patch I attached 40153.2.diff.
download_url_remote_get_args
which was introduced.$args['timeout']
,$args['stream']
, and$args['filename']
.$args['timeout']
can be debatable. But I think it's enough thatdownload_url()
itself accepts the$timeout
params.$args['filename']
and$args['stream']
unless there's a good reason, these 2 should also be left untouched IMHO to prevent any unexpected issues to arise with howdownload_url()
currently works.