Skip to content

Issue #109: Add HTTP HEAD support#124

Open
mikee13d wants to merge 2 commits into
mainfrom
feature/109-support-http-head
Open

Issue #109: Add HTTP HEAD support#124
mikee13d wants to merge 2 commits into
mainfrom
feature/109-support-http-head

Conversation

@mikee13d

@mikee13d mikee13d commented Apr 1, 2026

Copy link
Copy Markdown

This PR adds support for the HTTP HEAD method. HEAD requests now return the same status code and headers as GET requests, but without a response body. Existing GET functionality remains unchanged, and error responses follow the same behavior.

Summary by CodeRabbit

  • Bug Fixes
    • Properly support HTTP HEAD requests: responses now include correct headers and content-length but omit the response body, improving protocol behavior while preserving existing GET responses.

@coderabbitai

coderabbitai Bot commented Apr 1, 2026

Copy link
Copy Markdown

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 158230da-f6b4-478d-b7d2-32cdc53062d0

📥 Commits

Reviewing files that changed from the base of the PR and between f1b7d1f and 6b769e5.

📒 Files selected for processing (1)
  • src/main/java/org/example/StaticFileHandler.java
🚧 Files skipped from review as they are similar to previous changes (1)
  • src/main/java/org/example/StaticFileHandler.java

📝 Walkthrough

Walkthrough

ConnectionHandler now dispatches HEAD requests to a new StaticFileHandler.sendHeadRequest(...); other methods continue to use sendGetRequest(...). sendHeadRequest builds headers (including Content-Length) but writes an empty body per HTTP HEAD semantics.

Changes

Cohort / File(s) Summary
Request routing logic
src/main/java/org/example/ConnectionHandler.java
Add conditional: if request.getMethod() is HEAD (case-insensitive) call sendHeadRequest(outputStream, uri), otherwise call existing sendGetRequest(...). No other control-flow or public API changes.
HEAD request handler
src/main/java/org/example/StaticFileHandler.java
Add public sendHeadRequest(OutputStream outputStream, String uri) that reuses handleGetRequest(uri) to determine status, headers and Content-Length, then writes headers with an empty body (new byte[0]) and flushes.

Sequence Diagram

sequenceDiagram
    actor Client
    participant ConnectionHandler
    participant StaticFileHandler

    Client->>ConnectionHandler: HTTP HEAD /file.txt
    ConnectionHandler->>ConnectionHandler: Evaluate request.getMethod()
    alt Method is HEAD
        ConnectionHandler->>StaticFileHandler: sendHeadRequest(outputStream, uri)
        StaticFileHandler->>StaticFileHandler: handleGetRequest(uri)
        StaticFileHandler->>StaticFileHandler: Build response headers (incl. Content-Length)
        StaticFileHandler-->>Client: Send headers only (empty body)
    else Method is GET (or other)
        ConnectionHandler->>StaticFileHandler: sendGetRequest(outputStream, uri)
        StaticFileHandler->>StaticFileHandler: handleGetRequest(uri)
        StaticFileHandler->>StaticFileHandler: Build headers + body
        StaticFileHandler-->>Client: Send headers + file content
    end
Loading

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~8 minutes

Poem

🐰 A quiet hop, a header's song,
I counted bytes — but not for long.
I send the signs, the tale's complete,
No heavy load upon my feet.
Head first, body rests — hooray! 🎉

🚥 Pre-merge checks | ✅ 2 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 25.00% 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 title 'Issue #109: Add HTTP HEAD support' directly and clearly describes the main change: adding HTTP HEAD method support, which matches the changeset that implements HEAD request handling in ConnectionHandler and StaticFileHandler.

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

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch feature/109-support-http-head
⚔️ Resolve merge conflicts
  • Resolve merge conflict in branch feature/109-support-http-head

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.

@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: 1

🤖 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/example/StaticFileHandler.java`:
- Around line 69-78: sendHeadRequest currently calls handleGetRequest(uri) then
sets an empty body, which makes HttpResponseBuilder compute Content-Length: 0;
instead, after handleGetRequest(uri) use the computed fileBytes length to set
the Content-Length header on the HttpResponseBuilder before suppressing the body
(e.g., response.setHeader("Content-Length", String.valueOf(fileBytes.length)) or
response.setContentLength(fileBytes.length) if available), then
setStatusCode(statusCode), setContentTypeFromFilename(uri), setBody(new byte[0])
and write the response so the HEAD response advertises the same Content-Length a
GET would return.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 0c570eff-f22f-459f-9997-b391714ab6f0

📥 Commits

Reviewing files that changed from the base of the PR and between c473d5b and f1b7d1f.

📒 Files selected for processing (2)
  • src/main/java/org/example/ConnectionHandler.java
  • src/main/java/org/example/StaticFileHandler.java

Comment thread src/main/java/org/example/StaticFileHandler.java
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