Skip to content

chore: simplify, modernize (Go 1.26), update deps#139

Merged
rustatian merged 3 commits into
masterfrom
chore/cleanup-modernize-deps
Jun 3, 2026
Merged

chore: simplify, modernize (Go 1.26), update deps#139
rustatian merged 3 commits into
masterfrom
chore/cleanup-modernize-deps

Conversation

@rustatian

@rustatian rustatian commented May 29, 2026

Copy link
Copy Markdown
Member

Applied fixes

R/High plugin.go:201Header().Set(Content-Type) was called after w.Write, so the header was never sent. Moved before the write loop.

R/Med plugin.go:186buf = buf[:n] permanently shrunk the loop buffer on each iteration, degrading multi-chunk reads of large files. Added buf = buf[:cap(buf)] before ReadAt each iteration.

R/Low plugin.go:136 — Hardened path-traversal check: strings.Contains(path, "..") had false positives/negatives; replaced with strings.Contains(filepath.Clean(path), "..").

S/Med plugin.go:99Header().Get(xSendHeader) was called twice (lines 99 and 121). Captured once at the top of the decision block.

S/Low plugin.go:99 — Duplicated nested header-copy loop in both branches; deduplicated (range over value, not index).

S/Low plugin.go:148os.OpenFile(path, os.O_RDONLY, 0)os.Open(path).

S/Low plugin.go:154defer func() { _ = f.Close() }()defer f.Close().

S/Low plugin.go:170 — Removed goto out; restructured EOF path into a straightforward if block.

M/Low plugin.go:159 — Buffer allocation: if/else for small/large → make([]byte, min(size, int64(bufSize))).

M/Low plugin.go:217for k := range w.hdrToSend { delete(...) }clear(w.hdrToSend).

M/Low plugin.go:214w.data = make([]byte, 0, 10) in putWriter discards backing array → w.data = w.data[:0].

Dependencies

go get -u all && go mod tidy — updated indirect dependencies.

- Move Content-Type Set before the write loop (was after Write, so headers were never sent)
- Re-slice buf to full cap each iteration so multi-chunk reads work correctly
- Capture Header().Get(xSendHeader) once; eliminate duplicated header-copy loop
- Replace os.OpenFile(O_RDONLY,0) with os.Open; simplify defer f.Close()
- Use min() for buffer allocation; clear(w.hdrToSend); w.data[:0] in putWriter
- Restructure EOF handling to remove goto; shadow-free Flusher variable (fl)
- Harden path-traversal check with filepath.Clean
- Update all dependencies
Copilot AI review requested due to automatic review settings May 29, 2026 12:43
@coderabbitai

coderabbitai Bot commented May 29, 2026

Copy link
Copy Markdown

Warning

Review limit reached

@rustatian, we couldn't start this review because you've reached your PR review rate limit.

More reviews will be available in 25 minutes and 4 seconds. Learn how PR review limits work.

Your organization has run out of usage credits. Purchase more in the billing tab.

⌛ How to resolve this issue?

After more reviews become available, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

We recommend that you space out your commits to avoid hitting the rate limit.

🚦 How do rate limits work?

CodeRabbit enforces hourly rate limits for each developer per organization.

Our paid plans include higher PR review limits than trial, open-source, and free plans. In all cases, reviews become available again over time. During sustained high-volume PR review activity, CodeRabbit may temporarily slow when the next review becomes available.

Please see our Fair Usage Limits Policy for further information.

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: c722fc2f-4e9d-40ed-8e4b-9960aff99c17

📥 Commits

Reviewing files that changed from the base of the PR and between b2ea005 and 46ffc06.

⛔ Files ignored due to path filters (1)
  • go.sum is excluded by !**/*.sum
📒 Files selected for processing (1)
  • plugin.go
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch chore/cleanup-modernize-deps

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.

Copilot AI 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.

Pull request overview

This PR modernizes the project to Go 1.26, simplifies the X-Sendfile middleware logic, and refreshes module dependencies. It primarily focuses on correctness/performance improvements in plugin.go’s sendfile path and some cleanup in pooled writer reuse.

Changes:

  • Refactored X-Sendfile handling to avoid duplicated header-copy logic and capture the sendfile path once.
  • Adjusted sendfile streaming to set headers before writing and improved buffer/write flow.
  • Updated indirect dependencies (go.sum) after go get -u all && go mod tidy.

Reviewed changes

Copilot reviewed 1 out of 2 changed files in this pull request and generated 3 comments.

File Description
plugin.go Refactors X-Sendfile flow, adjusts header handling timing, and updates the file streaming loop + writer pooling cleanup.
go.sum Dependency checksum updates from module upgrades/tidy.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread plugin.go Outdated
Comment thread plugin.go
Comment thread plugin.go Outdated
rustatian added 2 commits May 29, 2026 23:02
Deduplicate the two identical worker-header copy loops into a single helper,
which also removes the nested for-loops from the path=="" branch and the need
to silence the nestif linter.
…inal chunk

- filepath.Clean result is now stored in cleanPath and used for both
  the traversal check and all subsequent Stat/Open calls, so the
  validated path is always the one actually accessed.
- Empty files (size == 0) are now returned immediately with 200 OK;
  previously ReadAt on a zero-length buffer returned (0, nil) and the
  loop never advanced, spinning forever.
- On io.EOF with a final non-empty chunk, a write error now returns
  early (consistent with the mid-stream path) and the flusher is
  called after the last successful write.
@rustatian rustatian self-assigned this Jun 3, 2026
@rustatian rustatian merged commit a9b9ad7 into master Jun 3, 2026
5 checks passed
@rustatian rustatian deleted the chore/cleanup-modernize-deps branch June 3, 2026 15:26
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