Elasticpress: Output custom X- HTTP headers from ElasticSearch servers

Created on 21 Oct 2017  路  2Comments  路  Source: 10up/ElasticPress

Have you searched for similar issues before submitting this one? Yes.

Is this a bug, question or feature request? Feature request.

Describe the issue you encountered:

Our ElasticSearch servers are configured to provide an "X-ElasticSearch-Server: $hostname" header with all HTTP responses. This helps us identify which server responded and debug when needed. It would be useful if we could define these custom headers in wp-config.php and have ElasticPress include them with the standard X-ElasticPress-Search header.

Current WordPress version: 4.8.2

Current ElasticPress version: 2.3.2

Current Elasticsearch version: 5.6.1

Where do you host your Elasticsearch server: Self-hosted.

Other plugins installed (WooCommerce, Simple Redirect Manager, etc..): WooCommerce

question

Most helpful comment

Hi @ahmed-sigmalux!

what you need is an ad-hoc solution and we are likely not going to implement it as of now because the majority of users won't need it. I would like to suggest you add a hook for ep_remote_request action and send that header manually. It can be something like this:

function send_ep_server_header( $query ) {
    if ( ! headers_sent() ) {
        $server = wp_remote_retrieve_header( $query['request'], 'X-ElasticSearch-Server' );
        if ( ! empty( $server ) ) {
            header( "X-ElasticSearch-Server: {$server}" );
        }
    }
}

add_action( 'ep_remote_request', 'send_ep_server_header' );

I am going to close this ticket for now, but if you still have questions, feel free to re-open it.

All 2 comments

@tlovett1 I'm assigning this one to you to decide what to do with this.

Hi @ahmed-sigmalux!

what you need is an ad-hoc solution and we are likely not going to implement it as of now because the majority of users won't need it. I would like to suggest you add a hook for ep_remote_request action and send that header manually. It can be something like this:

function send_ep_server_header( $query ) {
    if ( ! headers_sent() ) {
        $server = wp_remote_retrieve_header( $query['request'], 'X-ElasticSearch-Server' );
        if ( ! empty( $server ) ) {
            header( "X-ElasticSearch-Server: {$server}" );
        }
    }
}

add_action( 'ep_remote_request', 'send_ep_server_header' );

I am going to close this ticket for now, but if you still have questions, feel free to re-open it.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

keg picture keg  路  4Comments

blindpet picture blindpet  路  7Comments

brunocrosier picture brunocrosier  路  3Comments

MediaMaquina picture MediaMaquina  路  3Comments

emmerich picture emmerich  路  8Comments