MCPcopy
hub / github.com/minio/minio-go / makeTargetURL

Method makeTargetURL

api.go:1040–1115  ·  view source on GitHub ↗

makeTargetURL make a new target url.

(bucketName, objectName, bucketLocation string, isVirtualHostStyle bool, queryValues url.Values)

Source from the content-addressed store, hash-verified

1038
1039// makeTargetURL make a new target url.
1040func (c *Client) makeTargetURL(bucketName, objectName, bucketLocation string, isVirtualHostStyle bool, queryValues url.Values) (*url.URL, error) {
1041 host := c.endpointURL.Host
1042 // For Amazon S3 endpoint, try to fetch location based endpoint.
1043 if s3utils.IsAmazonEndpoint(*c.endpointURL) {
1044 if c.s3AccelerateEndpoint != "" && bucketName != "" {
1045 // http://docs.aws.amazon.com/AmazonS3/latest/dev/transfer-acceleration.html
1046 // Disable transfer acceleration for non-compliant bucket names.
1047 if strings.Contains(bucketName, ".") {
1048 return nil, errTransferAccelerationBucket(bucketName)
1049 }
1050 // If transfer acceleration is requested set new host.
1051 // For more details about enabling transfer acceleration read here.
1052 // http://docs.aws.amazon.com/AmazonS3/latest/dev/transfer-acceleration.html
1053 host = c.s3AccelerateEndpoint
1054 } else {
1055 // Do not change the host if the endpoint URL is a FIPS S3 endpoint or a S3 PrivateLink interface endpoint
1056 if !s3utils.IsAmazonFIPSEndpoint(*c.endpointURL) && !s3utils.IsAmazonPrivateLinkEndpoint(*c.endpointURL) {
1057 if s3utils.IsAmazonExpressRegionalEndpoint(*c.endpointURL) {
1058 if bucketName == "" {
1059 host = getS3ExpressEndpoint(bucketLocation, false)
1060 } else {
1061 // Fetch new host based on the bucket location.
1062 host = getS3ExpressEndpoint(bucketLocation, s3utils.IsS3ExpressBucket(bucketName))
1063 }
1064 } else {
1065 // Fetch new host based on the bucket location.
1066 host = getS3Endpoint(bucketLocation, c.s3DualstackEnabled)
1067 }
1068 }
1069 }
1070 }
1071
1072 // Save scheme.
1073 scheme := c.endpointURL.Scheme
1074
1075 // Strip port 80 and 443 so we won't send these ports in Host header.
1076 // The reason is that browsers and curl automatically remove :80 and :443
1077 // with the generated presigned urls, then a signature mismatch error.
1078 if h, p, err := net.SplitHostPort(host); err == nil {
1079 if scheme == "http" && p == "80" || scheme == "https" && p == "443" {
1080 host = h
1081 if ip := net.ParseIP(h); ip != nil && ip.To4() == nil {
1082 host = "[" + h + "]"
1083 }
1084 }
1085 }
1086
1087 urlStr := scheme + "://" + host + "/"
1088
1089 // Make URL only if bucketName is available, otherwise use the
1090 // endpoint URL.
1091 if bucketName != "" {
1092 // If endpoint supports virtual host style use that always.
1093 // Currently only S3 and Google Cloud Storage would support
1094 // virtual host style.
1095 if isVirtualHostStyle {
1096 urlStr = scheme + "://" + bucketName + "." + host + "/"
1097 if objectName != "" {

Callers 3

newRequestMethod · 0.95
PresignedPostPolicyMethod · 0.95
TestMakeTargetURLFunction · 0.80

Calls 11

IsAmazonEndpointFunction · 0.92
IsAmazonFIPSEndpointFunction · 0.92
IsS3ExpressBucketFunction · 0.92
EncodePathFunction · 0.92
QueryEncodeFunction · 0.92
getS3ExpressEndpointFunction · 0.85
getS3EndpointFunction · 0.85
ContainsMethod · 0.45

Tested by 1

TestMakeTargetURLFunction · 0.64