Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

per request headers #321

Open
tyro-jason opened this issue Sep 12, 2023 · 0 comments
Open

per request headers #321

tyro-jason opened this issue Sep 12, 2023 · 0 comments

Comments

@tyro-jason
Copy link

Hi There,

I added a static creator method modelled on the Util static methods to create a proxy, but with a Supplier<> instead of just a Map<String,String> to give me per request headers for things like tracing and auth...

    private static <T> T createClientProxy(ClassLoader classLoader, Class<T> proxyInterface, final IJsonRpcClient client, final Supplier<Map<String, String>> perRequestHeaderSupplier) {

        return (T) Proxy.newProxyInstance(classLoader, new Class<?>[]{proxyInterface}, (proxy, method, args) -> {
            if (method.getDeclaringClass() == Object.class) return proxyObjectMethods(method, proxy, args);

            final Object arguments = ReflectionUtil.parseArguments(method, args);
            final String methodName = method.getName();
            return client.invoke(methodName, arguments, method.getGenericReturnType(), perRequestHeaderSupplier.get());
        });
    }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant