Skip to content

Commit

Permalink
add x-total-count to allowed cors headers
Browse files Browse the repository at this point in the history
issue #58
  • Loading branch information
alekszivko committed Mar 3, 2025
1 parent 6422261 commit 74af8b1
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ public void filter(ContainerRequestContext requestContext, ContainerResponseCont
if (origin != null && origin.matches(dotenv.get("ALLOWED_ORIGINS_AS_REGEX"))) {
responseContext.getHeaders().add("Access-Control-Allow-Origin", origin);
responseContext.getHeaders().add("Access-Control-Allow-Methods", "GET, POST, PUT, DELETE, HEAD");
responseContext.getHeaders().add("Access-Control-Allow-Headers", "Content-Type, Authorization");
responseContext.getHeaders().add("Access-Control-Allow-Headers", "Content-Type, Authorization, x-total-count");
responseContext.getHeaders().add("Access-Control-Allow-Credentials", true);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ public class XTotalCountResponseFilter implements ContainerResponseFilter {
public void filter(ContainerRequestContext requestContext, ContainerResponseContext responseContext) throws IOException {
var body = responseContext.getEntity();

if (!responseContext.getHeaders().containsKey("X-Total-Count") && body instanceof Collection) {
responseContext.getHeaders().add("X-Total-Count", ((Collection<?>) body).size());
if (!responseContext.getHeaders().containsKey("x-total-count".toLowerCase()) && body instanceof Collection) {
responseContext.getHeaders().add("x-total-count".toLowerCase(), ((Collection<?>) body).size());
}

}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,10 +45,10 @@ public Response getMatches(Optional<String> gameToken, Optional<String> userToke

public Response createPaginatedResponse(long totalData, PageRequest pageRequest, List<Match> bodyData) {
return Response.ok()
.header("X-Total-Count", totalData)
.header("X-Total-Pages", (int) ceil((double) totalData / pageRequest.size()))
.header("X-Page-Size", pageRequest.size())
.header("X-Current-Page", pageRequest.page())
.header("X-Total-Count".toLowerCase(), totalData)
.header("X-Total-Pages".toLowerCase(), (int) ceil((double) totalData / pageRequest.size()))
.header("X-Page-Size".toLowerCase(), pageRequest.size())
.header("X-Current-Page".toLowerCase(), pageRequest.page())
.entity(bodyData.stream()
.map(MatchRestDto::new)
.toList())
Expand Down

0 comments on commit 74af8b1

Please sign in to comment.