Skip to content

Commit

Permalink
feat(feign client): set a fake metadata after resquest is completed s…
Browse files Browse the repository at this point in the history
…o that response headers will not be blank
  • Loading branch information
lony2003 committed Jun 25, 2024
1 parent 8ef091b commit 44fa37b
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 2 deletions.
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ buildscript {
mavenCentral()
}
ext {
projectVersion = '0.5.0'
projectVersion = '0.5.1'

// https://github.com/google/guava/releases
guavaVersion = '33.1.0-jre'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,9 @@
* You can put some metadata into the Header of your Feign Request, the Client will handle them.
* <p>
* As for response, the result code is always 200 OK, and if client have met any error, it will throw an IOException for
* that.
* that.<br>
* Currently, we have no method to gain metadata from server as Dapr Client doesn't have methods to do that, so headers will be blank.
* If Accept header has set in request, a fake Content-Type header will be created in response, and it will be the first value of Accept header.
*
* <pre>
* MyAppData response = Feign.builder().client(new DaprFeignClient()).target(MyAppData.class,
Expand Down Expand Up @@ -123,10 +125,19 @@ public Response execute(Request request, Request.Options options) throws IOExcep
default -> throw new IOException("Schema '" + schema + "' is not supported");
};

Map<String, Collection<String>> headerMap = new HashMap<>();

if (request.headers().containsKey("Accept")) {
headerMap.put("Content-Type", List.of(request.headers().get("Accept")
.stream().findFirst()
.orElseThrow(() -> new IOException("Accept header can not be null"))));
}

return Response.builder()
.status(200)
.reason("OK")
.request(request)
.headers(headerMap)
.body(toResponseBody(result, options))
.build();
}
Expand Down

0 comments on commit 44fa37b

Please sign in to comment.