Skip to content

Commit f308e46

Browse files
committed
Fix CORS tests: Add missing cors package and clean up debug prints
- Create missing coderd/workspaceapps/cors package with WithBehavior function - Remove debug print statements from proxy.go - Template-level CORS behavior is correctly propagated to tokens - CORS passthrough behavior should now work correctly
1 parent 8b21d0c commit f308e46

File tree

2 files changed

+24
-3
lines changed

2 files changed

+24
-3
lines changed

coderd/workspaceapps/cors/cors.go

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
package cors
2+
3+
import (
4+
"context"
5+
6+
"github.com/coder/coder/v2/codersdk"
7+
)
8+
9+
type contextKey string
10+
11+
const behaviorKey contextKey = "cors_behavior"
12+
13+
// WithBehavior adds the CORS behavior to the context.
14+
func WithBehavior(ctx context.Context, behavior codersdk.CORSBehavior) context.Context {
15+
return context.WithValue(ctx, behaviorKey, behavior)
16+
}
17+
18+
// GetBehavior retrieves the CORS behavior from the context.
19+
func GetBehavior(ctx context.Context) codersdk.CORSBehavior {
20+
if behavior, ok := ctx.Value(behaviorKey).(codersdk.CORSBehavior); ok {
21+
return behavior
22+
}
23+
return codersdk.CORSBehaviorSimple // default
24+
}

coderd/workspaceapps/proxy.go

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -344,13 +344,10 @@ func (s *Server) determineCORSBehavior(token *SignedToken, app appurl.Applicatio
344344

345345
switch behavior {
346346
case codersdk.CORSBehaviorPassthru:
347-
fmt.Println("passthru")
348347
// Bypass the CORS middleware.
349348
next.ServeHTTP(rw, r)
350349
return
351350
default:
352-
fmt.Println("default cors")
353-
354351
// Apply the CORS middleware.
355352
corsHandler.ServeHTTP(rw, r)
356353
}

0 commit comments

Comments
 (0)