Conversation
Replace two inline httputil.WriteJSONResponse 403 calls in handler.go with a package-level writeDIFCForbidden helper. This reduces duplication and makes future changes to the DIFC violation response shape easier (only one place to update). Closes #3053 Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Contributor
There was a problem hiding this comment.
Pull request overview
This PR refactors internal/proxy/handler.go to reduce duplicate DIFC 403 response handling by extracting a small helper function.
Changes:
- Added a private
writeDIFCForbidden(w, message)helper to centralize DIFC policy violation 403 JSON responses. - Replaced two duplicated inline
httputil.WriteJSONResponse(..., http.StatusForbidden, map[string]string{"message": ...})blocks with calls to the new helper.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
This was referenced Apr 3, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
🤖 This PR was created by Repo Assist, an automated AI assistant.
Summary
Extracts a
writeDIFCForbiddenpackage-level helper ininternal/proxy/handler.go, replacing two inlinehttputil.WriteJSONResponse403 calls that used an identicalmap[string]string{"message": ...}body shape.Problem
As identified in #3053,
handler.gohad two near-identical inline 403 response blocks for DIFC policy violations (Phase 2 write-blocked and Phase 5 strict-mode block). If the response shape for DIFC violations changes (e.g. adding acodefield), both call sites would need to be updated separately.Change
Added
writeDIFCForbidden(w http.ResponseWriter, message string)— a small private helper that centralises the DIFC 403 response — and replaced the two inline call sites with it.No behaviour change. The third 403 response in
handler.go(line ~71, GraphQL shape witherrors+datafields) uses a different body structure and is intentionally left as-is.Test Status
make agent-finishedcould not be run. The changes are:gofmtclean)Closes #3053