Skip to content

Feature/body size filter - #139

Merged
DennSel merged 18 commits into
mainfrom
feature/body-size-filter
Feb 27, 2026
Merged

Feature/body size filter#139
DennSel merged 18 commits into
mainfrom
feature/body-size-filter

Conversation

@DennSel

@DennSel DennSel commented Feb 26, 2026

Copy link
Copy Markdown

Summary

  • Added 'BodySizeFilter' to reject requests with body > 10MB
  • Returns HTTP 413 Payload Too Large when exceeded
  • Configurable via 'request-body-size.enabled' and 'max-size-mb' in YAML
  • Only validates POST/PUT/PATCH requests
  • Added comprehensive unit tests

Changes

  • Added 'PAYLOAD_TOO_LARGE(413)' status to 'HttpStatus'
  • Added 'BodySizeConfig' class
  • Added 'BodySizeFilter' with @global(order = 1)
  • Updated 'ConfigLoader' to read request-body-size config
  • Updated 'application-properties.yml' with default config
  • Added 'BodySizeFilterTest' with 8 test cases

Testing

  • All unit tests pass: 'mvn test'
  • Manually tested with curl:
    • Small requests (5 bytes) → 405 (allowed)
    • Large requests (15MB) → 413 (blocked)
    • Missing Content-Length → 413 (blocked)

Summary by CodeRabbit

  • New Features

    • Enforces a configurable request body size limit for POST/PUT/PATCH; returns 413 Payload Too Large or 411 Length Required when appropriate.
  • Configuration

    • New request-body-size settings (enabled flag and max-size-mb) with a default max of 10 MB; administrators can enable/adjust the limit.
  • Tests

    • Added unit tests covering allowed/blocked requests, missing/invalid Content-Length, header variants, and configuration validation.

Add support for rejecting too large bodies with the proper HTTP code
add getters for body size config
HTTP method checking

implement Content-Length validation in BodySizeFilter
Reject requests with missing, invalid, or oversized Content-Length headers with HTTP 413

add HTTP method checking to BodySizeFilter
Only validate body size for POST/PUT/PATCH requests. Allow all others to pass.
Enable request body size limiting with 10MB default maximum.
Run code formatter to comply with project style guidelines. All tests passing.
@coderabbitai

coderabbitai Bot commented Feb 26, 2026

Copy link
Copy Markdown
📝 Walkthrough

Walkthrough

Adds request-body-size configuration and enforcement: new BodySizeConfig and BodySizeFilter, config keys in ConfigLoader and application-properties, new HTTP statuses (411, 413), and unit tests validating filter behavior.

Changes

Cohort / File(s) Summary
Configuration & Resources
src/main/java/org/juv25d/config/BodySizeConfig.java, src/main/java/org/juv25d/util/ConfigLoader.java, src/main/resources/application-properties.yml
Adds BodySizeConfig; extends ConfigLoader with request-body-size parsing (enabled, max-size-mb), defaults (enabled=false, max-size-mb=10) and accessors isBodySizeEnabled() / getMaxBodySizeMb(); adds config YAML block.
Filter & HTTP Status
src/main/java/org/juv25d/filter/BodySizeFilter.java, src/main/java/org/juv25d/http/HttpStatus.java
Introduces global BodySizeFilter enforcing Content-Length checks for POST/PUT/PATCH, returning 411/400/413 as appropriate; adds LENGTH_REQUIRED(411) and PAYLOAD_TOO_LARGE(413) to HttpStatus.
Tests
src/test/java/org/juv25d/filter/BodySizeFilterTest.java
Adds JUnit5+Mockito tests covering allowed/blocked requests, missing/invalid Content-Length, method variants (GET/PUT/PATCH), header case/whitespace handling, and invalid configuration behavior.

Sequence Diagram

