/*
Copyright The Kubernetes Authors.

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

    http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/

// Code generated by applyconfiguration-gen. DO NOT EDIT.

package v1

import (
	apisv1 "sigs.k8s.io/gateway-api/apis/v1"
)

// HTTPCORSFilterApplyConfiguration represents a declarative configuration of the HTTPCORSFilter type for use
// with apply.
//
// HTTPCORSFilter defines a filter that that configures Cross-Origin Request
// Sharing (CORS).
type HTTPCORSFilterApplyConfiguration struct {
	// AllowOrigins indicates whether the response can be shared with requested
	// resource from the given `Origin`.
	//
	// The `Origin` consists of a scheme and a host, with an optional port, and
	// takes the form `<scheme>://<host>(:<port>)`.
	//
	// Valid values for scheme are: `http` and `https`.
	//
	// Valid values for port are any integer between 1 and 65535 (the list of
	// available TCP/UDP ports). Note that, if not included, port `80` is
	// assumed for `http` scheme origins, and port `443` is assumed for `https`
	// origins. This may affect origin matching.
	//
	// The host part of the origin may contain the wildcard character `*`. These
	// wildcard characters behave as follows:
	//
	// * `*` is a greedy match to the _left_, including any number of
	// DNS labels to the left of its position. This also means that
	// `*` will include any number of period `.` characters to the
	// left of its position.
	// * A wildcard by itself matches all hosts.
	//
	// An origin value that includes _only_ the `*` character indicates requests
	// from all `Origin`s are allowed.
	//
	// When the `AllowOrigins` field is configured with multiple origins, it
	// means the server supports clients from multiple origins. If the request
	// `Origin` matches the configured allowed origins, the gateway must return
	// the given `Origin` and sets value of the header
	// `Access-Control-Allow-Origin` same as the `Origin` header provided by the
	// client.
	//
	// The status code of a successful response to a "preflight" request is
	// always an OK status (i.e., 204 or 200).
	//
	// If the request `Origin` does not match the configured allowed origins,
	// the gateway returns 204/200 response but doesn't set the relevant
	// cross-origin response headers. Alternatively, the gateway responds with
	// 403 status to the "preflight" request is denied, coupled with omitting
	// the CORS headers. The cross-origin request fails on the client side.
	// Therefore, the client doesn't attempt the actual cross-origin request.
	//
	// Conversely, if the request `Origin` matches one of the configured
	// allowed origins, the gateway sets the response header
	// `Access-Control-Allow-Origin` to the same value as the `Origin`
	// header provided by the client.
	//
	// When config has the wildcard ("*") in allowOrigins, and the request
	// is not credentialed (e.g., it is a preflight request), the
	// `Access-Control-Allow-Origin` response header either contains the
	// wildcard as well or the Origin from the request.
	//
	// When the request is credentialed, the gateway must not specify the `*`
	// wildcard in the `Access-Control-Allow-Origin` response header. When
	// also the `AllowCredentials` field is true and `AllowOrigins` field
	// specified with the `*` wildcard, the gateway must return a single origin
	// in the value of the `Access-Control-Allow-Origin` response header,
	// instead of specifying the `*` wildcard. The value of the header
	// `Access-Control-Allow-Origin` is same as the `Origin` header provided by
	// the client.
	//
	// Support: Extended
	AllowOrigins []apisv1.CORSOrigin `json:"allowOrigins,omitempty"`
	// AllowCredentials indicates whether the actual cross-origin request allows
	// to include credentials.
	//
	// When set to true, the gateway will include the `Access-Control-Allow-Credentials`
	// response header with value true (case-sensitive).
	//
	// When set to false or omitted the gateway will omit the header
	// `Access-Control-Allow-Credentials` entirely (this is the standard CORS
	// behavior).
	//
	// Support: Extended
	AllowCredentials *bool `json:"allowCredentials,omitempty"`
	// AllowMethods indicates which HTTP methods are supported for accessing the
	// requested resource.
	//
	// Valid values are any method defined by RFC9110, along with the special
	// value `*`, which represents all HTTP methods are allowed.
	//
	// Method names are case-sensitive, so these values are also case-sensitive.
	// (See https://www.rfc-editor.org/rfc/rfc2616#section-5.1.1)
	//
	// Multiple method names in the value of the `Access-Control-Allow-Methods`
	// response header are separated by a comma (",").
	//
	// A CORS-safelisted method is a method that is `GET`, `HEAD`, or `POST`.
	// (See https://fetch.spec.whatwg.org/#cors-safelisted-method) The
	// CORS-safelisted methods are always allowed, regardless of whether they
	// are specified in the `AllowMethods` field.
	//
	// When the `AllowMethods` field is configured with one or more methods, the
	// gateway must return the `Access-Control-Allow-Methods` response header
	// which value is present in the `AllowMethods` field.
	//
	// If the HTTP method of the `Access-Control-Request-Method` request header
	// is not included in the list of methods specified by the response header
	// `Access-Control-Allow-Methods`, it will present an error on the client
	// side.
	//
	// If config contains the wildcard "*" in allowMethods and the request is
	// not credentialed, the `Access-Control-Allow-Methods` response header
	// can either use the `*` wildcard or the value of
	// Access-Control-Request-Method from the request.
	//
	// When the request is credentialed, the gateway must not specify the `*`
	// wildcard in the `Access-Control-Allow-Methods` response header. When
	// also the `AllowCredentials` field is true and `AllowMethods` field
	// specified with the `*` wildcard, the gateway must specify one HTTP method
	// in the value of the Access-Control-Allow-Methods response header. The
	// value of the header `Access-Control-Allow-Methods` is same as the
	// `Access-Control-Request-Method` header provided by the client. If the
	// header `Access-Control-Request-Method` is not included in the request,
	// the gateway will omit the `Access-Control-Allow-Methods` response header,
	// instead of specifying the `*` wildcard.
	//
	// Support: Extended
	AllowMethods []apisv1.HTTPMethodWithWildcard `json:"allowMethods,omitempty"`
	// AllowHeaders indicates which HTTP request headers are supported for
	// accessing the requested resource.
	//
	// Header names are not case-sensitive.
	//
	// Multiple header names in the value of the `Access-Control-Allow-Headers`
	// response header are separated by a comma (",").
	//
	// When the `AllowHeaders` field is configured with one or more headers, the
	// gateway must return the `Access-Control-Allow-Headers` response header
	// which value is present in the `AllowHeaders` field.
	//
	// If any header name in the `Access-Control-Request-Headers` request header
	// is not included in the list of header names specified by the response
	// header `Access-Control-Allow-Headers`, it will present an error on the
	// client side.
	//
	// If any header name in the `Access-Control-Allow-Headers` response header
	// does not recognize by the client, it will also occur an error on the
	// client side.
	//
	// A wildcard indicates that the requests with all HTTP headers are allowed.
	// If config contains the wildcard "*" in allowHeaders and the request is
	// not credentialed, the `Access-Control-Allow-Headers` response header
	// can either use the `*` wildcard or the value of
	// Access-Control-Request-Headers from the request.
	//
	// When the request is credentialed, the gateway must not specify the `*`
	// wildcard in the `Access-Control-Allow-Headers` response header. When
	// also the `AllowCredentials` field is true and `AllowHeaders` field
	// is specified with the `*` wildcard, the gateway must specify one or more
	// HTTP headers in the value of the `Access-Control-Allow-Headers` response
	// header. The value of the header `Access-Control-Allow-Headers` is same as
	// the `Access-Control-Request-Headers` header provided by the client. If
	// the header `Access-Control-Request-Headers` is not included in the
	// request, the gateway will omit the `Access-Control-Allow-Headers`
	// response header, instead of specifying the `*` wildcard.
	//
	// Support: Extended
	AllowHeaders []apisv1.HTTPHeaderName `json:"allowHeaders,omitempty"`
	// ExposeHeaders indicates which HTTP response headers can be exposed
	// to client-side scripts in response to a cross-origin request.
	//
	// A CORS-safelisted response header is an HTTP header in a CORS response
	// that it is considered safe to expose to the client scripts.
	// The CORS-safelisted response headers include the following headers:
	// `Cache-Control`
	// `Content-Language`
	// `Content-Length`
	// `Content-Type`
	// `Expires`
	// `Last-Modified`
	// `Pragma`
	// (See https://fetch.spec.whatwg.org/#cors-safelisted-response-header-name)
	// The CORS-safelisted response headers are exposed to client by default.
	//
	// When an HTTP header name is specified using the `ExposeHeaders` field,
	// this additional header will be exposed as part of the response to the
	// client.
	//
	// Header names are not case-sensitive.
	//
	// Multiple header names in the value of the `Access-Control-Expose-Headers`
	// response header are separated by a comma (",").
	//
	// A wildcard indicates that the responses with all HTTP headers are exposed
	// to clients. The `Access-Control-Expose-Headers` response header can only
	// use `*` wildcard as value when the request is not credentialed.
	//
	// When the `exposeHeaders` config field contains the "*" wildcard and
	// the request is credentialed, the gateway cannot use the `*` wildcard in
	// the `Access-Control-Expose-Headers` response header.
	//
	// Support: Extended
	ExposeHeaders []apisv1.HTTPHeaderName `json:"exposeHeaders,omitempty"`
	// MaxAge indicates the duration (in seconds) for the client to cache the
	// results of a "preflight" request.
	//
	// The information provided by the `Access-Control-Allow-Methods` and
	// `Access-Control-Allow-Headers` response headers can be cached by the
	// client until the time specified by `Access-Control-Max-Age` elapses.
	//
	// The default value of `Access-Control-Max-Age` response header is 5
	// (seconds).
	//
	// When the `MaxAge` field is unspecified, the gateway sets the response
	// header "Access-Control-Max-Age: 5" by default.
	MaxAge *int32 `json:"maxAge,omitempty"`
}

// HTTPCORSFilterApplyConfiguration constructs a declarative configuration of the HTTPCORSFilter type for use with
// apply.
func HTTPCORSFilter() *HTTPCORSFilterApplyConfiguration {
	return &HTTPCORSFilterApplyConfiguration{}
}

// WithAllowOrigins adds the given value to the AllowOrigins field in the declarative configuration
// and returns the receiver, so that objects can be build by chaining "With" function invocations.
// If called multiple times, values provided by each call will be appended to the AllowOrigins field.
func (b *HTTPCORSFilterApplyConfiguration) WithAllowOrigins(values ...apisv1.CORSOrigin) *HTTPCORSFilterApplyConfiguration {
	for i := range values {
		b.AllowOrigins = append(b.AllowOrigins, values[i])
	}
	return b
}

// WithAllowCredentials sets the AllowCredentials field in the declarative configuration to the given value
// and returns the receiver, so that objects can be built by chaining "With" function invocations.
// If called multiple times, the AllowCredentials field is set to the value of the last call.
func (b *HTTPCORSFilterApplyConfiguration) WithAllowCredentials(value bool) *HTTPCORSFilterApplyConfiguration {
	b.AllowCredentials = &value
	return b
}

// WithAllowMethods adds the given value to the AllowMethods field in the declarative configuration
// and returns the receiver, so that objects can be build by chaining "With" function invocations.
// If called multiple times, values provided by each call will be appended to the AllowMethods field.
func (b *HTTPCORSFilterApplyConfiguration) WithAllowMethods(values ...apisv1.HTTPMethodWithWildcard) *HTTPCORSFilterApplyConfiguration {
	for i := range values {
		b.AllowMethods = append(b.AllowMethods, values[i])
	}
	return b
}

// WithAllowHeaders adds the given value to the AllowHeaders field in the declarative configuration
// and returns the receiver, so that objects can be build by chaining "With" function invocations.
// If called multiple times, values provided by each call will be appended to the AllowHeaders field.
func (b *HTTPCORSFilterApplyConfiguration) WithAllowHeaders(values ...apisv1.HTTPHeaderName) *HTTPCORSFilterApplyConfiguration {
	for i := range values {
		b.AllowHeaders = append(b.AllowHeaders, values[i])
	}
	return b
}

// WithExposeHeaders adds the given value to the ExposeHeaders field in the declarative configuration
// and returns the receiver, so that objects can be build by chaining "With" function invocations.
// If called multiple times, values provided by each call will be appended to the ExposeHeaders field.
func (b *HTTPCORSFilterApplyConfiguration) WithExposeHeaders(values ...apisv1.HTTPHeaderName) *HTTPCORSFilterApplyConfiguration {
	for i := range values {
		b.ExposeHeaders = append(b.ExposeHeaders, values[i])
	}
	return b
}

// WithMaxAge sets the MaxAge field in the declarative configuration to the given value
// and returns the receiver, so that objects can be built by chaining "With" function invocations.
// If called multiple times, the MaxAge field is set to the value of the last call.
func (b *HTTPCORSFilterApplyConfiguration) WithMaxAge(value int32) *HTTPCORSFilterApplyConfiguration {
	b.MaxAge = &value
	return b
}
