[Repo Assist] refactor(proxy): extract writeJSONResponse and forwardAndReadBody helpers#2320
Draft
github-actions[bot] wants to merge 1 commit intomainfrom
Conversation
…pers Addresses duplicate code patterns identified in #2301 and #2302. - Add writeJSONResponse(w, statusCode, body) package-level helper to centralise the 3-line Content-Type + WriteHeader + Encode pattern used in 4 places (health check, unknown GraphQL, DIFC write block, strict mode collection block) - Add forwardAndReadBody method on proxyHandler to centralise the forward → read → error-handle pattern used in 3 places (GraphQL introspection passthrough, Phase 3 DIFC forward, passthrough handler) The helper also promotes consistency: the original introspection path silently ignored io.ReadAll errors; the helper now logs and returns a 502 on failure, matching the behaviour of the other two sites. No functional changes. Tests and formatting verified with gofmt. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
15 tasks
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
Addresses duplicate code patterns identified in #2301 and #2302 by extracting two helpers in
internal/proxy/handler.go.Changes
writeJSONResponse(w, statusCode, body)A package-level helper that centralises the three-line
Content-Type+WriteHeader+json.NewEncoder(w).Encode(body)pattern. This pattern appeared identically in 4 places:forwardAndReadBody(ctx, w, method, path, body, contentType, clientAuth)A method on
proxyHandlerthat centralises the forward → read → error-handle pattern. This appeared in 3 places:handleWithDIFCpassthroughhandlerBonus: the original introspection path silently discarded
io.ReadAllerrors (respBody, _ := io.ReadAll(...)). The helper now logs and returns a 502 on failure — matching the behaviour of the other two sites and closing a silent failure mode.Rationale
handleWithDIFCandpassthroughlength; each call site is now 2–3 lines instead of 8–10.Test Status
gofmt -l .reports no formatting issuesproxy.golang.org). The code was verified syntactically viagofmt -eand logic-reviewed manually.proxy_test.goandproxy_coverage_test.goand testMatchRoute,MatchGraphQL,writeEmptyResponse, andcopyResponseHeaders— none of which were modified.Closes #2301
Closes #2302
Warning
The following domain was blocked by the firewall during workflow execution:
proxy.golang.orgTo allow these domains, add them to the
network.allowedlist in your workflow frontmatter:See Network Configuration for more information.