http/cors.go
func (s *CORSMiddleware) Handle(next http.Handler) http.Handler {
	fn := func(w http.ResponseWriter, r *http.Request) {
		origin := HttpHeader_Origin().GetReader(r.Header)
		if r.Method != DEFAULT_CORS_PREFLIGHT_METHOD && origin.Value != "" {
			if !s.PredicateOrigin(origin.Value) {
				return
			}

			HttpHeader_AccessControlAllowOrigin().
				SetValue(origin.Value).
				SetWriter(w.Header())
			HttpHeader_AccessControlAllowCredentials().
				SetValue(strconv.FormatBool(s.UseCredentials)).
				SetWriter(w.Header())
			if len(s.Headers) > 0 {
				HttpHeader_AccessControlAllowHeaders().
					SetValue(strings.Join(s.Headers, ", ")).
					SetWriter(w.Header())
			} else {
				HttpHeader_AccessControlAllowHeaders().
					SetWriter(w.Header())
			}
		}
		next.ServeHTTP(w, r)
	}

	return http.HandlerFunc(fn)
}
func (s *CORSMiddleware) Handle(next http.Handler) http.Handler {
	fn := func(w http.ResponseWriter, r *http.Request) {
		origin := HttpHeader_Origin().GetReader(r.Header)
		if r.Method != DEFAULT_CORS_PREFLIGHT_METHOD && origin.Value != "" {
			if !s.PredicateOrigin(origin.Value) {
				return
			}

			HttpHeader_AccessControlAllowOrigin().
				SetValue(origin.Value).
				SetWriter(w.Header())
			HttpHeader_AccessControlAllowCredentials().
				SetValue(strconv.FormatBool(s.UseCredentials)).
				SetWriter(w.Header())
			if len(s.Headers) > 0 {
				HttpHeader_AccessControlAllowHeaders().
					SetValue(strings.Join(s.Headers, ", ")).
					SetWriter(w.Header())
			} else {
				HttpHeader_AccessControlAllowHeaders().
					SetWriter(w.Header())
			}
		}
		next.ServeHTTP(w, r)
	}

	return http.HandlerFunc(fn)
}
func ( s * CORSMiddleware ) Handle ( next http . Handler ) http . Handler { fn := func ( w http . ResponseWriter , r * http . Request ) { origin := HttpHeader_Origin ( ) . GetReader ( r . Header ) if r . Method != DEFAULT_CORS_PREFLIGHT_METHOD && origin . Value != " " { if ! s . PredicateOrigin ( origin . Value ) { return } HttpHeader_AccessControlAllowOrigin ( ) . SetValue ( origin . Value ) . SetWriter ( w . Header ( ) ) HttpHeader_AccessControlAllowCredentials ( ) . SetValue ( strconv . FormatBool ( s . UseCredentials ) ) . SetWriter ( w . Header ( ) ) if len ( s . Headers ) > 0 { HttpHeader_AccessControlAllowHeaders ( ) . SetValue ( strings . Join ( s . Headers , " " ) ) . SetWriter ( w . Header ( ) ) } else { HttpHeader_AccessControlAllowHeaders ( ) . SetWriter ( w . Header ( ) ) } } next . ServeHTTP ( w , r ) } return http . HandlerFunc ( fn ) }
// Handle is a HTTP handler for CORS-able API.
Handle is a HTTP handler for CORS - able API .