Return value from getLastModified is not truncated to seconds
Nobody has claimed this yet.
- Dominant language
- Java
- Stars
- 325
- Forks
- 112
- PR merge metrics
- No merged PRs in 30d
Description
Consider this servlet:
```kotlin
package org.acme
import jakarta.servlet.annotation.WebServlet
import jakarta.servlet.http.HttpServlet
import jakarta.servlet.http.HttpServletRequest
import jakarta.servlet.http.HttpServletResponse
@WebServlet(urlPatterns = ["/test"])
class TestServlet : HttpServlet() {
override fun doGet(req: HttpServletRequest, resp: HttpServletResponse) {
resp.contentType = "text/plain"
resp.writer.write("Hello")
}
override fun getLastModified(req: HttpServletRequest): Long {
return 1750746812123
}
}
```
Run up an application with this servlet then follow these steps:
1. Run `curl -v http://localhost:8080/test`.
2. Observe that the response includes the header `Last-Modified: Tue, 24 Jun 2025 06:33:32 GMT`.
3. Run `curl -v http://localhost:8080/test -H 'If-Modified-Since: Tue, 24 Jun 2025 06:33:32 GMT'`.
Expected result:
A 304 not modified response is returned.
Actual result:
A 200 response is returned.
If you then modify the servlet to return `1750746812000` from `getLastModified` then the last curl command returns the 304 as expected.
Compare your implementation to Tomcat’s for example; they truncate the value returned by `getLastModified` to the second before comparing it with the `If-Modified-Since` timestamp because that’s the precision of HTTP dates.
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.
Research direction
Start by locating the servlet handling for getLastModified and the comparison with the If-Modified-Since request header. Reproduce the behavior with the two curl commands from the report, then verify that a sub-second return value produces the expected 304 response.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- java
- Domain
- api, backend
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 48/100