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

This way of ReactiveHttpRequestInterceptor adding in the request header data, can you give a demo #687

Open
huhengyuan opened this issue Dec 17, 2024 · 1 comment

Comments

@huhengyuan
Copy link

huhengyuan commented Dec 17, 2024

This way of ReactiveHttpRequestInterceptor adding in the request header data, based on jdk17 can give a demo, to the problem of implementation of this way to seek the aid of bosses. Thank you very much.

@huhengyuan
Copy link
Author

huhengyuan commented Dec 18, 2024

@Configuration
public class FeignConfig implements ReactiveHttpRequestInterceptor {


    /**
     * Applies this function to the given argument.
     *
     * @param reactiveHttpRequest the function argument
     * @return the function result
     */
    @Override
    public Mono<ReactiveHttpRequest> apply(ReactiveHttpRequest reactiveHttpRequest) {
        return Mono.deferContextual(context -> {
            // 从 Reactor Context 中获取 token
            String token = context.get(HttpHeaders.AUTHORIZATION);
            // 将 token 放入请求头
            assert token != null;
            reactiveHttpRequest.headers().put(HttpHeaders.AUTHORIZATION, List.of(token));

            return Mono.just(reactiveHttpRequest);
        });
    }
}

已找到方案

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