UNPKG

@aws-sdk/client-s3

Version:

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

111 lines 5.85 kB
import { __extends } from "tslib"; import { PutBucketCorsRequest } from "../models/models_0"; import { deserializeAws_restXmlPutBucketCorsCommand, serializeAws_restXmlPutBucketCorsCommand, } from "../protocols/Aws_restXml"; import { getApplyMd5BodyChecksumPlugin } from "@aws-sdk/middleware-apply-body-checksum"; import { getBucketEndpointPlugin } from "@aws-sdk/middleware-bucket-endpoint"; import { getSerdePlugin } from "@aws-sdk/middleware-serde"; import { Command as $Command } from "@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> */ var PutBucketCorsCommand = /** @class */ (function (_super) { __extends(PutBucketCorsCommand, _super); // Start section: command_properties // End section: command_properties function PutBucketCorsCommand(input) { var _this = // Start section: command_constructor _super.call(this) || this; _this.input = input; return _this; // End section: command_constructor } /** * @internal */ PutBucketCorsCommand.prototype.resolveMiddleware = function (clientStack, configuration, options) { this.middlewareStack.use(getSerdePlugin(configuration, this.serialize, this.deserialize)); this.middlewareStack.use(getBucketEndpointPlugin(configuration)); this.middlewareStack.use(getApplyMd5BodyChecksumPlugin(configuration)); var stack = clientStack.concat(this.middlewareStack); var logger = configuration.logger; var clientName = "S3Client"; var commandName = "PutBucketCorsCommand"; var handlerExecutionContext = { logger: logger, clientName: clientName, commandName: commandName, inputFilterSensitiveLog: PutBucketCorsRequest.filterSensitiveLog, outputFilterSensitiveLog: function (output) { return output; }, }; var requestHandler = configuration.requestHandler; return stack.resolve(function (request) { return requestHandler.handle(request.request, options || {}); }, handlerExecutionContext); }; PutBucketCorsCommand.prototype.serialize = function (input, context) { return serializeAws_restXmlPutBucketCorsCommand(input, context); }; PutBucketCorsCommand.prototype.deserialize = function (output, context) { return deserializeAws_restXmlPutBucketCorsCommand(output, context); }; return PutBucketCorsCommand; }($Command)); export { PutBucketCorsCommand }; //# sourceMappingURL=PutBucketCorsCommand.js.map