Skip to content

feat: add opt-in Precognition support to ParseRequest - #26

Merged
rluders merged 1 commit into
mainfrom
claude/magical-clarke-txavzp
Oct 23, 2026
Merged

rluders merged 1 commit into
mainfrom
claude/magical-clarke-txavzp

Conversation

@rluders

@rluders rluders commented Oct 23, 2026 •

Copy link
Copy Markdown
Owner

Closes #20

API

  • ParseOptions.Precognition bool — per-endpoint opt-in. When false, the header is ignored (request processed normally).
  • Client sends Precognition: true. IsPrecognitionRequest(r) exposes the check.
  • ErrPrecognitionHandled sentinel + IsPrecognitionHandled(err).

Behavior (opted-in + header)

Same pipeline as today (decode → bind path params → validate), then stop:

Outcome Response err
Valid 204 No Content, Precognition-Success: true ErrPrecognitionHandled
Validation failed 422, validator's ProblemDetails (extensions kept) validation error
Malformed / too large / bad path param unchanged 400 / 413 parse error

Opted-in endpoints also add Vary: Precognition.

Business logic can't run: a successful precognitive request returns a non-nil error, so the existing if err != nil { return } pattern stops the handler. No change for current callers.

Also

  • README section, and examples/restapi POST /users opts in.
  • Tests cover every row above, opt-out, ordinary request on opted-in endpoint, Vary header, header parsing, and that the validator's problem is not mutated.

go vet, go test -race ./..., validation/playground and examples tests pass locally.


Generated by Claude Code

Summary by CodeRabbit

  • New Features
    • Endpoints can opt in to request pre-validation. Matching requests receive a success response when validation passes, or a validation error when it fails, without continuing through normal request handling.
    • Added helpers to identify pre-validation requests and handled responses.
  • Documentation
    • Documented response behavior, request-inspection helpers, and the limits of pre-validation. Opted-in endpoints include the relevant Vary header; requests without the option continue through normal handling.

Endpoints enable ParseOptions.Precognition; requests with the
"Precognition: true" header run decoding, path binding and validation,
then stop: 204 No Content on success (ParseRequest returns
ErrPrecognitionHandled), 422 with the validator's problem on failure.
Parse errors keep their usual 400/413 responses.

Closes #20

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01FHBdej3KvFACHzafbEhw7C
@coderabbitai

coderabbitai Bot commented Oct 23, 2026

Copy link
Copy Markdown

Review in Change Stack →

Note

Currently processing new changes in this PR. This may take a few minutes, please wait...

⚙️ Run configuration
  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: defaults
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 735e304e-0359-492e-8e44-0cbaba492bb1
📥 Commits

Reviewing files that changed from the base of the PR and between 8afdf5a and 32c60ae.

📒 Files selected for processing: 7
  • README.md
  • examples/restapi/main.go
  • request.go
  • request_internal.go
  • request_precognition.go
  • request_precognition_test.go
  • request_types.go
+------------------------------------------------+
| I raised Series-B funding to review your code. |
+------------------------------------------------+
  \
   \   (\__/)
       (•ㅅ•)
       /   づ
✨ Finishing Touches
📝 Generate docstrings
  • Commit to this branch
  • Create a new PR
🧪 Generate unit tests (beta)
  • Commit to this branch
  • Create a new PR
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

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.

@codecov-commenter

Copy link
Copy Markdown

⚠️ Please install the 'codecov app svg image' to ensure uploads and comments are reliably processed by Codecov.

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 87.39%. Comparing base (8afdf5a) to head (32c60ae).
❗ Your organization needs to install the Codecov GitHub app to enable full functionality.

Additional details and impacted files
@@            Coverage Diff             @@
##             main      #26      +/-   ##
==========================================
+ Coverage   86.27%   87.39%   +1.11%     
==========================================
  Files          14       15       +1     
  Lines         583      603      +20     
==========================================
+ Hits          503      527      +24     
+ Misses         62       58       -4     
  Partials       18       18              

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@rluders
rluders merged commit d7497cc into main Oct 23, 2026
7 of 8 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.

Feature Request: Add Precognition Support for Pre-Validating Requests

3 participants