2017-02-07 21:33:23 +00:00
|
|
|
package restful
|
|
|
|
|
|
|
|
import "strings"
|
|
|
|
|
|
|
|
// Copyright 2013 Ernest Micklei. All rights reserved.
|
|
|
|
// Use of this source code is governed by a license
|
|
|
|
// that can be found in the LICENSE file.
|
|
|
|
|
|
|
|
// OPTIONSFilter is a filter function that inspects the Http Request for the OPTIONS method
|
|
|
|
// and provides the response with a set of allowed methods for the request URL Path.
|
2017-06-11 16:03:28 +00:00
|
|
|
// As for any filter, you can also install it for a particular WebService within a Container.
|
|
|
|
// Note: this filter is not needed when using CrossOriginResourceSharing (for CORS).
|
2017-02-07 21:33:23 +00:00
|
|
|
func (c *Container) OPTIONSFilter(req *Request, resp *Response, chain *FilterChain) {
|
|
|
|
if "OPTIONS" != req.Request.Method {
|
|
|
|
chain.ProcessFilter(req, resp)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
resp.AddHeader(HEADER_Allow, strings.Join(c.computeAllowedMethods(req), ","))
|
|
|
|
}
|
|
|
|
|
|
|
|
// OPTIONSFilter is a filter function that inspects the Http Request for the OPTIONS method
|
|
|
|
// and provides the response with a set of allowed methods for the request URL Path.
|
2017-06-11 16:03:28 +00:00
|
|
|
// Note: this filter is not needed when using CrossOriginResourceSharing (for CORS).
|
2017-02-07 21:33:23 +00:00
|
|
|
func OPTIONSFilter() FilterFunction {
|
|
|
|
return DefaultContainer.OPTIONSFilter
|
|
|
|
}
|