<p dir="auto">Summary.</p>
<h2 dir="auto">Expected Result</h2>
<p dir="auto">That the library would automatically change the name of one of the headers in order to store it in response.headers, or have some alternative way to get response headers that allows for duplicate header names.</p>
<h2 dir="auto">Actual Result</h2>
<p dir="auto">Only one of the headers is shown, due to Python not allowing duplicat keys.</p>
<h2 dir="auto">Reproduction Steps</h2>
<div class="highlight highlight-source-python notranslate position-relative overflow-auto" dir="auto" data-snippet-clipboard-copy-content="import requests

# fetch some website that sends a response with multiple headers of the same name
response = requests.get(&quot;some url&quot;)
# {&quot;set-token&quot;: &quot;foo&quot;, &quot;set-token&quot;: &quot;baz&quot;}

# only shows one of the headers
response.headers
# {&quot;set-token&quot;: &quot;foo&quot;}"><pre class="notranslate"><span class="pl-k">import</span> <span class="pl-s1">requests</span>

<span class="pl-c"># fetch some website that sends a response with multiple headers of the same name</span>
<span class="pl-s1">response</span> <span class="pl-c1">=</span> <span class="pl-s1">requests</span>.<span class="pl-en">get</span>(<span class="pl-s">"some url"</span>)
<span class="pl-c"># {"set-token": "foo", "set-token": "baz"}</span>

<span class="pl-c"># only shows one of the headers</span>
<span class="pl-s1">response</span>.<span class="pl-s1">headers</span>
<span class="pl-c"># {"set-token": "foo"}</span></pre></div>
<h2 dir="auto">System Information</h2>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="{
  &quot;chardet&quot;: {
    &quot;version&quot;: null
  },
  &quot;charset_normalizer&quot;: {
    &quot;version&quot;: &quot;2.0.4&quot;
  },
  &quot;cryptography&quot;: {
    &quot;version&quot;: &quot;&quot;
  },
  &quot;idna&quot;: {
    &quot;version&quot;: &quot;3.2&quot;
  },
  &quot;implementation&quot;: {
    &quot;name&quot;: &quot;CPython&quot;,
    &quot;version&quot;: &quot;3.8.7&quot;
  },
  &quot;platform&quot;: {
    &quot;release&quot;: &quot;10&quot;,
    &quot;system&quot;: &quot;Windows&quot;
  },
  &quot;pyOpenSSL&quot;: {
    &quot;openssl_version&quot;: &quot;&quot;,
    &quot;version&quot;: null
  },
  &quot;requests&quot;: {
    &quot;version&quot;: &quot;2.26.0&quot;
  },
  &quot;system_ssl&quot;: {
    &quot;version&quot;: &quot;1010107f&quot;
  },
  &quot;urllib3&quot;: {
    &quot;version&quot;: &quot;1.26.6&quot;
  },
  &quot;using_charset_normalizer&quot;: true,
  &quot;using_pyopenssl&quot;: false
}"><pre class="notranslate"><code class="notranslate">{
  "chardet": {
    "version": null
  },
  "charset_normalizer": {
    "version": "2.0.4"
  },
  "cryptography": {
    "version": ""
  },
  "idna": {
    "version": "3.2"
  },
  "implementation": {
    "name": "CPython",
    "version": "3.8.7"
  },
  "platform": {
    "release": "10",
    "system": "Windows"
  },
  "pyOpenSSL": {
    "openssl_version": "",
    "version": null
  },
  "requests": {
    "version": "2.26.0"
  },
  "system_ssl": {
    "version": "1010107f"
  },
  "urllib3": {
    "version": "1.26.6"
  },
  "using_charset_normalizer": true,
  "using_pyopenssl": false
}
</code></pre></div>
<p dir="auto">When you send a request which replaces an existing cookie value with a new one and also returns a redirect response, when the new request is made, its request header from <code class="notranslate">r.request.headers['Cookies']</code> shows both the old and the new cookie value. However, the actual request header only contains the new cookie value.</p>
<h2 dir="auto">Expected Result</h2>
<p dir="auto">What would be expected is that <code class="notranslate">r.request.headers['Cookies']</code> would only have the new replaced cookie value rather than the old</p>
<h2 dir="auto">Actual Result</h2>
<p dir="auto">Its request header from <code class="notranslate">r.request.headers['Cookies']</code> shows both the old and the new cookie value</p>
<h2 dir="auto">Reproduction Steps</h2>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="python
import requests

r = requests.get('http://httpbin.org/cookies/set?FOO=BAZ', cookies={'FOO': 'BAR'})

print(r.json()) #{'cookies': {'FOO': 'BAZ'}}  

print(r.request.headers['Cookie']) # FOO=BAR; FOO=BAZ"><pre class="notranslate"><code class="notranslate">python
import requests

r = requests.get('http://httpbin.org/cookies/set?FOO=BAZ', cookies={'FOO': 'BAR'})

print(r.json()) #{'cookies': {'FOO': 'BAZ'}}  

print(r.request.headers['Cookie']) # FOO=BAR; FOO=BAZ
</code></pre></div>
<p dir="auto">From what I understand, the latter should be just <code class="notranslate">FOO=BAZ</code> as I believe it should only reflect the request headers from the final request. I think what is going on is that the cookies from the previous requests are merged into this.</p>
<h2 dir="auto">System Information</h2>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="$ python -m requests.help"><pre class="notranslate"><code class="notranslate">$ python -m requests.help
</code></pre></div>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="{
  &quot;chardet&quot;: {
    &quot;version&quot;: &quot;3.0.4&quot;
  },
  &quot;cryptography&quot;: {
    &quot;version&quot;: &quot;&quot;
  },
  &quot;idna&quot;: {
    &quot;version&quot;: &quot;2.9&quot;
  },
  &quot;implementation&quot;: {
    &quot;name&quot;: &quot;CPython&quot;,
    &quot;version&quot;: &quot;3.6.9&quot;
  },
  &quot;platform&quot;: {
    &quot;release&quot;: &quot;5.3.0-59-generic&quot;,
    &quot;system&quot;: &quot;Linux&quot;
  },
  &quot;pyOpenSSL&quot;: {
    &quot;openssl_version&quot;: &quot;&quot;,
    &quot;version&quot;: null
  },
  &quot;requests&quot;: {
    &quot;version&quot;: &quot;2.23.0&quot;
  },
  &quot;system_ssl&quot;: {
    &quot;version&quot;: &quot;1010100f&quot;
  },
  &quot;urllib3&quot;: {
    &quot;version&quot;: &quot;1.25.9&quot;
  },
  &quot;using_pyopenssl&quot;: false
}"><pre class="notranslate"><code class="notranslate">{
  "chardet": {
    "version": "3.0.4"
  },
  "cryptography": {
    "version": ""
  },
  "idna": {
    "version": "2.9"
  },
  "implementation": {
    "name": "CPython",
    "version": "3.6.9"
  },
  "platform": {
    "release": "5.3.0-59-generic",
    "system": "Linux"
  },
  "pyOpenSSL": {
    "openssl_version": "",
    "version": null
  },
  "requests": {
    "version": "2.23.0"
  },
  "system_ssl": {
    "version": "1010100f"
  },
  "urllib3": {
    "version": "1.25.9"
  },
  "using_pyopenssl": false
}
</code></pre></div>