DATAREST-835 - Search resources returning a single resource now get and consider ETag and Last-Modified headers.

We now interpret If-None-Match and If-Modified-Since headers on requests to resources backed by query methods returning a single instance only. This allows clients to optimize GET requests to those resources to save bandwidth.
This commit is contained in:
Oliver Gierke
2016-06-10 23:22:07 +02:00
parent 42378ab34d
commit aa7eec4683
11 changed files with 361 additions and 72 deletions

View File

@@ -343,4 +343,34 @@ public class MongoWebTests extends CommonWebTests {
mvc.perform(get(href)).andExpect(status().isOk());
}
/**
* @see DATAREST-835
*/
@Test
public void exposesETagHeaderForSearchResourceYieldingItemResource() throws Exception {
Link link = client.discoverUnique("profiles", "search", "findById");
Profile profile = repository.findAll().iterator().next();
mvc.perform(get(link.expand(profile.getId()).getHref()))//
.andExpect(header().string("ETag", is("\"0\"")))//
.andExpect(header().string("Last-Modified", is(notNullValue())));
}
/**
* @see DATAREST-835
*/
@Test
public void doesNotAddETagHeaderForCollectionQueryResource() throws Exception {
Link link = client.discoverUnique("profiles", "search", "findByType");
Profile profile = repository.findAll().iterator().next();
mvc.perform(get(link.expand(profile.getType()).getHref()))//
.andExpect(header().string("ETag", is(nullValue())))//
.andExpect(header().string("Last-Modified", is(nullValue())));
}
}