Skip to content

[ENHANCEMENT] Enable passing a custom reqwest client to the TransportBuilder #55

@frenchtoastbeer

Description

@frenchtoastbeer

Is your feature request related to a problem? Please describe.
I wanted to disable certificate validation for testing, but realized that there is no TransportBuilder method which allows me to pass in a custom reqwest client.

Describe the solution you'd like
I'd like to first generate a client like so.
(I made an edit to remove calling build on the reqwest client)

let transport_client = Client::builder()
  .danger_accept_invalid_hostnames(true)
  .danger_accept_invalid_certs(true);

and then pass it to a TransportBuilder like so:

let transport = TransportBuilder::new(conn_pool)
  .disable_proxy()
  .with_client(transport_client)
  .build()?;

Describe alternatives you've considered
My first thought was to make client_builder public, but it may not be obvious that TransportBuilder.client_builder was a reqwest client.

Additional context
For some weird reason, when I tried this, it compiles and runs. I don't understand how that's possible, but even so it still revokes self-signed certs.

pub use client::new;

pub mod client {
  use elasticsearch::http::transport::{TransportBuilder,SingleNodeConnectionPool};
  use elasticsearch::{Elasticsearch,Error};
  use url::Url;

  pub fn new(url: &str) -> Result<Elasticsearch, Error> {
    let url = Url::parse(url).unwrap();
    let conn_pool = SingleNodeConnectionPool::new(url);
    let transport = TransportBuilder::new(conn_pool).disable_proxy();
    transport.client_builder // I thought this was private
      .danger_accept_invalid_hostnames(true) // but this doesn't cause a compiler error
      .danger_accept_invalid_certs(true);
    transport.build()?;
    return Ok(Elasticsearch::new(transport));
  }
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions