Exemplo n.º 1
0
        internal AuthTypeEnum?NegotiateAuthType(string bucketName, bool async)
        {
            AuthTypeEnum?        authType = AuthTypeEnum.V2;
            GetApiVersionRequest request  = new GetApiVersionRequest();

            request.BucketName = bucketName;
            try
            {
                GetApiVersionResponse response = async ?  this.GetApiVersionAsync(request) : this.GetApiVersion(request);
                if (response.StatusCode == HttpStatusCode.OK)
                {
                    if ((response.Headers.ContainsKey(Constants.ObsApiHeader) &&
                         response.Headers[Constants.ObsApiHeader].CompareTo("3.0") >= 0) || (response.Headers.ContainsKey(Constants.ObsApiHeaderWithPrefix) &&
                                                                                             response.Headers[Constants.ObsApiHeaderWithPrefix].CompareTo("3.0") >= 0))
                    {
                        authType = AuthTypeEnum.OBS;
                    }
                }
            }
            catch (ObsException ex)
            {
                int statusCode = Convert.ToInt32(ex.StatusCode);
                if (statusCode <= 0 || statusCode == 404 || statusCode >= 500)
                {
                    throw ex;
                }

                if (LoggerMgr.IsInfoEnabled)
                {
                    string msg = string.IsNullOrEmpty(bucketName) ? "The target server doesnot support OBS protocol, use S3 protocol" : string.Format("The target server doesnot support OBS protocol, use S3 protocol, Bucket:{0}", bucketName);
                    LoggerMgr.Info(msg, ex);
                }
            }

            return(authType);
        }
Exemplo n.º 2
0
 internal GetApiVersionResponse GetApiVersion(GetApiVersionRequest request)
 {
     return(this.DoRequest <GetApiVersionRequest, GetApiVersionResponse>(request));
 }
 internal GetApiVersionResponse GetApiVersionAsync(GetApiVersionRequest request)
 {
     return(this.EndDoRequest <GetApiVersionRequest, GetApiVersionResponse>(this.BeginDoRequest <GetApiVersionRequest>(request, null, null)));
 }