# Path: httoop/exceptions.py
# class InvalidHeader(Invalid):
# 	u"""error raised when header is invalid"""


from datetime import datetime
from httoop.exceptions import InvalidHeader
import pytest
	headers['Set-Cookie'] = 'foo=bar; max-age=1.1'
	with pytest.raises(InvalidHeader):
		headers.get_element('Set-Cookie').max_age


def test_persistent(headers):
	headers['Set-Cookie'] = 'foo=bar; '
	assert not headers.get_element('Set-Cookie').persistent
	headers['Set-Cookie'] = 'foo=bar; expires=Thu, 31-Dec-2015 16:02:17 GMT'
	assert headers.get_element('Set-Cookie').persistent
	headers['Set-Cookie'] = 'foo=bar; max-age=1'
	assert headers.get_element('Set-Cookie').persistent


def test_mulitline_set_cookie(headers):
	headers.append('Set-Cookie', b'foo=bar;')
	headers.append('Set-Cookie', b'bar=baz; max-age=1')
	assert bytes(headers) == b'Set-Cookie: foo=bar;\r\nSet-Cookie: bar=baz; max-age=1\r\n\r\n'


def test_joining_multiple_cookies(headers):
	headers.append('Cookie', b'foo=bar')
	headers.append('Cookie', b'bar=baz')
	assert bytes(headers) == b'Cookie: foo=bar; bar=baz\r\n\r\n'


@pytest.mark.xfail(reason='Cookie must only be one header, separated by ;')
def test_parsing_multiple_cookie_lines(statemachine):
	statemachine.parse(b'GET / HTTP/1.1\r\nHost: www.example.com\r\n')
	statemachine.parse(b'Cookie: foo=bar\r\n')

# Path: httoop/exceptions.py
# class InvalidHeader(Invalid):
# 	u"""error raised when header is invalid"""


# Path: tests/headers/test_cookies.py
from datetime import datetime
from httoop.exceptions import InvalidHeader
import pytest

	headers['Set-Cookie'] = 'foo=bar; max-age=1.1'
	with pytest.raises(InvalidHeader):
		headers.get_element('Set-Cookie').max_age


def test_persistent(headers):
	headers['Set-Cookie'] = 'foo=bar; '
	assert not headers.get_element('Set-Cookie').persistent
	headers['Set-Cookie'] = 'foo=bar; expires=Thu, 31-Dec-2015 16:02:17 GMT'
	assert headers.get_element('Set-Cookie').persistent
	headers['Set-Cookie'] = 'foo=bar; max-age=1'
	assert headers.get_element('Set-Cookie').persistent


def test_mulitline_set_cookie(headers):
	headers.append('Set-Cookie', b'foo=bar;')
	headers.append('Set-Cookie', b'bar=baz; max-age=1')
	assert bytes(headers) == b'Set-Cookie: foo=bar;\r\nSet-Cookie: bar=baz; max-age=1\r\n\r\n'


def test_joining_multiple_cookies(headers):
	headers.append('Cookie', b'foo=bar')
	headers.append('Cookie', b'bar=baz')
	assert bytes(headers) == b'Cookie: foo=bar; bar=baz\r\n\r\n'


@pytest.mark.xfail(reason='Cookie must only be one header, separated by ;')
def test_parsing_multiple_cookie_lines(statemachine):
	statemachine.parse(b'GET / HTTP/1.1\r\nHost: www.example.com\r\n')
	statemachine.parse(b'Cookie: foo=bar\r\n')

	with pytest.raises(InvalidHeader):