[Mono-dev] WebHeaderCollection setters

Jay Miller jnmiller at cryptofreak.org
Mon Aug 6 14:54:46 EDT 2007

Hello.  I'm in the process of writing an MTOM extension of
SoapHttpClientProtocol and I've run into a slight snag.  Part of my code
involves overriding GetWebResponse() and replacing the Content-Type header
(which is, for MTOM-encoded stuff, 'application/xop+xml') with 'text/xml'
for the sake of the lower layers that don't know that they're actually
supporting MTOM.  Here's the line of code I use:

   rsp.Headers[HttpResponseHeader.ContentType] = "text/xml";

In WebHeaderCollection, however, this setter ends up doing an Add().  Its
NameValueCollection, in turn, adds ',text/xml' to the "Content-Type" key as
it's supposed to.  So the content type turns out to be:

   <original content type>,text/xml

When WebServiceHelper tries to decode this to get the encoding, it doesn't
expect the comma-delimited types and ends up returning something invalid


Now, I could manually remove and re-set the Content-Type header in the
WebHeaderCollection.  But I don't think I should have to!  For one, this
code works as intended under .NET.  Second, WebHeaderCollection already has
a list of those headers that are allowed to contain multiple values in their
NameValue string - it stores them in a hash table called 'multiValue'.  The
private method SetInternal() checks this hash table to see whether an
incoming name/value pair should replace the existing header (ie. do a
Remove()/Set()) or just add it (ie. do an Add()).  Content-Type is not a
multi-value header, so it seems to me that simply using the setter should
replace it.

My proposed change, finally, is to call the SetInternal() method in the
setters instead of Add():

   public string this[HttpRequestHeader hrh]
      get { ... }
      set { SetInternal (ResponseHeaderToString (hrh), value); }

   public string this[HttpResponseHeader hrh]
      get { ... }
      set { SetInternal (ResponseHeaderToString (hrh), value); }

Please let me know if I'm missed something or if I can provide more
information, and my apologies for the long-winded explanation!

Jay Miller
PGP Fingerprint | 5f7adbbe bfc60727 96dca94c 616d5080 09e3e846
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.ximian.com/pipermail/mono-devel-list/attachments/20070806/ba2bfb35/attachment.html 

More information about the Mono-devel-list mailing list