WordPress.org

Make WordPress Core

Opened 5 years ago

Closed 3 years ago

#24598 closed enhancement (fixed)

Allow custom headers in XML-RPC request

Reported by: ericmann Owned by: chriscct7
Milestone: 4.4 Priority: normal
Severity: normal Version: 3.5
Component: XML-RPC Keywords: has-patch
Focuses: Cc:

Description

WordPress avails an override to the default IXR_Client object that uses its own WP_Http wrapper for making the request. The wrapper itself is pluggable, but there are no filters before the call to wp_remote_post that allow developers to intercept and modify the request.

As a result, sending custom headers with the request (like cookies) requires developers in turn override IXR_Client with their own implementation in order to add the custom data. One example, which specifically addresses sending cookies with the request, is https://gist.github.com/ericmann/5808805.

Instead, the built-in WP_HTTP_IXR_Client object should pass its header array through a WordPress filter before building the remote request. Developers can hook in to this filter to add their own custom headers - be they cookies, authentication, language, or whatever.

Attachments (3)

ixr_client_filter.diff (1.5 KB) - added by ericmann 5 years ago.
Patch adding a filter to request headers.
24598.2.diff (1.2 KB) - added by ericmann 3 years ago.
Updated patch file.
24598.3.diff (1.3 KB) - added by ericmann 3 years ago.
Filter docs

Download all attachments as: .zip

Change History (13)

@ericmann
5 years ago

Patch adding a filter to request headers.

#1 @ericmann
5 years ago

The patch adds brackets to the existing single-line conditional statements in the file as the indentation can be tricky to follow and what the code is doing here should be absolutely clear.

#2 @danhgilmore
5 years ago

I had this requirement (to send cookies in my request) and Eric offered to help. This was a simple and quick fix, and exactly what I needed. I've already got it working on one installation and I'll have it on my other two installations by COB.

#3 @chriscct7
3 years ago

  • Keywords needs-refresh added
  • Milestone changed from Awaiting Review to 4.4
  • Owner set to chriscct7
  • Status changed from new to assigned
  • Version changed from 3.5.1 to 3.5

@ericmann
3 years ago

Updated patch file.

#4 @ericmann
3 years ago

  • Keywords needs-refresh removed

Updated patch file against the new development repository :-)

#5 @chriscct7
3 years ago

  • Keywords commit added
  • Status changed from assigned to accepted

Looks good

#6 @wonderboymusic
3 years ago

  • Keywords needs-docs added; commit removed

Filter docs

@ericmann
3 years ago

Filter docs

#7 @ericmann
3 years ago

  • Keywords needs-docs removed

Added a docblock for the filter.

#8 @wonderboymusic
3 years ago

  • Resolution set to fixed
  • Status changed from accepted to closed

In 34164:

Add a filter to allow custom headers to be sent via the WP HTTP IXR client: 'wp_http_ixr_client_headers'.

Props ericmann.
Fixes #24598.

#9 @DrewAPicture
3 years ago

  • Resolution fixed deleted
  • Status changed from closed to reopened

Instead of describing what the filter allows, let's describe what's filterable.

#10 @DrewAPicture
3 years ago

  • Resolution set to fixed
  • Status changed from reopened to closed

In 34203:

Docs: Update the hook doc summary for the wp_http_ixr_client_headers filter, introduced in [34164].

The idea is to try to reflect what the filterable value is rather than why it's filterable.

Fixes #24598.

Note: See TracTickets for help on using tickets.