@@ -74,11 +74,11 @@ func (a ResSetCORSAnn) Process(k store.K8s, annotations ...map[string]string) (e
7474 origin = "%[var(txn." + corsVarName + ")]"
7575 }
7676 a .parent .rules .Add (& rules.SetHdr {
77- HdrName : "Access-Control-Allow-Origin" ,
78- HdrFormat : origin ,
79- Response : true ,
80- CondTest : a .parent .acl ,
81- Cond : "if" ,
77+ HdrName : "Access-Control-Allow-Origin" ,
78+ HdrFormat : origin ,
79+ AfterResponse : true ,
80+ CondTest : a .parent .acl ,
81+ Cond : "if" ,
8282 })
8383 case "cors-allow-methods" :
8484 if a .parent .acl == "" {
@@ -96,23 +96,23 @@ func (a ResSetCORSAnn) Process(k store.K8s, annotations ...map[string]string) (e
9696 input = "\" " + strings .Join (methods , ", " ) + "\" "
9797 }
9898 a .parent .rules .Add (& rules.SetHdr {
99- HdrName : "Access-Control-Allow-Methods" ,
100- HdrFormat : input ,
101- Response : true ,
102- CondTest : a .parent .acl ,
103- Cond : "if" ,
99+ HdrName : "Access-Control-Allow-Methods" ,
100+ HdrFormat : input ,
101+ AfterResponse : true ,
102+ CondTest : a .parent .acl ,
103+ Cond : "if" ,
104104 })
105105 case "cors-allow-headers" :
106106 if a .parent .acl == "" {
107107 return
108108 }
109109 input = strings .Join (strings .Fields (input ), "" ) // strip spaces
110110 a .parent .rules .Add (rules.SetHdr {
111- HdrName : "Access-Control-Allow-Headers" ,
112- HdrFormat : "\" " + input + "\" " ,
113- Response : true ,
114- CondTest : a .parent .acl ,
115- Cond : "if" ,
111+ HdrName : "Access-Control-Allow-Headers" ,
112+ HdrFormat : "\" " + input + "\" " ,
113+ AfterResponse : true ,
114+ CondTest : a .parent .acl ,
115+ Cond : "if" ,
116116 })
117117 case "cors-max-age" :
118118 if a .parent .acl == "" {
@@ -128,22 +128,29 @@ func (a ResSetCORSAnn) Process(k store.K8s, annotations ...map[string]string) (e
128128 return fmt .Errorf ("invalid cors-max-age value %d" , maxage )
129129 }
130130 a .parent .rules .Add (& rules.SetHdr {
131- HdrName : "Access-Control-Max-Age" ,
132- HdrFormat : fmt .Sprintf ("\" %d\" " , maxage ),
133- Response : true ,
134- CondTest : a .parent .acl ,
135- Cond : "if" ,
131+ HdrName : "Access-Control-Max-Age" ,
132+ HdrFormat : fmt .Sprintf ("\" %d\" " , maxage ),
133+ AfterResponse : true ,
134+ CondTest : a .parent .acl ,
135+ Cond : "if" ,
136136 })
137137 case "cors-allow-credentials" :
138138 if a .parent .acl == "" || input != "true" {
139139 return
140140 }
141141 a .parent .rules .Add (& rules.SetHdr {
142- HdrName : "Access-Control-Allow-Credentials" ,
143- HdrFormat : "\" true\" " ,
144- Response : true ,
145- CondTest : a .parent .acl ,
146- Cond : "if" ,
142+ HdrName : "Access-Control-Allow-Credentials" ,
143+ HdrFormat : "\" true\" " ,
144+ AfterResponse : true ,
145+ CondTest : a .parent .acl ,
146+ Cond : "if" ,
147+ })
148+ case "cors-respond-to-options" :
149+ if a .parent .acl == "" || input != "true" {
150+ return
151+ }
152+ a .parent .rules .Add (& rules.ReqReturnStatus {
153+ StatusCode : 204 ,
147154 })
148155 default :
149156 err = fmt .Errorf ("unknown cors annotation '%s'" , a .name )
0 commit comments