WordPress.org

Make WordPress Core

Opened 3 years ago

Closed 3 years ago

Last modified 3 years ago

#16950 closed enhancement (duplicate)

Provide a redirected-to URI

Reported by: cogmios Owned by:
Milestone: Priority: normal
Severity: normal Version: 3.1
Component: HTTP API Keywords: 2nd-opinion needs-patch
Focuses: Cc:

Description

This discussion started (For me) here: http://wordpress.stackexchange.com/questions/11951/wp-remote-get-with-manual-redirect/11964#11964 (my name is edward de leau)

I then had contact with Scott Kingsley Clark who opened that thread and did not have time to work on it yet. I have the same problem:

I need to know where a url redirects to, to detect its base url (to extract favicons from).

So I made a redirect=0 and did manual processing: http://plugins.trac.wordpress.org/browser/wp-favicons/trunk/includes/class-http.php but discovered that from my testset of 1500 found favicons 500 were supplied by google because of the line 'Too many redirections'.

This was because the parameter FOLLOWLOCATION could not be set. See ticket : https://core.trac.wordpress.org/ticket/16855#comment:29
and my question: http://wordpress.stackexchange.com/questions/11951/wp-remote-get-with-manual-redirect/11964#11964 where Hakre supplied a fix to set FOLLOWLOCATION which works but the ticket is still under discussion.

So I had another approach: maybe just supply the URI that was redirected to. For CURL this can be done easily by adding a one-liner "do_action( 'http_api_curl_info', $handle);" directly after the exec call. For the other I have not researched this.

Would this be an option? (this IS the reason Curl supplies this information array with the forwarded URI). (then catchable via $info = curl_getinfo($handle);)

Attachments (1)

16950.patch (1.2 KB) - added by hakre 3 years ago.
Example Filter on curl_exec in transport

Download all attachments as: .zip

Change History (6)

comment:1 follow-up: cogmios3 years ago

do_action( 'http_api_curl_info', $handle) is not correct it should be do_action'http_api_curl_info', $location) where $location is the new URL if supplied (since I see now that on non-empty-basepath systems the URL in curl_info does not contain the proposed new location.

comment:2 dd323 years ago

  • Milestone Awaiting Review deleted
  • Resolution set to duplicate
  • Status changed from new to closed

closing as duplicate of #16855

comment:4 in reply to: ↑ 1 hakre3 years ago

Replying to cogmios:

do_action( 'http_api_curl_info', $handle) is not correct it should be do_action('http_api_curl_info', $location) where $location is the new URL if supplied (since I see now that on non-empty-basepath systems the URL in curl_info does not contain the proposed new location.

Probably you should provide a patch so it's more clear what this is about.

Keep in mind that for hooks, a general use should be supported, e.g. why not passing more than one variable to it? So the $handle, $location, $args.

I'll write a short patch.


Replying to dd32:

closing as duplicate of #16855

I think the creator of the ticket asks to introduce a new HOOK after curl_exec() has been run on a $handle.

comment:5 dd323 years ago

think the creator of the ticket asks to introduce a new HOOK

The original problem/causation is in the other ticket, and now changed, rendering this other approach moot.

Such a hook cannot be added reliably to the other transports, and adding a per-transport filter/action is asking for trouble.

hakre3 years ago

Example Filter on curl_exec in transport

Note: See TracTickets for help on using tickets.