/// <summary> /// Populate the http headers according to the properties of this object. /// </summary> /// <param name="headers">The generated http headers</param> internal void Populate(IDictionary <string, string> headers) { if (ModifiedSinceConstraint != null) { headers.Add(OssHeaders.GetObjectIfModifiedSince, DateUtils.FormatRfc822Date(ModifiedSinceConstraint.Value)); } if (UnmodifiedSinceConstraint != null) { headers.Add(OssHeaders.GetObjectIfUnmodifiedSince, DateUtils.FormatRfc822Date(UnmodifiedSinceConstraint.Value)); } if (_matchingETagConstraints.Count > 0) { headers.Add(OssHeaders.GetObjectIfMatch, OssUtils.JoinETag(_matchingETagConstraints)); } if (_nonmatchingEtagConstraints.Count > 0) { headers.Add(OssHeaders.GetObjectIfNoneMatch, OssUtils.JoinETag(_nonmatchingEtagConstraints)); } if (RequestPayer == RequestPayer.Requester) { headers.Add(OssHeaders.OssRequestPayer, RequestPayer.Requester.ToString().ToLowerInvariant()); } }
internal void Populate(IDictionary <string, string> headers) { var copyHeaderValue = OssUtils.BuildCopyObjectSource(SourceBucketName, SourceKey); if (!string.IsNullOrEmpty(SourceVersionId)) { copyHeaderValue = copyHeaderValue + "?versionId=" + SourceVersionId; } headers.Add(OssHeaders.CopyObjectSource, copyHeaderValue); if (ModifiedSinceConstraint != null) { headers.Add(OssHeaders.CopySourceIfModifedSince, DateUtils.FormatRfc822Date(ModifiedSinceConstraint.Value)); } if (UnmodifiedSinceConstraint != null) { headers.Add(OssHeaders.CopySourceIfUnmodifiedSince, DateUtils.FormatRfc822Date(UnmodifiedSinceConstraint.Value)); } if (_matchingETagConstraints.Count > 0) { headers.Add(OssHeaders.CopySourceIfMatch, OssUtils.JoinETag(_matchingETagConstraints)); } if (_nonmatchingETagConstraints.Count > 0) { headers.Add(OssHeaders.CopySourceIfNoneMatch, OssUtils.JoinETag(_nonmatchingETagConstraints)); } if (NewObjectMetadata != null) { headers.Add(OssHeaders.CopyObjectMetaDataDirective, "REPLACE"); NewObjectMetadata.Populate(headers); } // Remove Content-Length header, ObjectMeta#Populate will create // ContentLength header, but we do not need it for the request body is empty. headers.Remove(HttpHeaders.ContentLength); if (RequestPayer == RequestPayer.Requester) { headers.Add(OssHeaders.OssRequestPayer, RequestPayer.Requester.ToString().ToLowerInvariant()); } if (TrafficLimit > 0) { headers.Add(OssHeaders.OssTrafficLimit, TrafficLimit.ToString()); } }
/// <summary> /// Populate the http headers according to the properties of this object. /// </summary> /// <param name="headers">The generated http headers</param> internal void Populate(IDictionary <string, string> headers) { if (Range != null && (Range[0] >= 0 || Range[1] >= 0)) { var rangeHeaderValue = new StringBuilder(); rangeHeaderValue.Append("bytes="); if (Range[0] >= 0) { rangeHeaderValue.Append(Range[0].ToString(CultureInfo.InvariantCulture)); } rangeHeaderValue.Append("-"); if (Range[1] >= 0) { rangeHeaderValue.Append(Range[1].ToString(CultureInfo.InvariantCulture)); } headers.Add(HttpHeaders.Range, rangeHeaderValue.ToString()); } if (ModifiedSinceConstraint != null) { headers.Add(OssHeaders.GetObjectIfModifiedSince, DateUtils.FormatRfc822Date(ModifiedSinceConstraint.Value)); } if (UnmodifiedSinceConstraint != null) { headers.Add(OssHeaders.GetObjectIfUnmodifiedSince, DateUtils.FormatRfc822Date(UnmodifiedSinceConstraint.Value)); } if (_matchingETagConstraints.Count > 0) { headers.Add(OssHeaders.GetObjectIfMatch, OssUtils.JoinETag(_matchingETagConstraints)); } if (_nonmatchingEtagConstraints.Count > 0) { headers.Add(OssHeaders.GetObjectIfNoneMatch, OssUtils.JoinETag(_nonmatchingEtagConstraints)); } if (RequestPayer == RequestPayer.Requester) { headers.Add(OssHeaders.OssRequestPayer, RequestPayer.Requester.ToString().ToLowerInvariant()); } if (TrafficLimit > 0) { headers.Add(OssHeaders.OssTrafficLimit, TrafficLimit.ToString()); } }
internal void Populate(IDictionary <string, string> headers) { var copyHeaderValue = OssUtils.BuildCopyObjectSource(SourceBucketName, SourceKey); headers.Add(OssHeaders.CopyObjectSource, copyHeaderValue); if (ModifiedSinceConstraint != null) { headers.Add(OssHeaders.CopySourceIfModifedSince, DateUtils.FormatRfc822Date(ModifiedSinceConstraint.Value)); } if (UnmodifiedSinceConstraint != null) { headers.Add(OssHeaders.CopySourceIfUnmodifiedSince, DateUtils.FormatRfc822Date(UnmodifiedSinceConstraint.Value)); } if (_matchingETagConstraints.Count > 0) { headers.Add(OssHeaders.CopySourceIfMatch, OssUtils.JoinETag(_matchingETagConstraints)); } if (_nonmatchingETagConstraints.Count > 0) { headers.Add(OssHeaders.CopySourceIfNoneMatch, OssUtils.JoinETag(_nonmatchingETagConstraints)); } if (NewObjectMetaData != null) { headers.Add(OssHeaders.CopyObjectMetaDataDirective, "REPLACE"); NewObjectMetaData.Populate(headers); } else if (NewObjectMetadata != null) { headers.Add(OssHeaders.CopyObjectMetaDataDirective, "REPLACE"); NewObjectMetadata.Populate(headers); } // Remove Content-Length header, ObjectMeta#Populate will create // ContentLength header, but we do not need it for the request body is empty. headers.Remove(HttpHeaders.ContentLength); }
/// <summary> /// Populate the http headers according to the properties of this object. /// </summary> /// <param name="headers">The generated http headers</param> internal void Populate(IDictionary <string, string> headers) { if (ModifiedSinceConstraint != null) { headers.Add(OssHeaders.GetObjectIfModifiedSince, DateUtils.FormatRfc822Date(ModifiedSinceConstraint.Value)); } if (UnmodifiedSinceConstraint != null) { headers.Add(OssHeaders.GetObjectIfUnmodifiedSince, DateUtils.FormatRfc822Date(UnmodifiedSinceConstraint.Value)); } if (_matchingETagConstraints.Count > 0) { headers.Add(OssHeaders.GetObjectIfMatch, OssUtils.JoinETag(_matchingETagConstraints)); } if (_nonmatchingEtagConstraints.Count > 0) { headers.Add(OssHeaders.GetObjectIfNoneMatch, OssUtils.JoinETag(_nonmatchingEtagConstraints)); } }
public void OssUtilsTest() { var conf = new ClientConfiguration(); Assert.AreEqual(OssUtils.IsBucketNameValid(""), false); var str = OssUtils.MakeResourcePath(new Uri("http://192.168.1.1"), "bucket", "key/abc/"); Assert.AreEqual(str, "bucket/key/abc/"); //cname conf.IsCname = true; var uri = OssUtils.MakeBucketEndpoint(new Uri("http://endpoint"), "bucket", conf); Assert.AreEqual(uri.ToString(), "http://endpoint/"); //ip endpoint & endpoint port conf.IsCname = false; uri = OssUtils.MakeBucketEndpoint(new Uri("http://192.168.1.1"), "bucket", conf); Assert.AreEqual(uri.ToString(), "http://192.168.1.1/"); uri = OssUtils.MakeBucketEndpoint(new Uri("http://192.168.1.1:3128"), "bucket", conf); Assert.AreEqual(uri.ToString(), "http://192.168.1.1:3128/"); //bucket conf.IsCname = false; uri = OssUtils.MakeBucketEndpoint(new Uri("http://endpoint"), null, conf); Assert.AreEqual(uri.ToString(), "http://endpoint/"); conf.IsCname = false; uri = OssUtils.MakeBucketEndpoint(new Uri("http://endpoint"), "bucket", conf); Assert.AreEqual(uri.ToString(), "http://bucket.endpoint/"); //TrimQuotes Assert.AreEqual(OssUtils.TrimQuotes("\"test\""), "test"); Assert.AreEqual(OssUtils.TrimQuotes("test\""), "test"); Assert.AreEqual(OssUtils.TrimQuotes("\"test"), "test"); Assert.AreEqual(OssUtils.TrimQuotes(null), null); //ComputeContentCrc64 var content = new MemoryStream(Encoding.ASCII.GetBytes("")); str = OssUtils.ComputeContentCrc64(content, 1); Assert.AreEqual(str, string.Empty); //JoinETag var etagList = new List <string>(); etagList.Add("etag1"); etagList.Add("etag2"); str = OssUtils.JoinETag(etagList); Assert.AreEqual(str, "etag1, etag2"); //GetResourcePathFromSignedUrl str = OssUtils.GetResourcePathFromSignedUrl(new Uri("http://endpoint/key")); Assert.AreEqual(str, "key"); str = OssUtils.GetResourcePathFromSignedUrl(new Uri("http://endpoint")); Assert.AreEqual(str, ""); //GetParametersFromSignedUrl }