Skip to content

Conversation

@predic8
Copy link
Member

@predic8 predic8 commented Feb 11, 2026

Summary by CodeRabbit

  • New Features

    • Expanded HTTP request builder with method shortcuts and richer fluent body/format helpers; added snapshot creation and new public helpers (e.g., method/URI checks).
  • Improvements

    • Improved HTTP/1.0 handling and more accurate body-detection; added STOMP serialization and request heap-size estimation.
  • Tests

    • Extended tests for HTTP/1.0, empty-body scenarios, and request behavior; adjusted test lifecycle setup.

… body handling tests

- Changed `@BeforeAll` and `@AfterAll` annotations to non-static for consistency.
- Reorganized test setup and teardown logic to ensure proper resource management.
- Added test cases for HTTP/1.0 requests with and without bodies.
- Introduced `PATCH_EMPTY_BODY` and improved input stream naming for clarity.
- Updated `shouldNotContainBody` logic to handle HTTP/1.0 requests correctly.
@coderabbitai
Copy link
Contributor

coderabbitai bot commented Feb 11, 2026

📝 Walkthrough

Walkthrough

Request API visibility and internals were reorganized: method and uri made private; builder entry points for HTTP verbs and many fluent helpers were added; body-detection/HTTP/1.0 behavior adjusted; snapshot/heap-size and STOMP serialization APIs introduced; tests updated for HTTP/1.0 and empty-body cases.

Changes

Cohort / File(s) Summary
Request Core API
core/src/main/java/com/predic8/membrane/core/http/Request.java
Made method and uri private; reworked start-line parsing; added isHEAD/isGET/... helpers; adjusted body-detection (HTTP/1.0, content-length/transfer-encoding); added isBindTargetConnectionToIncoming(), estimateHeapSize(), createSnapshot(...), and writeSTOMP(...); expanded Builder with static verb factories and many overloads (get/post/put/delete/options/connect) plus fluent body/content helpers and URIFactory usage.
Tests: HTTP/1.0 and Empty-Body
core/src/test/java/com/predic8/membrane/core/http/RequestTest.java, core/src/test/java/com/predic8/membrane/core/http/Http10Test.java
Added HTTP/1.0 sample requests and tests; introduced separate empty-body constants for POST/PATCH; refactored tests to use setMethod/setUri instead of direct field access; changed several lifecycle/test method visibilities/names to package-private; updated setup/teardown streams and assertions.
Minor API surface changes
Tests and builders across repo (cohesive to Request changes) core/src/...
Field visibility changes required callers/tests to use setters and Builder entry points; snapshot/serialization additions touch serialization paths and tests.

Estimated code review effort

🎯 4 (Complex) | ⏱️ ~45 minutes

Possibly related issues

None

Possibly related PRs

Suggested reviewers

  • rrayst

Poem

🐰 Hopping through headers with a jittery cheer,
verbs line up neatly — get, post, put appear.
Fields tucked in pockets, snapshots snug and bright,
HTTP/1.0 whispers, empty bodies alight.
I nibble a carrot and applaud the new sight! 🥕

