...
1 package restful
2
3 import "strings"
4
5
6
7
8
9
10
11
12
13 func (c *Container) OPTIONSFilter(req *Request, resp *Response, chain *FilterChain) {
14 if "OPTIONS" != req.Request.Method {
15 chain.ProcessFilter(req, resp)
16 return
17 }
18
19 archs := req.Request.Header.Get(HEADER_AccessControlRequestHeaders)
20 methods := strings.Join(c.computeAllowedMethods(req), ",")
21 origin := req.Request.Header.Get(HEADER_Origin)
22
23 resp.AddHeader(HEADER_Allow, methods)
24 resp.AddHeader(HEADER_AccessControlAllowOrigin, origin)
25 resp.AddHeader(HEADER_AccessControlAllowHeaders, archs)
26 resp.AddHeader(HEADER_AccessControlAllowMethods, methods)
27 }
28
29
30
31
32 func OPTIONSFilter() FilterFunction {
33 return DefaultContainer.OPTIONSFilter
34 }
35
View as plain text