Simple cookie use in ClientSession produces malformed HTTP request header in v1.2.0 #1566
Closed
Description
Long story short
I have client code which uses simple cookies in http requests. It works fine on aiohttp 1.1.6 machines, but not on aiohttp 1.2.0 machines.
Expected behaviour
A ClientSession is invoked with simple cookies (not CookieJar) in order to pass cookies to a server as part of the request. Here is an actual, valid request on a 1.1.6 host:
GET / HTTP/1.1
Accept-Encoding: gzip, deflate
Accept: */*
Host: server.example.com
User-Agent: Python/3.5 aiohttp/1.1.6
Cookie: cows_are=cool
Content-Length: 0
Actual behaviour
The HTTP request header produced by aiohttp 1.2.0 is malformed, erroneously including the string "Set-Cookie:". This is from a 1.2.0 host using the same client script:
GET / HTTP/1.1
Accept-Encoding: gzip, deflate
Accept: */*
Host: server.example.com
User-Agent: Python/3.4 aiohttp/1.2.0
Cookie: cows_are="Set-Cookie: cows_are=cool"
Content-Length: 0
Steps to reproduce
I ran nc -l 80 on my test server so I could inspect the HTTP request being generated, then I ran this script on both versions of aiohttp:
#!/usr/bin/env python3
import aiohttp
import asyncio
import async_timeout
@asyncio.coroutine
def fetch(session, url):
with aiohttp.Timeout(10):
response = yield from session.get(url)
return (yield from response.text())
@asyncio.coroutine
def main(loop):
cookies = {'cows_are': 'cool'}
with aiohttp.ClientSession(loop=loop, cookies=cookies) as session:
html = yield from fetch(session, 'http://server.example.com/')
print(html)
loop = asyncio.get_event_loop()
loop.run_until_complete(main(loop))
Your environment
Working host:
- Linux host1 4.8.0-34-generic Fix checking for coroutine in HTTP server #36-Ubuntu SMP Wed Dec 21 17:24:18 UTC 2016 x86_64 x86_64 x86_64 GNU/Linux
- Python 3.5.2+
- aiohttp 1.1.6
Non-working host:
- Linux host2 4.4.38-v7+ Retrieve four things from the web with concurrency #938 SMP Thu Dec 15 15:22:21 GMT 2016 armv7l GNU/Linux
- Python 3.4.2
- aiohttp 1.2.0
I don't believe that the Python version difference is a factor, but I have not tested for that.