Skip to content

Can't add middleware for HttpClientBuilder -> HttpClient generic has private struct inside that can't be used as return arg or propery type. #1590

@rumatoest

Description

@rumatoest

It is impossible to add middlware to HttpClientBuilder

let middleware = RpcServiceBuilder::new()
        .rpc_logger(1024)
        .layer_fn(|service| MyMiddleware {
            service,
            count: std::sync::Arc::new(tokio::sync::Mutex::new(0)),
        });
let client = HttpClientBuilder::default()
            .set_rpc_middleware(middleware)
            .build(url);

It turned out that client does not have a type of HttpClient which is actually HttpClient<RpcLogger<http_client::rpc_service::RpcService<_>>>
But instead it has a type HttpClient<RpcLogger<MyMiddleware<http_client::rpc_service::RpcService<_>>>>
which I can not define anywhere (as a function return type) because http_client::rpc_service::RpcService is private. The struct itself is public but the module is private so I can't just return client from function or use it as a struct property.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions