Delete cookies not working with adapter

## Summary.

Using the requests-wsgi-adapter code, deleting cookies (eg using httpbin) doesn't work.  I wrote a test that demonstrates it:  https://github.com/Singletoned/requests-wsgi-adapter/blob/feature/delete-cookies/tests.py#L77

The equivalent code using requests and httpbin.org works fine, but using requests, requests-wsgi-adapter and httpbin as a wsgi app, it fails to delete the cookie.

```
# This works as expected

import requests

session = requests.Session()

response = session.get("http://httpbin.org/cookies/set?flim=flam&flooble=flumble")
print(response.json())
assert response.json()['cookies'] == {'flooble': 'flumble', 'flim': 'flam'}

response = session.get("http://httpbin.org/cookies/delete?flim=flam")
print(response.json())
assert response.json()['cookies'] == {'flooble': 'flumble'}
```

I imagine the fact that is doesn't work is a result of the interface between requests and requests-wsgi-adapter, but I can't work out what is going wrong.  Any help investigating this would be greatly appreciated.

I wonder if it might be something to do with the cookie domain...

## Expected Result

I expect the `flim` cookie to not be in the response anymore.

## Actual Result

Rather than deleting the cookie it appears to do nothing.

## Reproduction Steps

```
# pip install httpbin requests-wsgi-adapter
# This fails
import httpbin
import requests

from wsgiadapter import WSGIAdapter

session = requests.session()
session.mount('http://localhost', WSGIAdapter(app=httpbin.app))
session.get(
    "http://localhost/cookies/set?flimble=floop&flamble=flaap")
response = session.get("http://localhost/cookies")
assert response.json() == {
    'cookies': {'flimble': 'floop', 'flamble': 'flaap'}}
response = session.get(
    "http://localhost/cookies/delete?flimble")
result = response.json()
expected = {'cookies': {'flamble': 'flaap'}}
assert result == expected, result
```

## System Information

    $ python -m requests.help

```
{
  "chardet": {
    "version": "3.0.4"
  },
  "cryptography": {
    "version": ""
  },
  "implementation": {
    "name": "CPython",
    "version": "3.6.2"
  },
  "platform": {
    "release": "16.7.0",
    "system": "Darwin"
  },
  "pyOpenSSL": {
    "openssl_version": "",
    "version": null
  },
  "requests": {
    "version": "2.18.1"
  },
  "system_ssl": {
    "version": "100020cf"
  },
  "urllib3": {
    "version": "1.22"
  },
  "using_pyopenssl": false
}
```

What are the response headers for each request in both cases?

These are the failing headers using the wsgi adapter:
```
[('Content-Type', 'text/html; charset=utf-8'),
 ('Content-Length', '223'),
 ('Location', '/cookies'),
 ('Set-Cookie', 'flimble=floop; Path=/'),
 ('Set-Cookie', 'flamble=flaap; Path=/'),
 ('Access-Control-Allow-Origin', '*'),
 ('Access-Control-Allow-Credentials', 'true'),
 ('X-Powered-By', 'Flask'),
 ('X-Processed-Time', '0')]

[('Content-Type', 'application/json'),
 ('Access-Control-Allow-Origin', '*'),
 ('Access-Control-Allow-Credentials', 'true'),
 ('X-Powered-By', 'Flask'),
 ('X-Processed-Time', '0'),
 ('Content-Length', '71')]

[('Content-Type', 'text/html; charset=utf-8'),
 ('Content-Length', '223'),
 ('Location', '/cookies'),
 ('Set-Cookie',
  'flimble=; Expires=Thu, 01-Jan-1970 00:00:00 GMT; Max-Age=0; Path=/'),
 ('Access-Control-Allow-Origin', '*'),
 ('Access-Control-Allow-Credentials', 'true'),
 ('X-Powered-By', 'Flask'),
 ('X-Processed-Time', '0')]

[('Content-Type', 'application/json'),
 ('Access-Control-Allow-Origin', '*'),
 ('Access-Control-Allow-Credentials', 'true'),
 ('X-Powered-By', 'Flask'),
 ('X-Processed-Time', '0'),
 ('Content-Length', '71')]
```
And these are the passing ones using requests against httpbin.org
```

Connection: keep-alive
Server: meinheld/0.6.1
Date: Wed, 01 Nov 2017 20:41:15 GMT
Content-Type: text/html; charset=utf-8
Content-Length: 223
Location: /cookies
Set-Cookie: flim=flam; Path=/
Set-Cookie: flooble=flumble; Path=/
Access-Control-Allow-Origin: *
Access-Control-Allow-Credentials: true
X-Powered-By: Flask
X-Processed-Time: 0.00153303146362
Via: 1.1 vegur

Connection: keep-alive
Server: meinheld/0.6.1
Date: Wed, 01 Nov 2017 20:41:14 GMT
Content-Type: application/json
Access-Control-Allow-Origin: *
Access-Control-Allow-Credentials: true
X-Powered-By: Flask
X-Processed-Time: 0.00084400177002
Content-Length: 69
Via: 1.1 vegur

Connection: keep-alive
Server: meinheld/0.6.1
Date: Wed, 01 Nov 2017 20:41:15 GMT
Content-Type: text/html; charset=utf-8
Content-Length: 223
Location: /cookies
Set-Cookie: flim=; Expires=Thu, 01-Jan-1970 00:00:00 GMT; Max-Age=0; Path=/
Access-Control-Allow-Origin: *
Access-Control-Allow-Credentials: true
X-Powered-By: Flask
X-Processed-Time: 0.00103402137756
Via: 1.1 vegur


Connection: keep-alive
Server: meinheld/0.6.1
Date: Wed, 01 Nov 2017 20:41:15 GMT
Content-Type: application/json
Access-Control-Allow-Origin: *
Access-Control-Allow-Credentials: true
X-Powered-By: Flask
X-Processed-Time: 0.000602006912231
Content-Length: 48
Via: 1.1 vegur
```

Sorry that they are in different formats.

Hrm. Those seem just fine. I suspect requests-wsgi adapter is not correctly shimming the underlying response into a format that cookielib likes. 

These are the cookies from each response:
```
<RequestsCookieJar[<Cookie flamble=flaap for example.com/>, <Cookie flimble=floop for example.com/>]>
<RequestsCookieJar[]>
<RequestsCookieJar[<Cookie flimble= for example.com/cookies>]>
<RequestsCookieJar[]>
```
They seem correct.

Although I notice that the deleted cookie is for "example.com/cookies" not "example.com/".  I wonder if that could affect it?

Yup, that will do it. That is incorrect though: the path is specified in the cookie header. 

That stuff is handled by `requests.cookies` and std lib's `http.cookiejar`.  The interface is somewhat complicated (with MockReqeusts and email messages and stuff), but I'm trying to follow it.

I've got it down to a minimum failing example.

```
import requests
import http.cookiejar
from requests.structures import CaseInsensitiveDict


class MockMessage(object):
    def __init__(self, headers):
        self._headers = CaseInsensitiveDict(headers)

    def getheaders(self, name, default=None):
        header = self._headers.get(name)
        if default is None:
            default = []
        if header is None:
            return default
        return [s.strip() for s in header.split(',')]

    get_all = getheaders


class Stub(object):
    def __init__(self, **kwargs):
        for key in kwargs:
            setattr(self, key, kwargs[key])


cookies = http.cookiejar.CookieJar()


res = Stub(
    _original_response=Stub(
        msg=MockMessage(
            {
                'Set-Cookie': 'flimble=; Expires=Thu, 01-Jan-1970 00:00:00 GMT; Max-Age=0; Path=/',})
    ))

req = Stub(
    **{
        'method': 'GET',
        'url': 'http://example.com/cookies/delete?flimble',
        'headers': {'Host': 'example.com'}})

print(cookies)

result = requests.cookies.extract_cookies_to_jar(cookies, req, res)

print(result)
print(cookies)
```

It seems to be the line `[s.strip() for s in header.split(',')]` that is causing the problem, as it is naively splitting the header on commas.  I can't see what the correct solution would be though.  And I can't find any code that does a better job of parsing the headers.

For cookie headers, don’t split them. Just check the header names first. 

Unfortunately that doesn't work.  They don't get parsed at all if I do that and then no cookies are detected.

Ah, ok, sorry. The problem you have here is that a different layer (maybe yours, maybe Requests), is joining the two `Set-Cookie` headers at the start together with a comma. This isn't right, but it's a common behaviour when storing these headers in a dictionary. Really this needs to be solved by using a dictionary more like urllib3's `HeaderDict`, which is able to return a list of all the headers received rather than joining them.

Okay, I know where that's happening and it's easily fixable.  I think that fix my problems.  Is it reasonable to not handle joined `Set-Cookie` headers if a server sends them?  (Handling multiple separate headers is fine).  My code is only going to be dealing with WSGI servers, so I doubt anyone will have set them manually, nor will there be any major legacy issues.  Thanks for all your help with this. 😸 

Yeah, it’s fine. 😁

Brilliant, thanks again for all your help with this.  I think I've got it sorted 😺