示例#1
0
        public static void PopulateObjectMetadata(HttpWebResponse response, ObjectMetadata metadata)
        {
            var ignoredHeaders = new HashSet <string> {
                Headers.DATE,
                Headers.SERVER,
                Headers.REQUEST_ID,
                Headers.CONNECTION
            };

            foreach (string name in response.Headers.AllKeys)
            {
                if (name.StartsWith(Headers.KS3_USER_METADATA_PREFIX))
                {
                    string value = response.Headers[name];
                    string key   = name.Substring(Headers.KS3_USER_METADATA_PREFIX.Length);

                    metadata.SetUserMetaData(key, value);
                }
                else if (ignoredHeaders.Contains(name))
                {
                    // ignore...
                }
                else if (name.Equals(Headers.LAST_MODIFIED, StringComparison.OrdinalIgnoreCase))
                {
                    metadata.SetHeader(name, DateTime.Parse(response.Headers[name]));
                }
                else if (name.Equals(Headers.CONTENT_LENGTH, StringComparison.OrdinalIgnoreCase))
                {
                    metadata.SetHeader(name, long.Parse(response.Headers[name]));
                }
                else if (name.Equals(Headers.ETAG))
                {
                    metadata.SetHeader(name, RemoveQuotes(response.Headers[name]));
                }
                else
                {
                    metadata.SetHeader(name, response.Headers[name]);
                }
            }
        }