Esempio n. 1
0
        internal void AddHeaders(HttpHeaders sourceHeaders)
        {
            Contract.Requires(sourceHeaders != null);
            Contract.Assert(this.parserStore == sourceHeaders.parserStore,
                            "Can only copy headers from an instance with the same header parsers.");

            if (sourceHeaders.headerStore == null)
            {
                return;
            }

            List <string> invalidHeaders = null;

            foreach (var header in sourceHeaders.headerStore)
            {
                // Only add header values if they're not already set on the message. Note that we don't merge
                // collections: If both the default headers and the message have set some values for a certain
                // header, then we don't try to merge the values.
                if ((headerStore == null) || (!headerStore.ContainsKey(header.Key)))
                {
                    HeaderStoreItemInfo sourceInfo = header.Value;

                    // If DefaultRequestHeaders values are copied to multiple messages, it is useful to parse these
                    // default header values only once. This is what we're doing here: By parsing raw headers in
                    // 'sourceHeaders' before copying values to our header store.
                    if (!sourceHeaders.ParseRawHeaderValues(header.Key, sourceInfo, false))
                    {
                        // If after trying to parse source header values no value is left (i.e. all values contain
                        // invalid newline chars), mark this header as 'to-be-deleted' and skip to the next header.
                        if (invalidHeaders == null)
                        {
                            invalidHeaders = new List <string>();
                        }

                        invalidHeaders.Add(header.Key);
                    }
                    else
                    {
                        AddHeaderInfo(header.Key, sourceInfo);
                    }
                }
            }

            if (invalidHeaders != null)
            {
                Contract.Assert(sourceHeaders.headerStore != null);
                foreach (string invalidHeader in invalidHeaders)
                {
                    sourceHeaders.headerStore.Remove(invalidHeader);
                }
            }
        }
 internal virtual void AddHeaders(HttpHeaders sourceHeaders)
 {
     if (sourceHeaders._headerStore == null)
     {
         return;
     }
     foreach (KeyValuePair <HeaderDescriptor, HttpHeaders.HeaderStoreItemInfo> keyValuePair in sourceHeaders._headerStore)
     {
         if (this._headerStore == null || !this._headerStore.ContainsKey(keyValuePair.Key))
         {
             HttpHeaders.HeaderStoreItemInfo headerStoreItemInfo = keyValuePair.Value;
             if (!sourceHeaders.ParseRawHeaderValues(keyValuePair.Key, headerStoreItemInfo, false))
             {
                 sourceHeaders._headerStore.Remove(keyValuePair.Key);
             }
             else
             {
                 this.AddHeaderInfo(keyValuePair.Key, headerStoreItemInfo);
             }
         }
     }
 }