Skip to content

Commit

Permalink
Fix @nocache without fields handling in RESTEasy Reactive
Browse files Browse the repository at this point in the history
  • Loading branch information
geoand committed Sep 1, 2021
1 parent fe1a755 commit 07db37f
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -30,37 +30,53 @@ public JavaArchive get() {
});

@Test
public void testWith() {
RestAssured.get("/test/with")
public void testWithFields() {
RestAssured.get("/test/withFields")
.then()
.statusCode(200)
.body(equalTo("with"))
.body(equalTo("withFields"))
.header("Cache-Control", "no-cache=\"f1\", no-cache=\"f2\"");
}

@Test
public void testWithout() {
RestAssured.get("/test/without")
public void testWithoutFields() {
RestAssured.get("/test/withoutFields")
.then()
.statusCode(200)
.body(equalTo("without"))
.body(equalTo("withoutFields"))
.header("Cache-Control", "no-cache");
}

@Test
public void testWithoutAnnotation() {
RestAssured.get("/test/withoutAnnotation")
.then()
.statusCode(200)
.body(equalTo("withoutAnnotation"))
.header("Cache-Control", nullValue());
}

@Path("test")
public static class ResourceWithNoCache {

@Path("with")
@Path("withFields")
@GET
@NoCache(fields = { "f1", "f2" })
public String with() {
return "with";
public String withFields() {
return "withFields";
}

@Path("withoutFields")
@GET
@NoCache
public String withoutFields() {
return "withoutFields";
}

@Path("without")
@Path("withoutAnnotation")
@GET
public String without() {
return "without";
public String withoutAnnotation() {
return "withoutAnnotation";
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -61,18 +61,18 @@ private ExtendedCacheControl noCacheToCacheControl(AnnotationInstance noCacheIns
if (noCacheInstance == null) {
return null;
}
ExtendedCacheControl cacheControl = new ExtendedCacheControl();
cacheControl.setNoCache(true);
cacheControl.setNoTransform(false);
AnnotationValue fieldsValue = noCacheInstance.value("fields");
if (fieldsValue != null) {
String[] fields = fieldsValue.asStringArray();
if ((fields != null) && (fields.length > 0)) {
ExtendedCacheControl cacheControl = new ExtendedCacheControl();
cacheControl.setNoCache(true);
cacheControl.setNoTransform(false);
cacheControl.getNoCacheFields().addAll(Arrays.asList(fields));
return cacheControl;

}
}
return null;
return cacheControl;
}

private ExtendedCacheControl cacheToCacheControl(AnnotationInstance cacheInstance) {
Expand Down

0 comments on commit 07db37f

Please sign in to comment.