Make WordPress Core

Opened 10 years ago

Closed 10 years ago

#27021 closed enhancement (fixed)

Add more context to the http_api_curl action

Reported by: kovshenin's profile kovshenin Owned by: nacin's profile nacin
Milestone: 3.9 Priority: normal
Severity: normal Version:
Component: HTTP API Keywords: has-patch
Focuses: Cc:

Description

Currently the http_api_curl action just passes the cURL handle, which is not very useful without more context, like what URL was requested and what the arguments were.

A simple use case is CURLOPT_TIMEOUT_MS which was removed in r12472 due to bugginess with some versions of PHP and cURL, but which works pretty well on newer versions, so with a more useful action, it could easily be implemented in a plugin:

function better_curl_timeout( $handle, $r ) {
	if ( defined( 'CURLOPT_CONNECTTIMEOUT_MS' ) && defined( 'CURLOPT_TIMEOUT_MS' ) ) {
		$timeout_ms = (int) ceil( 1000 * $r['timeout'] );
		curl_setopt( $handle, CURLOPT_CONNECTTIMEOUT_MS, $timeout_ms );
		curl_setopt( $handle, CURLOPT_TIMEOUT_MS, $timeout_ms );
	}
}
add_action( 'http_api_curl', 'better_curl_timeout', 10, 2 );

Attachments (2)

27021.diff (522 bytes) - added by kovshenin 10 years ago.
27021.2.diff (763 bytes) - added by kovshenin 10 years ago.

Download all attachments as: .zip

Change History (9)

@kovshenin
10 years ago

#1 @kovshenin
10 years ago

  • Keywords has-patch added

Patch in 27021.diff

#2 @dd32
10 years ago

  • Milestone changed from Awaiting Review to 3.9

As much as we shouldn't be encouraging people to use transport-specific hooks such as this, if we're going to have the hook in there, we might as well make it pass context.. so seems like a decent suggestion to me.

#3 follow-ups: @nacin
10 years ago

Doesn't moving from do_action_ref_array() to do_action() cause issues with functions anticipating the by-reference variable?

#4 in reply to: ↑ 3 @kovshenin
10 years ago

Replying to nacin: You're right, though $handle is just a resource so not sure there's a point to pass it by reference. Unless the hooked action to replaces the resource with a brand new one using curl_init(), so yeah maybe do &$handle instead.

#5 in reply to: ↑ 3 @nacin
10 years ago

Replying to nacin:

Doesn't moving from do_action_ref_array() to do_action() cause issues with functions anticipating the by-reference variable?

See #16661 for the history.

@kovshenin
10 years ago

#6 @kovshenin
10 years ago

Yes, makes sense. Refreshed in 27021.2.diff, back to _ref_array() + added some docs.

#7 @nacin
10 years ago

  • Owner set to nacin
  • Resolution set to fixed
  • Status changed from new to closed

In 27475:

Add context to an internal HTTP API hook.

props kovshenin.
fixes #27021.

Note: See TracTickets for help on using tickets.