OpenFeign / OpenFeign/feign

Pass RequestTemplate to the client implementation

Open
#1,435 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Java
Stars
9.8k
Forks
1.9k
Avg merge
1d 2h
Merged PRs (30d)
41

Description

Feign allow to add request interceptor. Sometimes it is not sufficient and we need to use the low level client implementation extension mechanism but the requestTemplate context is not flowing and we miss some information.

For eg. I have apache httpclient request and response interceptor. They have access to the apache HttpContext and it should contains a way to get access to the requestTemplate.

I reimplement ApacheHttpClient and change the execute method to be

  @Override
  public Response execute(Request request, Request.Options options) throws IOException {
    HttpUriRequest httpUriRequest;
    try {
      httpUriRequest = toHttpUriRequest(request, options);
    } catch (URISyntaxException e) {
      throw new IOException("URL '" + request.url() + "' couldn't be parsed into a URI", e);
    }
    // inject requestTemplate to allow interceptors to know the feign request metadata
    BasicHttpContext context = new BasicHttpContext();
    context.setAttribute("feign.requestTemplate", request.requestTemplate());
    HttpResponse httpResponse = client.execute(httpUriRequest, context);
    return toFeignResponse(httpResponse, request);
  }

This is a simple modification but the actual ApacheHttpClient is final, meaning we need to copy/paste the whole class content.

The apache interceptor can then extract the requestTemplate and access any metadata it may needs like method annotations.

I don't know if this can be done for all client implementations, but a common pattern and a convention for the name of the key in the client context may be adopted.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with the ApacheHttpClient execute implementation described in the issue, then inspect the other client implementations to determine whether a shared request-context convention is feasible. Define how RequestTemplate reaches client-level interceptors and verify the behavior across applicable clients; the issue names no tests or specific files beyond the ApacheHttpClient example.

Written by the indexing model from the issue text.

Assessment

Tech stack
java
Domain
api, backend
Issue type
Feature
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.