sequenceDiagram
    participant Client
    participant BodySizeFilter
    participant ConfigLoader
    participant FilterChain
    participant HttpResponse

    Client->>BodySizeFilter: HTTP request (POST/PUT/PATCH)
    BodySizeFilter->>ConfigLoader: isBodySizeEnabled()
    ConfigLoader-->>BodySizeFilter: enabled

    alt Disabled
        BodySizeFilter->>FilterChain: forward request
    else Enabled
        BodySizeFilter->>BodySizeFilter: read Content-Length header
        alt Missing or non-numeric or negative
            BodySizeFilter->>HttpResponse: set 411/400/413 with body
            HttpResponse-->>Client: error response
        else Present
            BodySizeFilter->>ConfigLoader: getMaxBodySizeMb()
            ConfigLoader-->>BodySizeFilter: maxSizeMb
            alt Content-Length > maxSizeBytes
                BodySizeFilter->>HttpResponse: set 413 Payload Too Large
                HttpResponse-->>Client: 413 response
            else Within limit
                BodySizeFilter->>FilterChain: forward request
            end
        end
    end
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

Possibly related PRs

Suggested reviewers

  • johanbriger
  • TatjanaTrajkovic

Poem

🐰 I hopped through headers, light and keen,
Counting bytes in spaces unseen.
Ten megabytes is where I stand,
I guard the stream with gentle hand.
No oversized guests cross my land.

🚥 Pre-merge checks | ✅ 1 | ❌ 2

