feign icon indicating copy to clipboard operation
feign copied to clipboard

How to handle context of a processing.

Open dulm opened this issue 2 years ago • 1 comments

I need to sign the content of body, then add to head. The signKey is different for each different user. So i need to pass signKey to SignRequestInterceptor, the signKey is context.
there is context concept in WebClient, can be retrive in any part of the procedue.

q1: In feign, is there any official way to save the context?

q2: We could use header as the context, but the defaultRequestHeaders is added as interceptor after the requestInterceptors. so we can't get the head in requestInterceptors.

Can feign fix it, change the order?

        defaultRequestHeaders:
          APP_ID: 123
          APP_KEY: abc
        requestInterceptors:
          - club.AuthRequestInterceptor

FeignClientFactoryBean.configureUsingProperties:

		if (config.getRequestInterceptors() != null && !config.getRequestInterceptors().isEmpty()) {
			// this will add request interceptor to builder, not replace existing
			for (Class<RequestInterceptor> bean : config.getRequestInterceptors()) {
				RequestInterceptor interceptor = getOrInstantiate(bean);
				builder.requestInterceptor(interceptor);
			}
		}
                ....
               /
		addDefaultRequestHeaders(config, builder);

dulm avatar Mar 23 '22 03:03 dulm

At the moment, this sort of capability is the responsibility of the User, not Feign, since this type of use case is tightly coupled to the user's needs. However, I'm not against a proposal on how we could incorporate basic context, or state into a Feign Target request pipeline.

kdavisk6 avatar Mar 24 '22 14:03 kdavisk6