Skip to content

Simple cookie use in ClientSession produces malformed HTTP request header in v1.2.0 #1566

Closed
@nugget

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:

Non-working host:

I don't believe that the Python version difference is a factor, but I have not tested for that.

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions