UNPKG

@aws-sdk/client-s3

Version:

AWS SDK for JavaScript S3 Client for Node.js, Browser and React Native

107 lines 5.61 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.PutBucketCorsCommand = void 0; const models_0_1 = require("../models/models_0"); const Aws_restXml_1 = require("../protocols/Aws_restXml"); const middleware_apply_body_checksum_1 = require("@aws-sdk/middleware-apply-body-checksum"); const middleware_bucket_endpoint_1 = require("@aws-sdk/middleware-bucket-endpoint"); const middleware_serde_1 = require("@aws-sdk/middleware-serde"); const smithy_client_1 = require("@aws-sdk/smithy-client"); /** * <p>Sets the <code>cors</code> configuration for your bucket. If the configuration exists, * Amazon S3 replaces it.</p> * <p>To use this operation, you must be allowed to perform the <code>s3:PutBucketCORS</code> * action. By default, the bucket owner has this permission and can grant it to others.</p> * <p>You set this configuration on a bucket so that the bucket can service cross-origin * requests. For example, you might want to enable a request whose origin is * <code>http://www.example.com</code> to access your Amazon S3 bucket at * <code>my.example.bucket.com</code> by using the browser's <code>XMLHttpRequest</code> * capability.</p> * <p>To enable cross-origin resource sharing (CORS) on a bucket, you add the * <code>cors</code> subresource to the bucket. The <code>cors</code> subresource is an XML * document in which you configure rules that identify origins and the HTTP methods that can * be executed on your bucket. The document is limited to 64 KB in size. </p> * <p>When Amazon S3 receives a cross-origin request (or a pre-flight OPTIONS request) against a * bucket, it evaluates the <code>cors</code> configuration on the bucket and uses the first * <code>CORSRule</code> rule that matches the incoming browser request to enable a * cross-origin request. For a rule to match, the following conditions must be met:</p> * <ul> * <li> * <p>The request's <code>Origin</code> header must match <code>AllowedOrigin</code> * elements.</p> * </li> * <li> * <p>The request method (for example, GET, PUT, HEAD, and so on) or the * <code>Access-Control-Request-Method</code> header in case of a pre-flight * <code>OPTIONS</code> request must be one of the <code>AllowedMethod</code> * elements. </p> * </li> * <li> * <p>Every header specified in the <code>Access-Control-Request-Headers</code> request * header of a pre-flight request must match an <code>AllowedHeader</code> element. * </p> * </li> * </ul> * <p> For more information about CORS, go to <a href="https://docs.aws.amazon.com/AmazonS3/latest/dev/cors.html">Enabling * Cross-Origin Resource Sharing</a> in the <i>Amazon Simple Storage Service Developer Guide</i>.</p> * * <p class="title"> * <b>Related Resources</b> * </p> * <ul> * <li> * <p> * <a href="https://docs.aws.amazon.com/AmazonS3/latest/API/API_GetBucketCors.html">GetBucketCors</a> * </p> * </li> * <li> * <p> * <a href="https://docs.aws.amazon.com/AmazonS3/latest/API/API_DeleteBucketCors.html">DeleteBucketCors</a> * </p> * </li> * <li> * <p> * <a href="https://docs.aws.amazon.com/AmazonS3/latest/API/RESTOPTIONSobject.html">RESTOPTIONSobject</a> * </p> * </li> * </ul> */ class PutBucketCorsCommand extends smithy_client_1.Command { // Start section: command_properties // End section: command_properties constructor(input) { // Start section: command_constructor super(); this.input = input; // End section: command_constructor } /** * @internal */ resolveMiddleware(clientStack, configuration, options) { this.middlewareStack.use(middleware_serde_1.getSerdePlugin(configuration, this.serialize, this.deserialize)); this.middlewareStack.use(middleware_bucket_endpoint_1.getBucketEndpointPlugin(configuration)); this.middlewareStack.use(middleware_apply_body_checksum_1.getApplyMd5BodyChecksumPlugin(configuration)); const stack = clientStack.concat(this.middlewareStack); const { logger } = configuration; const clientName = "S3Client"; const commandName = "PutBucketCorsCommand"; const handlerExecutionContext = { logger, clientName, commandName, inputFilterSensitiveLog: models_0_1.PutBucketCorsRequest.filterSensitiveLog, outputFilterSensitiveLog: (output) => output, }; const { requestHandler } = configuration; return stack.resolve((request) => requestHandler.handle(request.request, options || {}), handlerExecutionContext); } serialize(input, context) { return Aws_restXml_1.serializeAws_restXmlPutBucketCorsCommand(input, context); } deserialize(output, context) { return Aws_restXml_1.deserializeAws_restXmlPutBucketCorsCommand(output, context); } } exports.PutBucketCorsCommand = PutBucketCorsCommand; //# sourceMappingURL=PutBucketCorsCommand.js.map