🚥 Pre-merge checks | ✅ 2 | ❌ 1
❌ Failed checks (1 warning)
Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 5.71% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (2 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The PR title 'PATCH Method with no Body' directly aligns with the primary changeset, which introduces support for handling PATCH requests without bodies (adding PATCH_EMPTY_BODY constant, Http/1.0 empty body handling, and related test coverage).

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

✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch patch-with-no-body-fix

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.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🤖 Fix all issues with AI agents
In `@core/src/test/java/com/predic8/membrane/core/http/RequestTest.java`:
- Around line 140-153: The tearDown method omits closing the inPatchEmptyBody
InputStream causing a resource leak; update the tearDown method (which currently
calls closeQuietly for getReq, inPost, inPostEmptyBody, etc.) to also call
closeQuietly(inPatchEmptyBody) so the stream initialized in setUp is properly
closed; ensure the reference uses the exact field name inPatchEmptyBody and keep
it alongside the other closeQuietly(...) calls in tearDown.
🧹 Nitpick comments (2)
core/src/main/java/com/predic8/membrane/core/http/Request.java (2)

48-51: Fields method and uri changed from private to package-private.

This relaxes encapsulation to allow direct field access from test code in the same package (see RequestTest.create() at line 396). This is a reasonable trade-off for testability, but worth noting that any class in com.predic8.membrane.core.http can now mutate these fields directly, bypassing setters.


178-200: Static factory methods create a new URIFactory on every call.

Each get(String), post(String), delete(String), etc. instantiates a new URIFactory() internally. If URIFactory construction is non-trivial, this could become a concern on hot paths. For now this is fine, but consider documenting that the URIFactory-accepting overloads should be preferred for performance-sensitive code.

…est`

- Replaced direct field access with `setMethod` and `setUri` to improve encapsulation.
- Adjusted `RequestTest` to use setters for `method` and `uri`.
Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 2

🤖 Fix all issues with AI agents
In `@core/src/main/java/com/predic8/membrane/core/http/Request.java`:
- Around line 259-262: The Builder.contentType(String) method currently calls
req.getHeader().add(CONTENT_TYPE, value) which can create duplicate Content-Type
headers; change it to use the same header replacement logic as json()/xml() by
calling the header's setContentType(...) or equivalent replace method on
req.getHeader() so the Content-Type is replaced rather than appended (i.e.,
update Builder.contentType to use req.getHeader().setContentType(...) or the
header object used by json()/xml()).
- Around line 215-226: The buildExchange() path currently always adds the field
fullURL to exc.getDestinations(), which can be null when Request was built via
uri(String) or connect(String); update
Request.buildExchange(AbstractHttpHandler) (and the no-arg buildExchange()) to
avoid adding null: if fullURL is non-null add it as now, otherwise add a safe
alternative such as req.getUri().toString() (or simply skip adding) so no null
is inserted into Exchange.getDestinations(); locate the code in the
buildExchange methods and replace the unconditional
exc.getDestinations().add(fullURL) with a null-check and the fallback.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🤖 Fix all issues with AI agents
In `@core/src/main/java/com/predic8/membrane/core/http/Request.java`:
- Around line 350-354: The connect() Builder helper directly calls
req.setMethod(METHOD_CONNECT) and req.setUri(...) and therefore bypasses the
method(...) and url(...) helpers so fullURL is never initialized, causing
buildExchange() to add a null destination; fix by ensuring
Builder.connect(String url) sets fullURL (e.g., fullURL = url) and then
delegates to method(METHOD_CONNECT) and url(url) or at minimum assign fullURL
before calling req.setUri/getAuthority; update the connect() implementation
(refer to Builder.connect, method(...), url(...), fullURL, req.setMethod,
req.setUri, buildExchange()) to match the other verb helpers' behavior.
🧹 Nitpick comments (2)
core/src/main/java/com/predic8/membrane/core/http/Request.java (2)

56-68: STOMP fallback silently swallows malformed HTTP request lines.

Since stompPattern (^(.+?)$) matches any non-empty string, a malformed HTTP request line like "GET /foo" (missing version) will be silently parsed as a STOMP frame instead of raising EOFWhileReadingFirstLineException. This could mask real protocol errors in non-STOMP contexts.

Consider adding a stricter STOMP check (e.g., matching known STOMP commands like CONNECT, SEND, SUBSCRIBE, etc.) or using an external flag to indicate whether STOMP is expected on this connection.


178-200: No patch() convenience method on the Builder, despite METHOD_PATCH being defined.

Static entry points and instance methods exist for GET, POST, PUT, DELETE, OPTIONS, and CONNECT, but PATCH is missing — which is ironic given the PR title. Consider adding patch(String) and patch(URIFactory, String) for consistency.

Proposed addition
 public static Builder connect(String url) throws URISyntaxException {
     return new Builder().connect(url);
 }
+
+public static Builder patch(String url) throws URISyntaxException {
+    return new Builder().patch(url);
+}

And in the Builder class:

public Builder patch(URIFactory uriFactory, String url) throws URISyntaxException {
    return method(Request.METHOD_PATCH).url(uriFactory, url);
}

public Builder patch(String url) throws URISyntaxException {
    return patch(new URIFactory(), url);
}

@predic8
Copy link
Member Author

predic8 commented Feb 11, 2026

/ok-to-test

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.

2 participants