<p>I am debugging some code in the Selenium-rc proxy server. It seems the culprit is the <code>HttpURLConnection</code> object, whose interface for getting at the HTTP headers does not cope with duplicate header names, such as:</p>

<pre><code>Set-Cookie: foo=foo; Path=/
Set-Cookie: bar=bar; Path=/
</code></pre>

<p>The way of getting at the headers through the <code>HttpURLConnection</code> (using <code>getHeaderField(int n)</code> and <code>getHeaderFieldKey(int n)</code>) seems to be causing my second cookie to be lost. My question is</p>

<ol>
<li>Is it true that <code>HttpURLConnection</code> itself can't cope with it, and</li>
<li>If so, is there a workaround to it?</li>
</ol>

Without actually having tried it (can't remember to have handled that topic myself), there's also getHeaderFields, inherited from
UrlConnection
. Does this do what you need?