mirror of
https://github.com/duanhf2012/origin.git
synced 2026-02-24 14:44:42 +08:00
提交httpservice支持设置跨域设置
This commit is contained in:
@@ -39,7 +39,6 @@ type HttpRequest struct {
|
|||||||
mapParam map[string]string
|
mapParam map[string]string
|
||||||
URL string
|
URL string
|
||||||
//Req http.Request
|
//Req http.Request
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
type HttpRespone struct {
|
type HttpRespone struct {
|
||||||
@@ -50,6 +49,7 @@ type HttpRespone struct {
|
|||||||
|
|
||||||
type ServeHTTPRouterMux struct {
|
type ServeHTTPRouterMux struct {
|
||||||
httpfiltrateList []HttpFiltrate
|
httpfiltrateList []HttpFiltrate
|
||||||
|
allowOrigin bool
|
||||||
}
|
}
|
||||||
type ControllerMapsType map[string]reflect.Value
|
type ControllerMapsType map[string]reflect.Value
|
||||||
|
|
||||||
@@ -195,12 +195,18 @@ func (slf *HttpServerService) OnInit() error {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (slf *ServeHTTPRouterMux) SetAlowOrigin(w http.ResponseWriter, r *http.Request) {
|
||||||
|
slf.allowOrigin = true
|
||||||
|
}
|
||||||
|
|
||||||
func (slf *ServeHTTPRouterMux) ServeHTTP(w http.ResponseWriter, r *http.Request) {
|
func (slf *ServeHTTPRouterMux) ServeHTTP(w http.ResponseWriter, r *http.Request) {
|
||||||
if origin := r.Header.Get("Origin"); origin != "" {
|
if slf.allowOrigin == true {
|
||||||
w.Header().Set("Access-Control-Allow-Origin", "*")
|
if origin := r.Header.Get("Origin"); origin != "" {
|
||||||
w.Header().Set("Access-Control-Allow-Methods", "POST, GET, OPTIONS, PUT, DELETE")
|
w.Header().Set("Access-Control-Allow-Origin", "*")
|
||||||
w.Header().Set("Access-Control-Allow-Headers",
|
w.Header().Set("Access-Control-Allow-Methods", "POST, GET, OPTIONS, PUT, DELETE")
|
||||||
"Action, Module") //有使用自定义头 需要这个,Action, Module是例子
|
w.Header().Set("Access-Control-Allow-Headers",
|
||||||
|
"Action, Module") //有使用自定义头 需要这个,Action, Module是例子
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if r.Method == "OPTIONS" {
|
if r.Method == "OPTIONS" {
|
||||||
|
|||||||
Reference in New Issue
Block a user