❌ Failed checks (1 warning, 1 inconclusive)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
Title check ❓ Inconclusive The title 'Feature/body size filter' is partially related but overly broad and generic; it describes the feature category rather than the specific change (implementing body size validation). Consider a more specific title like 'Add request body size validation filter' to clearly convey the primary change and make it more informative for code history.
✅ Passed checks (1 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
  • 📝 Generate docstrings (stacked PR)
  • 📝 Generate docstrings (commit on current branch)
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch feature/body-size-filter

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@DennSel DennSel changed the title Feature/body size filter Feature/body size filter #137 Feb 26, 2026
@DennSel DennSel changed the title Feature/body size filter #137 Feature/body size filter Feb 26, 2026

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 3

🧹 Nitpick comments (2)
src/main/java/org/juv25d/filter/BodySizeFilter.java (1)

108-114: Prefer HttpStatus.PAYLOAD_TOO_LARGE over hardcoded 413/text.

This avoids status drift and keeps response construction aligned with the centralized enum.

Proposed refactor
+import org.juv25d.http.HttpStatus;
@@
     private void sendPayloadTooLarge(HttpResponse res, String message) {
-        byte[] body = ("413 Payload Too Large: " + message + "\n")
+        byte[] body = (HttpStatus.PAYLOAD_TOO_LARGE.getCode() + " "
+            + HttpStatus.PAYLOAD_TOO_LARGE.getDescription() + ": " + message + "\n")
             .getBytes(StandardCharsets.UTF_8);
 
-        res.setStatusCode(413);
-        res.setStatusText("Payload Too Large");
+        res.setStatusCode(HttpStatus.PAYLOAD_TOO_LARGE.getCode());
+        res.setStatusText(HttpStatus.PAYLOAD_TOO_LARGE.getDescription());
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@src/main/java/org/juv25d/filter/BodySizeFilter.java` around lines 108 - 114,
Replace the hardcoded numeric/status text in sendPayloadTooLarge: use the
centralized HttpStatus.PAYLOAD_TOO_LARGE enum value to set the response status
and reason instead of 413 and "Payload Too Large". Call the appropriate getters
on HttpStatus.PAYLOAD_TOO_LARGE to populate res.setStatusCode(...) and
res.setStatusText(...) (leaving headers/body as-is) so the handler stays in sync
with the shared status enum.
src/test/java/org/juv25d/filter/BodySizeFilterTest.java (1)

110-120: Add regression tests for negative and case-variant Content-Length.

Given this filter’s core responsibility, it’s worth pinning behavior for Content-Length: -1 and lowercase header key forms to prevent future regressions.

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@src/test/java/org/juv25d/filter/BodySizeFilterTest.java` around lines 110 -
120, Add two regression tests to BodySizeFilterTest: one named
shouldBlockRequest_whenContentLengthNegative that constructs BodySizeFilter(10),
stubs req.method() to "POST" and req.headers() to Map.of("Content-Length", "-1")
(or "content-length" variant if header normalization is expected), calls
filter.doFilter(req, res, chain), then asserts verifyNoInteractions(chain) and
verify(res).setStatusCode(413); and another named
shouldHandleRequest_whenContentLengthHeaderLowercase that stubs req.method() to
"POST" and req.headers() to Map.of("content-length", "5"), calls
filter.doFilter(...), then asserts the request proceeds via
verify(chain).doFilter(req, res) (and does not set 413). Target the existing
test class BodySizeFilterTest and the BodySizeFilter.doFilter behavior for
locating where to add these tests.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@src/main/java/org/juv25d/filter/BodySizeFilter.java`:
- Around line 60-67: The Content-Length parsing in BodySizeFilter currently
allows negative values; after parsing contentLength into bodySize in the try
block, add a check for bodySize < 0 and treat it as invalid by logging and
returning a 413 like the oversized case (use the same logging helper
logBodySizeExceeded(req, bodySize) or an appropriate negative-value log and call
sendPayloadTooLarge(res, "...") with a message indicating an invalid negative
Content-Length), otherwise keep the existing maxSizeBytes comparison; ensure
this logic sits inside the same try block that parses
Long.parseLong(contentLength) so NumberFormatException still falls through to
existing handling.

In `@src/main/java/org/juv25d/util/ConfigLoader.java`:
- Around line 117-123: ConfigLoader currently accepts non-positive
request-body-size.max-size-mb; update the bodySizeConfig handling (in the block
that sets requestBodySizeEnabled and maxBodySizeMb) to parse the "max-size-mb"
value as a long, verify it is > 0, and if not throw a clear configuration
exception (e.g., IllegalArgumentException) mentioning
"request-body-size.max-size-mb" and the invalid value; keep the existing default
(10L) when missing, but enforce the positive check after parsing and before
assigning to the maxBodySizeMb field.

In `@src/test/java/org/juv25d/filter/BodySizeFilterTest.java`:
- Around line 67-70: The test method name should reflect that the setup
simulates a missing Content-Length header rather than a zero length body: rename
the test method shouldBlockRequest_whenMethodHasBodyButSizeIsZero() to something
like shouldBlockRequest_whenMethodHasBodyButNoContentLength() (or similar) to
match the arrangement using BodySizeFilter, the mocked req.method() returning
"POST", and req.headers() returning an empty map.

---

Nitpick comments:
In `@src/main/java/org/juv25d/filter/BodySizeFilter.java`:
- Around line 108-114: Replace the hardcoded numeric/status text in
sendPayloadTooLarge: use the centralized HttpStatus.PAYLOAD_TOO_LARGE enum value
to set the response status and reason instead of 413 and "Payload Too Large".
Call the appropriate getters on HttpStatus.PAYLOAD_TOO_LARGE to populate
res.setStatusCode(...) and res.setStatusText(...) (leaving headers/body as-is)
so the handler stays in sync with the shared status enum.

In `@src/test/java/org/juv25d/filter/BodySizeFilterTest.java`:
- Around line 110-120: Add two regression tests to BodySizeFilterTest: one named
shouldBlockRequest_whenContentLengthNegative that constructs BodySizeFilter(10),
stubs req.method() to "POST" and req.headers() to Map.of("Content-Length", "-1")
(or "content-length" variant if header normalization is expected), calls
filter.doFilter(req, res, chain), then asserts verifyNoInteractions(chain) and
verify(res).setStatusCode(413); and another named
shouldHandleRequest_whenContentLengthHeaderLowercase that stubs req.method() to
"POST" and req.headers() to Map.of("content-length", "5"), calls
filter.doFilter(...), then asserts the request proceeds via
verify(chain).doFilter(req, res) (and does not set 413). Target the existing
test class BodySizeFilterTest and the BodySizeFilter.doFilter behavior for
locating where to add these tests.

ℹ️ Review info

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between e46bb6b and 79227c6.

📒 Files selected for processing (6)
  • src/main/java/org/juv25d/config/BodySizeConfig.java
  • src/main/java/org/juv25d/filter/BodySizeFilter.java
  • src/main/java/org/juv25d/http/HttpStatus.java
  • src/main/java/org/juv25d/util/ConfigLoader.java
  • src/main/resources/application-properties.yml
  • src/test/java/org/juv25d/filter/BodySizeFilterTest.java

Comment thread src/main/java/org/juv25d/filter/BodySizeFilter.java
Comment thread src/main/java/org/juv25d/util/ConfigLoader.java
Comment thread src/test/java/org/juv25d/filter/BodySizeFilterTest.java Outdated
@DennSel DennSel linked an issue Feb 26, 2026 that may be closed by this pull request

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🧹 Nitpick comments (1)
src/test/java/org/juv25d/filter/BodySizeFilterTest.java (1)

134-144: Add a whitespace-value regression test for Content-Length.

You already cover lowercase header keys well (Line 135+). Add one case for values like " 5 " to lock expected behavior around header value normalization.

🧪 Proposed test addition
+    `@Test`
+    void shouldAllowRequest_whenContentLengthHasSurroundingWhitespace() throws IOException {
+        BodySizeFilter filter = new BodySizeFilter(10);
+        when(req.method()).thenReturn("POST");
+        when(req.headers()).thenReturn(Map.of("Content-Length", " 5 "));
+
+        filter.doFilter(req, res, chain);
+
+        verify(chain, times(1)).doFilter(req, res);
+        verifyNoInteractions(res);
+    }
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@src/test/java/org/juv25d/filter/BodySizeFilterTest.java` around lines 134 -
144, Add a regression test in BodySizeFilterTest to ensure Content-Length header
values with surrounding whitespace are handled correctly: create a test (e.g.,
shouldAllowRequest_whenContentLengthHeaderValueHasWhitespace) that instantiates
BodySizeFilter(10), mocks req.method() to "POST" and req.headers() to return
Map.of("content-length", " 5 "), calls filter.doFilter(req, res, chain), and
then verifies chain.doFilter(req, res) was called once and that there were no
interactions with res; this locks expected normalization/trim behavior in the
BodySizeFilter logic.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Nitpick comments:
In `@src/test/java/org/juv25d/filter/BodySizeFilterTest.java`:
- Around line 134-144: Add a regression test in BodySizeFilterTest to ensure
Content-Length header values with surrounding whitespace are handled correctly:
create a test (e.g.,
shouldAllowRequest_whenContentLengthHeaderValueHasWhitespace) that instantiates
BodySizeFilter(10), mocks req.method() to "POST" and req.headers() to return
Map.of("content-length", " 5 "), calls filter.doFilter(req, res, chain), and
then verifies chain.doFilter(req, res) was called once and that there were no
interactions with res; this locks expected normalization/trim behavior in the
BodySizeFilter logic.

ℹ️ Review info

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 79227c6 and dc8c74e.

📒 Files selected for processing (3)
  • src/main/java/org/juv25d/filter/BodySizeFilter.java
  • src/main/java/org/juv25d/util/ConfigLoader.java
  • src/test/java/org/juv25d/filter/BodySizeFilterTest.java
🚧 Files skipped from review as they are similar to previous changes (1)
  • src/main/java/org/juv25d/util/ConfigLoader.java

test to verify that Content-Length values with surrounding
whitespace are trimmed and handled correctly per HTTP specification.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 2

🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@src/main/java/org/juv25d/filter/BodySizeFilter.java`:
- Around line 34-38: The BodySizeConfig/BodySizeFilter flow must validate
maxSizeMb and prevent MB→bytes overflow: in BodySizeConfig (constructor/getter)
validate that maxSizeMb is non-negative and within a safe upper bound (e.g., <=
Long.MAX_VALUE / (1024*1024)), and in BodySizeFilter constructors (the
BodySizeFilter() and the other constructor around lines 24-29) perform the same
check before assigning maxSizeBytes; if validation fails throw an
IllegalArgumentException so the app fails fast rather than silently overflowing
or producing a negative maxSizeBytes, and compute maxSizeBytes using a checked
multiplication (or cast/compare) to guarantee no overflow when multiplying
getMaxSizeMb() by 1024*1024.
- Around line 54-56: In BodySizeFilter replace the stream predicate that does
e.getKey().equalsIgnoreCase("Content-Length") with a null-safe check so null
header keys don't throw; for example, change the filter to check the key is
non-null before calling equalsIgnoreCase or use
"Content-Length".equalsIgnoreCase(e.getKey()) in the lambda that builds the
contentLength from req.headers().entrySet().stream(), keeping the subsequent
.map(Map.Entry::getValue) logic intact.

ℹ️ Review info

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between dc8c74e and 222df97.

📒 Files selected for processing (2)
  • src/main/java/org/juv25d/filter/BodySizeFilter.java
  • src/test/java/org/juv25d/filter/BodySizeFilterTest.java
🚧 Files skipped from review as they are similar to previous changes (1)
  • src/test/java/org/juv25d/filter/BodySizeFilterTest.java

Comment thread src/main/java/org/juv25d/filter/BodySizeFilter.java
Comment thread src/main/java/org/juv25d/filter/BodySizeFilter.java
@DennSel DennSel self-assigned this Feb 26, 2026

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

♻️ Duplicate comments (1)
src/main/java/org/juv25d/filter/BodySizeFilter.java (1)

34-38: ⚠️ Potential issue | 🟡 Minor

Skip toBytes() when filter is disabled to avoid spurious startup failures.

If the filter is disabled in configuration, the maxSizeBytes value is never used. Calling toBytes() unconditionally means a disabled filter with an invalid maxSizeMb config (e.g., 0 or negative) will throw at startup, even though the feature is off.

Proposed fix
     public BodySizeFilter() {
         BodySizeConfig config = new BodySizeConfig();
         this.enabled = config.isEnabled();
-        this.maxSizeBytes = toBytes(config.getMaxSizeMb());
+        this.maxSizeBytes = this.enabled ? toBytes(config.getMaxSizeMb()) : 0L;
     }
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@src/main/java/org/juv25d/filter/BodySizeFilter.java` around lines 34 - 38,
The constructor in BodySizeFilter currently calls toBytes(config.getMaxSizeMb())
unconditionally which can throw on invalid config even when the filter is
disabled; change the BodySizeFilter() constructor to first read enabled =
config.isEnabled() and only call toBytes(config.getMaxSizeMb()) to set
maxSizeBytes when enabled is true (otherwise set maxSizeBytes to a safe default
like 0 or leave it unset) so disabled filters do not trigger startup failures;
update references to BodySizeConfig.getMaxSizeMb(), the enabled field, and the
toBytes(...) helper accordingly.
🧹 Nitpick comments (2)
src/main/java/org/juv25d/filter/BodySizeFilter.java (2)

17-17: Minor: Missing space before opening brace.

Formatting nit: implements Filter{ should have a space before {.

-public class BodySizeFilter implements Filter{
+public class BodySizeFilter implements Filter {
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@src/main/java/org/juv25d/filter/BodySizeFilter.java` at line 17, Formatting
nit: in the class declaration for BodySizeFilter (public class BodySizeFilter
implements Filter{) add a space before the opening brace so it reads "implements
Filter {", ensuring the class signature follows the project's spacing
conventions.

98-101: Consider null-safe method comparison.

If req.method() could return null (e.g., malformed request), calling method.equalsIgnoreCase(...) would throw NPE. Using the constant on the left side makes this null-safe.

Proposed fix
     private boolean shouldCheckBodySize(HttpRequest req) {
         String method = req.method();
-        return method.equalsIgnoreCase("POST") || method.equalsIgnoreCase("PUT") || method.equalsIgnoreCase("PATCH");
+        return "POST".equalsIgnoreCase(method) || "PUT".equalsIgnoreCase(method) || "PATCH".equalsIgnoreCase(method);
     }
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@src/main/java/org/juv25d/filter/BodySizeFilter.java` around lines 98 - 101,
The shouldCheckBodySize(HttpRequest req) method calls req.method() and then
invokes equalsIgnoreCase on that result which can NPE if req.method() is null;
change the comparison to be null-safe by either checking req.method() for null
first or by calling equalsIgnoreCase on the constant strings (e.g.,
"POST".equalsIgnoreCase(req.method())) for each check so that
shouldCheckBodySize returns true for POST/PUT/PATCH without risking a
NullPointerException.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Duplicate comments:
In `@src/main/java/org/juv25d/filter/BodySizeFilter.java`:
- Around line 34-38: The constructor in BodySizeFilter currently calls
toBytes(config.getMaxSizeMb()) unconditionally which can throw on invalid config
even when the filter is disabled; change the BodySizeFilter() constructor to
first read enabled = config.isEnabled() and only call
toBytes(config.getMaxSizeMb()) to set maxSizeBytes when enabled is true
(otherwise set maxSizeBytes to a safe default like 0 or leave it unset) so
disabled filters do not trigger startup failures; update references to
BodySizeConfig.getMaxSizeMb(), the enabled field, and the toBytes(...) helper
accordingly.

---

Nitpick comments:
In `@src/main/java/org/juv25d/filter/BodySizeFilter.java`:
- Line 17: Formatting nit: in the class declaration for BodySizeFilter (public
class BodySizeFilter implements Filter{) add a space before the opening brace so
it reads "implements Filter {", ensuring the class signature follows the
project's spacing conventions.
- Around line 98-101: The shouldCheckBodySize(HttpRequest req) method calls
req.method() and then invokes equalsIgnoreCase on that result which can NPE if
req.method() is null; change the comparison to be null-safe by either checking
req.method() for null first or by calling equalsIgnoreCase on the constant
strings (e.g., "POST".equalsIgnoreCase(req.method())) for each check so that
shouldCheckBodySize returns true for POST/PUT/PATCH without risking a
NullPointerException.

ℹ️ Review info

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 222df97 and 7058541.

📒 Files selected for processing (1)
  • src/main/java/org/juv25d/filter/BodySizeFilter.java

@EmmaTravljanin

Copy link
Copy Markdown

ser bra ut :)

EmmaTravljanin
EmmaTravljanin previously approved these changes Feb 26, 2026

@jesperlarsson1910 jesperlarsson1910 left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Line 66 we call the too large method but the if statement is for null or empty, should that call something else?

Refactored BodySizeFilter to return 411 Length Required for missing headers and 400 Bad Request for invalid values, instead of a blanket 413. Expanded HttpStatus enum to
  include 411.
Updated test expectations in BodySizeFilterTest to align with new error handling. Tests now verify 411 for missing headers and 400 for invalid/negative values while retaining 413 for actual limit violations.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🧹 Nitpick comments (1)
src/main/java/org/juv25d/http/HttpStatus.java (1)

24-24: Minor: Extra blank line.

There's an unnecessary double blank line between the enum constants and the field declarations. Consider removing it for consistency.

🧹 Suggested fix
     PAYLOAD_TOO_LARGE(413, "Payload Too Large"),
     INTERNAL_SERVER_ERROR(500, "Internal Server Error"),
     NOT_IMPLEMENTED(501, "Not Implemented"),
     BAD_GATEWAY(502, "Bad Gateway"),
     GATEWAY_TIMEOUT(504, "Gateway Timeout"),
     UNKNOWN(-1, "Unknown Status");
-
 
     private final int code;
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@src/main/java/org/juv25d/http/HttpStatus.java` at line 24, In the HttpStatus
enum remove the extra blank line between the enum constants and the subsequent
field declarations so the constants and fields are directly adjacent; update the
HttpStatus enum formatting to have a single blank line (or none) separating
constants from fields to match project style and ensure consistent formatting.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Nitpick comments:
In `@src/main/java/org/juv25d/http/HttpStatus.java`:
- Line 24: In the HttpStatus enum remove the extra blank line between the enum
constants and the subsequent field declarations so the constants and fields are
directly adjacent; update the HttpStatus enum formatting to have a single blank
line (or none) separating constants from fields to match project style and
ensure consistent formatting.

ℹ️ Review info

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 7058541 and 9dcfbc4.

📒 Files selected for processing (3)
  • src/main/java/org/juv25d/filter/BodySizeFilter.java
  • src/main/java/org/juv25d/http/HttpStatus.java
  • src/test/java/org/juv25d/filter/BodySizeFilterTest.java
🚧 Files skipped from review as they are similar to previous changes (2)
  • src/main/java/org/juv25d/filter/BodySizeFilter.java
  • src/test/java/org/juv25d/filter/BodySizeFilterTest.java

@DennSel

DennSel commented Feb 26, 2026

Copy link
Copy Markdown
Author

Line 66 we call the too large method but the if statement is for null or empty, should that call something else?
@jesperlarsson1910
Good catch, you're right! I've updated the code to distinguish between the different error states.

@jesperlarsson1910 jesperlarsson1910 left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can't see anything that sticks out now, good job!

@DennSel
DennSel merged commit c0804cd into main Feb 27, 2026
2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Request Body Size Limit

3 participants