Possibility to filter Content-Type (and other headers) #61

alisspers opened this Issue Dec 20, 2013 · 1 comment


None yet
2 participants

alisspers commented Dec 20, 2013

We're using jQuery File Upload with iframe-transport to upload files to a custom API endpoint.

Due to IE:s lack of support for application/json responses to an <iframe>, we need this endpoint to return Content-Type: text/plain whenever application/json isn't accepted.

Would it be possible to add a filter to WP_JSON_Server::serve_request() (or wherever you se fit) so plugins can modify the response headers?

As a workaround, we've added this code at the top of serve_request():

header( 'Vary: Accept' );
if ( isset( $_SERVER['HTTP_ACCEPT'] ) && ( strpos( $_SERVER['HTTP_ACCEPT'], 'application/json' ) !== false ) ) {
    $this->header( 'Content-Type', 'application/json; charset=' . get_option( 'blog_charset' ), true );
} else {
    $this->header( 'Content-Type', 'text/plain; charset=' . get_option( 'blog_charset' ), true );

@rmccue rmccue added this to the 1.0 milestone Mar 4, 2014


rmccue commented Mar 4, 2014

Sorry about this, and thanks for the report!

You should be able to use the json_serve_request filter here to send extra headers as needed, but we don't currently pass the server itself into that. We should fix that. :)

kellbot pushed a commit to kellbot/WP-API that referenced this issue Aug 1, 2014

Merge pull request #139 from WP-API/add-serve-request-arg
Pass WP_JSON_Server instance to json_serve_request.  Fixes #61.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment