Please fill out the sections below to help us address your issue.
v1.10.38
go version)?go version go1.8.1 darwin/amd64
there is no code to detect if is NotModified error code while GetObject in s3 client
Setting IfModifiedSince when doing a GetObject request, make it return 304 code.
If you have have an runnable example, please include it.
you can fake this easy
Hi @cloudaice thanks for reaching out to us. In this case does your application receive an error from the GetObject API call? If you could include the error message it would help debug this issue.
Hi @cloudaice I used the following example to make an GetObject API call to for an object with IfModifiedSince set to get a 304 status back. In my example I am seeing a NotModfiied error code being returned in the err value. Are you not seeing this? If you could provide a debug output with the HTTP request and response values that would be helpful.
package main
import (
"context"
"flag"
"fmt"
"time"
"github.com/aws/aws-sdk-go/aws"
"github.com/aws/aws-sdk-go/aws/session"
"github.com/aws/aws-sdk-go/service/s3"
)
func main() {
var bucket, key string
var timeout time.Duration
flag.StringVar(&bucket, "b", "", "The `bucket` name.")
flag.StringVar(&key, "k", "", "Object `key` name.")
flag.DurationVar(&timeout, "d", 10*time.Second, "Upload `timeout`.")
flag.Parse()
sess := session.Must(session.NewSession())
svc := s3.New(sess, &aws.Config{
LogLevel: aws.LogLevel(aws.LogDebugWithHTTPBody),
})
ctx := context.Background()
if timeout > 0 {
ctx, _ = context.WithTimeout(ctx, timeout)
}
req, resp := svc.GetObjectRequest(&s3.GetObjectInput{
Bucket: aws.String(bucket),
Key: aws.String(key),
IfModifiedSince: aws.Time(time.Now().Add(-20 * time.Minute)),
})
req.SetContext(ctx)
req.HTTPRequest.Header.Add("Accept-Encoding", "application/x-gzip")
err := req.Send()
fmt.Println("Response:", resp)
fmt.Println("Error:", err)
}
Debug HTTP Output:
2017/09/15 10:06:45 DEBUG: Request s3/GetObject Details:
---[ REQUEST POST-SIGN ]-----------------------------
GET /somekey HTTP/1.1
Host: <bucket>.s3-us-west-2.amazonaws.com
User-Agent: aws-sdk-go/1.10.45 (go1.8.3; darwin; amd64)
Accept-Encoding: application/x-gzip
Authorization: AWS4-HMAC-SHA256 Credential=<keyID>/20170915/us-west-2/s3/aws4_request, SignedHeaders=accept-encoding;host;if-modified-since;x-amz-content-sha256;x-amz-date, Signature=<signature>
If-Modified-Since: Fri, 15 Sep 2017 16:46:45 GMT
X-Amz-Content-Sha256: <sha256>
X-Amz-Date: 20170915T170645Z
-----------------------------------------------------
2017/09/15 10:06:46 DEBUG: Response s3/GetObject Details:
---[ RESPONSE ]--------------------------------------
HTTP/1.1 304 Not Modified
Date: Fri, 15 Sep 2017 17:06:46 GMT
Etag: "1f6e74cd9c05ea97e186953ad620739b"
Last-Modified: Wed, 13 Sep 2017 18:55:32 GMT
Server: AmazonS3
X-Amz-Id-2: <hostID>
X-Amz-Meta-123: 123value
X-Amz-Meta-Abc: abcvalue
X-Amz-Request-Id: <requestID>
-----------------------------------------------------
2017/09/15 10:06:46
Output of resp, and err values
Response: {
Body: <nil>,
ETag: "\"1f6e74cd9c05ea97e186953ad620739b\"",
LastModified: 2017-09-13 18:55:32 +0000 UTC,
Metadata: {
Abc: "abcvalue",
123: "123value"
}
}
Error: NotModified: Not Modified
status code: 304, request id: <requestID>, host id:<hostID>=
Hi @cloudaice Are you still running into this issue? I've not been able to reproduce it locally my self. Let us know if you still are having issues. If you're able to create a sample that reproduces the issue please let us know and reopen the issue.
i know this is old but i just ran into this and this is still the case as of the latest sdk.
i think what @cloudaice meant by this is _not_ that the sdk doesn't return the error code but that an error code constant doesn't exist to compare against. there are others like s3.ErrCodeNoSuchKey, s3.ErrCodeNoSuchBucket, etc. but not an s3.ErrCodeNotModified
@jasdel The issue is, as a client how can we differentiate between different errors like it was a timeout or the object does not exist or the object has the same etag as passed in if-none-match etc. There should be proper error constants returned to compare against by the clients.
I just ran into this as well - s3.ErrCodeNotModifed = "notModified" does not exist - but it should.
Most helpful comment
i know this is old but i just ran into this and this is still the case as of the latest sdk.
i think what @cloudaice meant by this is _not_ that the sdk doesn't return the error code but that an error code constant doesn't exist to compare against. there are others like s3.ErrCodeNoSuchKey, s3.ErrCodeNoSuchBucket, etc. but not an s3.ErrCodeNotModified