Request Redirection and the REST API
This section describes how to handle HTTP redirects using REST. For general information about Amazon S3 redirects, see Request Redirection and the REST API.
Redirects and HTTP User-Agents
Programs that use the Amazon S3 REST API should handle redirects either at the application layer or the HTTP layer. Many HTTP client libraries and user agents can be configured to correctly handle redirects automatically. However, many others have incorrect or incomplete redirect implementations.
Before relying on a library to fulfill the redirect requirement, test the following cases:
|1||Verify all HTTP request headers are correctly included in the redirected request (the second request after receiving a redirect) including HTTP standards such as Authorization and Date.|
|2||Verify non-GET redirects, such as PUT and DELETE, work correctly.|
|3||Verify large PUT requests follow redirects correctly.|
|4||Verify PUT requests follow redirects correctly if the 100-continue response takes a long time to arrive.|
HTTP user-agents that strictly conform to RFC2616 might require explicit confirmation before following a redirect when the HTTP request method is not GET or HEAD. It is generally safe to follow redirects generated by Amazon S3 automatically, as the system will only issue redirects to hosts within the amazonaws.com domain and the effect of the redirected request will be the same as the original request.
Redirects and 100-Continue
To simplify redirect handling, improve efficiencies, and avoid the costs associated with sending a redirected request body twice, configure your application to use 100-continues for PUT operations. When your application uses 100-continue, it does not send the request body until it receives an acknowledgement. If the message is rejected based on the headers, the body of the message is not sent. For more information about 100-continue, go to RFC 2616 Section 8.2.3
According to RFC 2616, when using
This section provides an example of client-server interaction using HTTP redirects and 100-continue.
Following is a sample PUT to the
PUT /nelson.txt HTTP/1.1 Host: quotes.s3.amazonaws.com Date: Mon, 15 Oct 2007 22:18:46 +0000 Content-Length: 6 Expect: 100-continue
Amazon S3 returns the following:
HTTP/1.1 307 Temporary Redirect Location: http://quotes.s3-4c25d83b.amazonaws.com/nelson.txt?rk=8d47490b Content-Type: application/xml Transfer-Encoding: chunked Date: Mon, 15 Oct 2007 22:18:46 GMT Server: AmazonS3 <?xml version="1.0" encoding="UTF-8"?> <Error> <Code>TemporaryRedirect</Code> <Message>Please re-send this request to the specified temporary endpoint. Continue to use the original request endpoint for future requests. </Message> <Endpoint>quotes.s3-4c25d83b.amazonaws.com</Endpoint> <Bucket>quotes</Bucket> </Error>
The client follows the redirect response and issues a new request to the
quotes.s3-4c25d83b.amazonaws.com temporary endpoint.
PUT /nelson.txt?rk=8d47490b HTTP/1.1 Host: quotes.s3-4c25d83b.amazonaws.com Date: Mon, 15 Oct 2007 22:18:46 +0000 Content-Length: 6 Expect: 100-continue
Amazon S3 returns a 100-continue indicating the client should proceed with sending the request body.
HTTP/1.1 100 Continue
The client sends the request body.
Amazon S3 returns the final response.
HTTP/1.1 200 OK Date: Mon, 15 Oct 2007 22:18:48 GMT ETag: "a2c8d6b872054293afd41061e93bc289" Content-Length: 0 Server: AmazonS3