http/cors.go
func (s *CORSPreflight) ServeHTTP(w http.ResponseWriter, r *http.Request) {
	origin := HttpHeader_Origin().GetReader(r.Header)
	status := http.StatusBadRequest
	msg := ""
	defer func() {
		w.WriteHeader(status)
		w.Write([]byte(msg))
	}()

	if origin.Value != "" {
		if !s.PredicateOrigin(origin.Value) {
			status = http.StatusForbidden
			return
		}

		method := HttpHeader_AccessControlRequestMethod().
			GetReader(r.Header).Value
		header := strings.Split(
			HttpHeader_AccessControlRequestHeaders().
				GetReader(r.Header).Value, ", ")
		if len(header) == 1 && header[0] == "" {
			header = []string{}
		}

		if !raiqub.StringSlice(s.Methods).Exists(method) {
			msg = "Method not allowed"
			return
		}

		if len(s.Headers) == 0 {
			HttpHeader_AccessControlAllowHeaders().
				SetWriter(w.Header())
		} else {
			if len(header) > 0 &&
				!raiqub.StringSlice(s.Headers).ExistsAllIgnoreCase(header) {
				msg = "Header not allowed"
				return
			}
			HttpHeader_AccessControlAllowHeaders().
				SetValue(strings.Join(s.Headers, ", ")).
				SetWriter(w.Header())
		}

		HttpHeader_AccessControlAllowMethods().
			SetValue(strings.Join(s.Methods, ", ")).
			SetWriter(w.Header())
		HttpHeader_AccessControlAllowOrigin().
			SetValue(origin.Value).
			SetWriter(w.Header())
		HttpHeader_AccessControlAllowCredentials().
			SetValue(strconv.FormatBool(s.UseCredentials)).
			SetWriter(w.Header())
		// Optional
		HttpHeader_AccessControlMaxAge().
			SetValue(strconv.Itoa(int(DEFAULT_CORS_MAX_AGE))).
			SetWriter(w.Header())
		status = http.StatusOK
	} else {
		status = http.StatusNotFound
	}
}
func (s *CORSPreflight) ServeHTTP(w http.ResponseWriter, r *http.Request) {
	origin := HttpHeader_Origin().GetReader(r.Header)
	status := http.StatusBadRequest
	msg := ""
	defer func() {
		w.WriteHeader(status)
		w.Write([]byte(msg))
	}()

	if origin.Value != "" {
		if !s.PredicateOrigin(origin.Value) {
			status = http.StatusForbidden
			return
		}

		method := HttpHeader_AccessControlRequestMethod().
			GetReader(r.Header).Value
		header := strings.Split(
			HttpHeader_AccessControlRequestHeaders().
				GetReader(r.Header).Value, ", ")
		if len(header) == 1 && header[0] == "" {
			header = []string{}
		}

		if !raiqub.StringSlice(s.Methods).Exists(method) {
			msg = "Method not allowed"
			return
		}

		if len(s.Headers) == 0 {
			HttpHeader_AccessControlAllowHeaders().
				SetWriter(w.Header())
		} else {
			if len(header) > 0 &&
				!raiqub.StringSlice(s.Headers).ExistsAllIgnoreCase(header) {
				msg = "Header not allowed"
				return
			}
			HttpHeader_AccessControlAllowHeaders().
				SetValue(strings.Join(s.Headers, ", ")).
				SetWriter(w.Header())
		}

		HttpHeader_AccessControlAllowMethods().
			SetValue(strings.Join(s.Methods, ", ")).
			SetWriter(w.Header())
		HttpHeader_AccessControlAllowOrigin().
			SetValue(origin.Value).
			SetWriter(w.Header())
		HttpHeader_AccessControlAllowCredentials().
			SetValue(strconv.FormatBool(s.UseCredentials)).
			SetWriter(w.Header())
		// Optional
		HttpHeader_AccessControlMaxAge().
			SetValue(strconv.Itoa(int(DEFAULT_CORS_MAX_AGE))).
			SetWriter(w.Header())
		status = http.StatusOK
	} else {
		status = http.StatusNotFound
	}
}
func ( s * CORSPreflight ) ServeHTTP ( w http . ResponseWriter , r * http . Request ) { origin := HttpHeader_Origin ( ) . GetReader ( r . Header ) status := http . StatusBadRequest msg := " " defer func ( ) { w . WriteHeader ( status ) w . Write ( [ ] byte ( msg ) ) } ( ) if origin . Value != " " { if ! s . PredicateOrigin ( origin . Value ) { status = http . StatusForbidden return } method := HttpHeader_AccessControlRequestMethod ( ) . GetReader ( r . Header ) . Value header := strings . Split ( HttpHeader_AccessControlRequestHeaders ( ) . GetReader ( r . Header ) . Value , " " ) if len ( header ) == 1 && header [ 0 ] == " " { header = [ ] string { } } if ! raiqub . StringSlice ( s . Methods ) . Exists ( method ) { msg = " " return } if len ( s . Headers ) == 0 { HttpHeader_AccessControlAllowHeaders ( ) . SetWriter ( w . Header ( ) ) } else { if len ( header ) > 0 && ! raiqub . StringSlice ( s . Headers ) . ExistsAllIgnoreCase ( header ) { msg = " " return } HttpHeader_AccessControlAllowHeaders ( ) . SetValue ( strings . Join ( s . Headers , " " ) ) . SetWriter ( w . Header ( ) ) } HttpHeader_AccessControlAllowMethods ( ) . SetValue ( strings . Join ( s . Methods , " " ) ) . SetWriter ( w . Header ( ) ) HttpHeader_AccessControlAllowOrigin ( ) . SetValue ( origin . Value ) . SetWriter ( w . Header ( ) ) HttpHeader_AccessControlAllowCredentials ( ) . SetValue ( strconv . FormatBool ( s . UseCredentials ) ) . SetWriter ( w . Header ( ) ) // Optional HttpHeader_AccessControlMaxAge ( ) . SetValue ( strconv . Itoa ( int ( DEFAULT_CORS_MAX_AGE ) ) ) . SetWriter ( w . Header ( ) ) status = http . StatusOK } else { status = http . StatusNotFound } }
// ServeHTTP handle a pre-flight request.
ServeHTTP handle a pre - flight request .