- Notifications
You must be signed in to change notification settings - Fork1.1k
feat: add MCP HTTP server experiment and improve experiment middleware#18712
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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.
Already on GitHub?Sign in to your account
Uh oh!
There was an error while loading.Please reload this page.
Changes fromall commits
File filter
Filter by extension
Conversations
Uh oh!
There was an error while loading.Please reload this page.
Jump to
Uh oh!
There was an error while loading.Please reload this page.
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more abouthow customized files appear on GitHub.
Uh oh!
There was an error while loading.Please reload this page.
Some generated files are not rendered by default. Learn more abouthow customized files appear on GitHub.
Uh oh!
There was an error while loading.Please reload this page.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -3,21 +3,59 @@ package httpmw | ||
| import ( | ||
| "fmt" | ||
| "net/http" | ||
| "strings" | ||
| "github.com/coder/coder/v2/buildinfo" | ||
| "github.com/coder/coder/v2/coderd/httpapi" | ||
| "github.com/coder/coder/v2/codersdk" | ||
| ) | ||
| // RequireExperiment returns middleware that checks if all required experiments are enabled. | ||
| // If any experiment is disabled, it returns a 403 Forbidden response with details about the missing experiments. | ||
| funcRequireExperiment(experiments codersdk.Experiments,requiredExperiments...codersdk.Experiment)func(next http.Handler) http.Handler { | ||
| returnfunc(next http.Handler) http.Handler { | ||
| returnhttp.HandlerFunc(func(w http.ResponseWriter,r*http.Request) { | ||
| for_,experiment:=rangerequiredExperiments { | ||
| if!experiments.Enabled(experiment) { | ||
| varexperimentNames []string | ||
| for_,exp:=rangerequiredExperiments { | ||
| experimentNames=append(experimentNames,string(exp)) | ||
| } | ||
| // Print a message that includes the experiment names | ||
| // even if some experiments are already enabled. | ||
| varmessagestring | ||
| iflen(requiredExperiments)==1 { | ||
| message=fmt.Sprintf("%s functionality requires enabling the '%s' experiment.", | ||
| requiredExperiments[0].DisplayName(),requiredExperiments[0]) | ||
| }else { | ||
| message=fmt.Sprintf("This functionality requires enabling the following experiments: %s", | ||
| strings.Join(experimentNames,", ")) | ||
| } | ||
| httpapi.Write(r.Context(),w,http.StatusForbidden, codersdk.Response{ | ||
| Message:message, | ||
| }) | ||
| return | ||
| } | ||
| } | ||
| next.ServeHTTP(w,r) | ||
| }) | ||
| } | ||
| } | ||
| // RequireExperimentWithDevBypass checks if ALL the given experiments are enabled, | ||
| // but bypasses the check in development mode (buildinfo.IsDev()). | ||
| funcRequireExperimentWithDevBypass(experiments codersdk.Experiments,requiredExperiments...codersdk.Experiment)func(next http.Handler) http.Handler { | ||
| returnfunc(next http.Handler) http.Handler { | ||
| returnhttp.HandlerFunc(func(w http.ResponseWriter,r*http.Request) { | ||
| ifbuildinfo.IsDev() { | ||
| next.ServeHTTP(w,r) | ||
| return | ||
| } | ||
| RequireExperiment(experiments,requiredExperiments...)(next).ServeHTTP(w,r) | ||
| }) | ||
| } | ||
| } | ||
ThomasK33 marked this conversation as resolved. Show resolvedHide resolvedUh oh!There was an error while loading.Please reload this page. | ||
Some generated files are not rendered by default. Learn more abouthow customized files appear on GitHub.
Uh oh!
There was an error while loading.Please reload this page.
Some generated files are not rendered by default. Learn more abouthow customized files appear on GitHub.
Uh oh!
There was an error while loading.Please reload this page.
Uh oh!
There was an error while loading.Please reload this page.