Viewing 4 replies - 1 through 4 (of 4 total)
  • Plugin Contributor Michael Beckwith

    (@tw2113)

    The BenchPresser

    We **almost** do.

    https://github.com/WebDevStudios/wp-search-with-algolia/blob/main/includes/factories/class-algolia-search-client-factory.php#L60-L86

    Here we recently added ability to customize timeout values, but we stopped at that. A quick example of customizing what we have already can be seen below:

    <?php
    function wds_algolia_custom_searchclient_config( $config ) {
    	$config['connectTimeout'] = 5;  // default: 2
    	$config['readTimeout']    = 60; // default: 30
    	$config['writeTimeout']   = 60; // default: 30
    
    	return $config;
    }
    add_filter( 'algolia_custom_search_config', 'wds_algolia_custom_searchclient_config' );

    That said, I’m wondering if in our client factory, we could/should add support for an extra area. Perhaps a $config['headers'] array that could be added to and we iterate over that.

    Example from our end:

    if ( is_array($custom_config['headers'] ) && ! empty( $custom_config['headers'] ) ) {
    	$config->setDefaultHeaders( $custom_config['headers'] );
    }
     

    And then you could pass in your needed one in a same way as the first demo filter?

    Thoughts?

    Thread Starter tpg73

    (@tpg73)

    Thanks for letting us know.
    Thanks to you, I was able to achieve what I wanted to do.

    I have implemented the following filter hooks

    function wds_algolia_custom_searchclient_config( $config ) {
    
    	$ip_address = $_SERVER['HTTP_X_FORWARDED_FOR'] ?? $_SERVER['REMOTE_ADDR'];
    
    	$headers = [
    		'X-Forwarded-For' => $ip_address,
    	];
    	$config['headers'] = $headers;
    
    	return $config;
    }
    add_filter( 'algolia_custom_search_config', 'wds_algolia_custom_searchclient_config' );

    And I added the following code to line 85 of class-algolia-search-client-factory.php

    if ( is_array($custom_config['headers'] ) && ! empty( $custom_config['headers'] ) ) {
    	$config->setDefaultHeaders( $custom_config['headers'] );
    }

    However, the result is editing the plugin source file directly, and future version upgrades may require re-editing the source file. Is this unavoidable in the current situation?

    Plugin Contributor Michael Beckwith

    (@tw2113)

    The BenchPresser

    Yes, I was mostly just looking for feedback on if you thought that looked like a good solution for your need, and as a consequence, you also already tested it out to confirm.

    That said, we don’t have an immediate release planned, but I have tentatively pushed this for a 2.9.0 release. Feel free to keep this in place for the moment, but keep an eye out on the changelog if you see a new release come out, just in case we didn’t get this change in.

    I have a PR that can be seen at https://github.com/WebDevStudios/wp-search-with-algolia/pull/416 but the biggest change is going to be the array key, which I’m going to switch out to better match with the config values from Algolia’s PHP API.

    Enhancement issue can be seen at https://github.com/WebDevStudios/wp-search-with-algolia/issues/415

    Thanks for the feedback. I’m going to mark this thread as resolved, but feel free to chime in with a bit more if/as needed.

    Thread Starter tpg73

    (@tpg73)

    Thank you for your response. I have also checked the issue. We will review the change log in a future update.

    Thank you very much for your help. Mark as resolved.

Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘How to set extra header’ is closed to new replies.