![](/img/trans.png)
[英]Configure Infinispan in wildfly 14 standalone.xml instead of standalone-ha.xml
[英]How to configure ETag response header in standalone.xml in wildfly 12 server?
我想在每個響應中添加etag屬性。 我已經在響應中添加了variable-header和一個cache-control標頭(max-age = 600,公共),但是我沒有找到任何在響應中添加etag的解決方案。 誰能幫我嗎?
ETag標頭只是一個附加標頭,就像您已經添加的緩存控制標頭一樣。 看一下下面的示例代碼,用於在JAX-RS資源中生成ETag頭:
@GET
@Path("/yourResource/{id}")
public Response getPerson(@PathParam("id") String name, @Context Request request){
CacheControl cc = new CacheControl();
cc.setMaxAge(86400);
Response.ResponseBuilder rb = null;
EntityTag etag = new EntityTag(someService.getById(id).hashCode()+"");
responseBuilder = req.evaluatePreconditions(etag);
if (responseBuilder != null) {
return responseBuilder.cacheControl(cc).tag(etag).build();
}
responseBuilder = Response.ok(UserDatabase.getUserById(id)).cacheControl(cc).tag(etag);
return responseBuilder .build();
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.