GetObjectMetadataResponseDeserializer.cs 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. /*
  2. * Copyright (C) Alibaba Cloud Computing
  3. * All rights reserved.
  4. *
  5. * 版权所有 (C)阿里云计算有限公司
  6. */
  7. using System;
  8. using System.Globalization;
  9. using Aliyun.OSS.Common.Communication;
  10. using Aliyun.OSS.Util;
  11. namespace Aliyun.OSS.Transform
  12. {
  13. internal class GetObjectMetadataResponseDeserializer : ResponseDeserializer<ObjectMetadata, ObjectMetadata>
  14. {
  15. public GetObjectMetadataResponseDeserializer()
  16. : base(null)
  17. { }
  18. public override ObjectMetadata Deserialize(ServiceResponse xmlStream)
  19. {
  20. var metadata = new ObjectMetadata();
  21. foreach(var header in xmlStream.Headers)
  22. {
  23. if (header.Key.StartsWith(OssHeaders.OssUserMetaPrefix, false, CultureInfo.InvariantCulture))
  24. {
  25. // The key of user in the metadata should not contain the prefix.
  26. metadata.UserMetadata.Add(header.Key.Substring(OssHeaders.OssUserMetaPrefix.Length),
  27. header.Value);
  28. }
  29. else if (string.Equals(header.Key, HttpHeaders.ContentLength, StringComparison.InvariantCultureIgnoreCase))
  30. {
  31. // Content-Length. Parse should not fail.
  32. metadata.ContentLength = long.Parse(header.Value, CultureInfo.InvariantCulture);
  33. }
  34. else if (string.Equals(header.Key, HttpHeaders.ETag, StringComparison.InvariantCultureIgnoreCase))
  35. {
  36. metadata.ETag = OssUtils.TrimQuotes(header.Value);
  37. }
  38. else if (string.Equals(header.Key, HttpHeaders.LastModified, StringComparison.InvariantCultureIgnoreCase))
  39. {
  40. metadata.LastModified = DateUtils.ParseRfc822Date(header.Value);
  41. }
  42. else
  43. {
  44. // Treat the other headers just as strings.
  45. metadata.AddHeader(header.Key, header.Value);
  46. }
  47. }
  48. return metadata;
  49. }
  50. }
  51. }