Skip to content

feat: MustRegex, IsControl, HTTPNotFound, HTTPDetectContentType, HTTPMaxBytesReader - #31

Merged
Snider merged 1 commit into
mainfrom
feat/app-helpers
Nov 24, 2026
Merged

Snider merged 1 commit into
mainfrom
feat/app-helpers

Conversation

@Snider

@Snider Snider commented Nov 24, 2026 •

Copy link
Copy Markdown
Contributor

Helpers an app needs that core didn't have, found moving Pinku off the standard library:

Helper For
MustRegex package-level patterns (panics on a typo, like regexp.MustCompile)
IsControl keeping control characters out of file names
HTTPNotFound 404 replies
HTTPDetectContentType serving images by their bytes
HTTPMaxBytesReader capping request bodies (fails past the cap; LimitReader truncates)

Good/Bad/Ugly tests and an example each. Also passes natively on Windows.

🤖 Generated with Claude Code
Co-Authored-By: Virgil virgil@lethean.io

Summary by CodeRabbit

  • New Features
    • Added helpers for generating not-found responses, detecting content types and limiting the number of bytes read from a request body.
    • Added a helper to compile regular expressions that panics if the pattern is invalid.
    • Added a helper to identify Unicode control characters.

…MaxBytesReader

The helpers Pinku reached for and core didn't have, found moving it off the
standard library: a compile-once pattern, the control-character test for
safe file names, and the three net/http calls a small JSON API needs
(MaxBytesReader fails past its cap rather than truncating, unlike
LimitReader). Good/Bad/Ugly tests and an example each.

Co-Authored-By: Virgil <virgil@lethean.io>
@coderabbitai

coderabbitai Bot commented Nov 24, 2026 •

Copy link
Copy Markdown
Contributor

Explain Change →

Caution

Review failed

The pull request is closed.

Walkthrough

The pull request adds three HTTP wrappers, a regular-expression compilation helper, and a Unicode control-character helper. Examples and tests cover the added functions.

Changes: HTTP helpers

Layer / File(s) Summary
HTTP wrappers and validation
api.go, api_example_test.go, api_test.go
Adds wrappers for http.NotFound, http.DetectContentType, and http.MaxBytesReader. Examples and tests cover response status and body, MIME detection, and reads below, at, and above the byte limit.

Regular-expression helper

Layer / File(s) Summary
MustRegex compilation and validation
regexp.go, regexp_example_test.go, regexp_test.go
Adds MustRegex, which returns the compiled expression or panics with an error that includes the pattern and compile error. The example extracts a capture, and tests cover valid, invalid, and empty patterns.

Unicode helper

Layer / File(s) Summary
IsControl and validation
unicode.go, unicode_example_test.go, unicode_test.go
Adds IsControl, which delegates to unicode.IsControl. The example and tests check control characters and non-control runes.
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Warning

Billing warning: we have not been able to collect payment for this subscription for more than 72 hours. Please update the payment method or pay any pending invoices in Billing to avoid service interruption.

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

@Snider
Snider merged commit dc541b5 into main Nov 24, 2026
2 of 3 checks passed
@Snider
Snider deleted the feat/app-helpers branch November 24, 2026 13:53
@codecov

codecov Bot commented Nov 24, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.

📢 Thoughts on this report? Let us know!

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.

1 participant