-
Notifications
You must be signed in to change notification settings - Fork 572
backend: Extract handleExternalProxy from createHeadlampHandler #4298
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
backend: Extract handleExternalProxy from createHeadlampHandler #4298
Conversation
|
[APPROVALNOTIFIER] This PR is NOT APPROVED This pull-request has been approved by: hxrshxz The full list of commands accepted by this bot can be found here. DetailsNeeds approval from an approver in each of these files:Approvers can indicate their approval by writing |
e8e0102 to
df27629
Compare
There was a problem hiding this comment.
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 refactors the createHeadlampHandler function by extracting the external proxy handler logic into a separate method called handleExternalProxy. The refactoring moves OAuth state management from local variables to struct fields and reduces the main handler function length by approximately 110 lines.
Key Changes:
- Extracted
/externalproxyhandler logic (~108 lines) into newhandleExternalProxymethod - Added
oauthRequestMapandoauthMufields toHeadlampConfigstruct for OAuth state management - Updated OIDC handlers to use struct-level fields instead of local variables
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
backend/cmd/headlamp.go
Outdated
| defer resp.Body.Close() | ||
|
|
Copilot
AI
Dec 20, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Duplicate defer statement for resp.Body.Close(). The response body is already deferred for closure at line 895. This second defer at line 929 is redundant and should be removed.
| defer resp.Body.Close() |
df27629 to
af01932
Compare
skoeva
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
could you adjust the commit message to match the PR title? take a look here for more info
af01932 to
57afc45
Compare
illume
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Seems there’s some tests failing.
To run them locally you can do:
make backend-test
f1f256e to
08668a2
Compare
2e0b8a9 to
d222047
Compare
d222047 to
e03d74e
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull request overview
Copilot reviewed 2 out of 2 changed files in this pull request and generated 7 comments.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
illume
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for this.
If you want to continue this:
- Please see the open review comments?
- Probably handleExternalProxy should be moved into a separate module?
|
hey @illume! moved the external proxy handler to a seperate pkg/externalproxy module as you suggested. also fixed all the copilot review comments while i was at it (variable shadowing, removed redundant timeout, added graceful shutdown for oauth cleanup, etc). all tests passing now 👍 |
5034e03 to
ec56aa6
Compare
|
The github tests weren't running for some reason. Closing the PR and opening it again got them running again. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull request overview
Copilot reviewed 4 out of 4 changed files in this pull request and generated 3 comments.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| // Use the parsed URL to avoid unused warning | ||
| _ = parsedURL.String() |
Copilot
AI
Feb 2, 2026
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This code appears to be working around a linter warning by artificially using parsedURL. The variable is parsed but never meaningfully used in the test logic. Consider removing both the parsing and this workaround since the test validates URL allowance through the HTTP response behavior, not by directly checking the parsed URL.
| // Initialize OAuth request map if not already initialized | ||
| if config.oauthRequestMap == nil { | ||
| config.oauthRequestMap = make(map[string]*OauthConfig) | ||
| } | ||
|
|
||
| return | ||
| } | ||
| // Initialize OAuth cleanup done channel if not already initialized | ||
| if config.oauthCleanupDone == nil { | ||
| config.oauthCleanupDone = make(chan struct{}) | ||
| } |
Copilot
AI
Feb 2, 2026
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The initialization logic for oauthRequestMap and oauthCleanupDone should be moved to a proper initialization function or constructor for HeadlampConfig rather than being placed inside the handler creation. This prevents the cleanup goroutine from being started multiple times if createHeadlampHandler is called more than once.
| // Start background goroutine to clean up expired OAuth entries (prevents unbounded memory growth) | ||
| go func() { |
Copilot
AI
Feb 2, 2026
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Starting this goroutine unconditionally in createHeadlampHandler means multiple goroutines could be created if the function is called multiple times. This creates a goroutine leak since there's no mechanism to stop previously started cleanup goroutines. The cleanup goroutine should be started once during config initialization, not during handler creation.
|
Thanks for this! I will come back to try it out and look in more detail. Could you please consider changing the git commit message to this?
|
…xternalproxy module
ec56aa6 to
f11b440
Compare
Summary
This PR refactors
createHeadlampHandlerby extracting the external proxy handler into a separate method, reducing function length and improving code maintainability.Related Issue
Fixes #3273 (partial)
Changes
/externalproxyhandler intohandleExternalProxymethod (~108 lines)oauthRequestMapandoauthMufields toHeadlampConfigstructcreateHeadlampHandlerfrom ~530 to ~420 linesSteps to Test
make backend-lintmake backend-testScreenshots (if applicable)
N/A - Backend refactoring only
Notes for the Reviewer
N/A