spring-projects / spring-projects/spring-data-rest
Updates with If-Unmodified-Since header return 412 but update the entity [DATAREST-1234]
@odrotbohm is already working on this.
Since Dec 31, 2020.
- Dominant language
- Java
- Stars
- 958
- Forks
- 568
- PR merge metrics
- No merged PRs in 30d
Description
Stefan Fussenegger opened DATAREST-1234 and commented
Currently a request containing If-Unmodified-Since returns 412 Precondition Failed but the object state is updated. This can be verified by appending this code to example.springdata.rest.headers.WebIntegrationTests in spring-data-examples/rest/headers:
mvc.perform(get(uri).header(IF_NONE_MATCH, response.getHeader(ETAG))).//
andExpect(status().isNotModified());
Thread.sleep(1000L);
mvc.perform(patch(uri).header(IF_UNMODIFIED_SINCE, response.getHeader(LAST_MODIFIED)).accept(MediaType.APPLICATION_JSON).contentType(MediaType.APPLICATION_JSON_UTF8).content("{\"firstname\": \"changed\"}")).//
andExpect(status().isPreconditionFailed());
mvc.perform(get(uri).header(IF_NONE_MATCH, response.getHeader(ETAG))).//
andExpect(status().isNotModified()); // fails with 200 OK
The reason this happens is that SDR ignores the header completely, updates the state accordingly and returns with 200 OK. Later a 412 Precondition Failed is generated by org.springframework.web.context.request.ServletWebRequest.checkNotModified(String, long) as the returned Last-Modified generated by the updated object is compared with If-Unmodified-Since.
Note that this behavior can only be observed for 200 OK response, i.e. if the response contains the body - which it does by default if an Accept header has been sent (see returnStatus == 200 in org.springframework.web.servlet.mvc.method.annotation.HttpEntityMethodProcessor.handleReturnValue(Object, MethodParameter, ModelAndViewContainer, NativeWebRequest))
1 votes, 2 watchers
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Assessment
This issue has not been assessed yet.