internal/Bitstream HEAD response#956
Conversation
[Port dspace-7_x] Return headers for HEAD request
|
Warning Rate limit exceeded@jr-rk has exceeded the limit for the number of commits or files that can be reviewed per hour. Please wait 7 minutes and 51 seconds before requesting another review. ⌛ How to resolve this issue?After the wait time has elapsed, a review can be triggered using the We recommend that you space out your commits to avoid hitting the rate limit. 🚦 How do rate limits work?CodeRabbit enforces hourly rate limits for each developer per organization. Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout. Please see our FAQ for further information. 📒 Files selected for processing (1)
## Walkthrough
The changes introduce explicit handling for HTTP HEAD requests in the bitstream retrieval REST controller, ensuring correct headers (including Content-Length) are set without returning a response body. Header initialization logic is refined to set headers conditionally. Integration tests are updated to verify the correct behavior and statistics logging for HEAD requests.
## Changes
| File(s) | Change Summary |
|---------------------------------------------------------------------------------------------|-----------------------------------------------------------------------------------------------------------------------|
| dspace-server-webapp/src/main/java/org/dspace/app/rest/BitstreamRestController.java | Adds explicit handling for HTTP HEAD requests, sets Content-Length header, and adjusts response logic accordingly. |
| dspace-server-webapp/src/main/java/org/dspace/app/rest/utils/HttpHeadersInitializer.java | Refines header initialization: sets Content-Length and Content-Disposition only when appropriate, removes HEAD logic. |
| dspace-server-webapp/src/test/java/org/dspace/app/rest/BitstreamRestControllerIT.java | Updates integration test to check HEAD request for correct headers, empty body, and adjusts statistics record count. |
## Sequence Diagram(s)
```mermaid
sequenceDiagram
participant Client
participant BitstreamRestController
participant HttpHeadersInitializer
Client->>BitstreamRestController: HEAD /bitstreams/{id}/content
BitstreamRestController->>HttpHeadersInitializer: Prepare headers (with length, disposition, etc.)
HttpHeadersInitializer-->>BitstreamRestController: Initialized headers
BitstreamRestController-->>Client: Response (headers only, no body)Poem
|
There was a problem hiding this comment.
Actionable comments posted: 0
🧹 Nitpick comments (1)
dspace-server-webapp/src/main/java/org/dspace/app/rest/utils/HttpHeadersInitializer.java (1)
147-149: Improved null-safety for Content-Length header.The null check before setting the Content-Length header adds robustness, though the implementation could be simplified.
Consider simplifying the null check to avoid potential boxing issues:
-if (Objects.nonNull((Long.valueOf(this.length)))) { +if (this.length > 0) { httpHeaders.put(HttpHeaders.CONTENT_LENGTH, Collections.singletonList(String.valueOf(this.length))); }
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (3)
dspace-server-webapp/src/main/java/org/dspace/app/rest/BitstreamRestController.java(2 hunks)dspace-server-webapp/src/main/java/org/dspace/app/rest/utils/HttpHeadersInitializer.java(3 hunks)dspace-server-webapp/src/test/java/org/dspace/app/rest/BitstreamRestControllerIT.java(2 hunks)
⏰ Context from checks skipped due to timeout of 90000ms (3)
- GitHub Check: dspace-dependencies / docker-build (linux/amd64, ubuntu-latest, true)
- GitHub Check: Run Integration Tests
- GitHub Check: Run Unit Tests
🔇 Additional comments (5)
dspace-server-webapp/src/main/java/org/dspace/app/rest/BitstreamRestController.java (2)
156-156: Good addition of explicit content length for headers.The addition of
.withLength(bit.getSizeBytes())ensures that the Content-Length header is properly set, which is essential for accurate HEAD request responses.
194-197: Well-implemented HEAD request handling.This implementation correctly handles HTTP HEAD requests by returning only headers without a response body, following HTTP protocol standards. The debug logging provides helpful visibility for troubleshooting.
dspace-server-webapp/src/test/java/org/dspace/app/rest/BitstreamRestControllerIT.java (2)
224-232: Comprehensive HEAD request test implementation.The test case properly verifies all important aspects of the HEAD request response:
- Status code (200 OK)
- Expected Content-Length header
- Content-Type header
- ETag header
- Empty response body
This provides complete validation of the new HEAD request functionality.
260-260: Correctly updated stats record count.The expected number of statistics records has been properly updated from 2 to 3 to account for the additional HEAD request now being logged.
dspace-server-webapp/src/main/java/org/dspace/app/rest/utils/HttpHeadersInitializer.java (1)
172-178: Enhanced Content-Disposition header handling.The improved check for null or empty disposition before setting the Content-Disposition header makes the code more robust. Moving the logging statement outside the conditional ensures consistent logging regardless of whether the header was set.
dspace-server-webapp/src/test/java/org/dspace/app/rest/BitstreamRestControllerIT.java
Outdated
Show resolved
Hide resolved
* Fixed browse - the results are not lowercase (#954) * S3-CESNET direct downloads (#949) * Return headers for HEAD request - the bitstream download endpoint (#956) * The bitstream name is encoded in the URL. (#958) * SWORDv2 issues: Cannot update bitstream of archived Item. The swordv2 url is not composed correctly. Fixed deleting the workspace item when used org.dspace.sword2.WorkflowManagerDefault (#957) * The file preview process not required username and password in UI (#960) * Added translation of distribution license for collection to Czech (#952) * Added dead and deadSince to handle rest (#948) * Display community and collection handle (#961) * Embargo during submission not recorded in provenance (#950) * Allow to access File Downloader for any authorized user (ufal#1199) * allow.edit.metadata property should also work for submitters that are members of collection SUBMIT subgroup (ufal#1202) * Prevent error 500 for non admin user uploading file to bundle (ufal#1205) * Track downloads as pageviews (ufal#1209) * Loading the bitstreams - performance issue (ufal#1211)
[Port dspace-7_x] Return headers for HEAD request
Problem description
When the HEAD request was called, it responded with default values.
Summary by CodeRabbit
New Features
Bug Fixes
Content-LengthandContent-Dispositionare set only when appropriate.Tests