Skip to content

Commit 20c3ffd

Browse files
committed
commit cors package
Signed-off-by: Callum Styan <callumstyan@gmail.com>
1 parent 8b21d0c commit 20c3ffd

File tree

1 file changed

+21
-0
lines changed

1 file changed

+21
-0
lines changed

coderd/workspaceapps/cors/cors.go

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
package cors
2+
3+
import (
4+
"context"
5+
6+
"github.com/coder/coder/v2/codersdk"
7+
)
8+
9+
type contextKeyBehavior struct{}
10+
11+
// WithBehavior sets the CORS behavior for the given context.
12+
func WithBehavior(ctx context.Context, behavior codersdk.CORSBehavior) context.Context {
13+
return context.WithValue(ctx, contextKeyBehavior{}, behavior)
14+
}
15+
16+
// HasBehavior returns true if the given context has the specified CORS behavior.
17+
func HasBehavior(ctx context.Context, behavior codersdk.CORSBehavior) bool {
18+
val := ctx.Value(contextKeyBehavior{})
19+
b, ok := val.(codersdk.CORSBehavior)
20+
return ok && b == behavior
21+
}

0 commit comments

Comments
 (0)