From 4896a5d5e0def6bbf508c879de8e4451254829c3 Mon Sep 17 00:00:00 2001 From: "Gavin M. Roy" Date: Mon, 18 Jan 2021 13:23:31 -0500 Subject: [PATCH] Include cookies in the Request validation --- tests/test_requests.py | 4 +++- tornado_openapi3/requests.py | 6 ++++-- 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/tests/test_requests.py b/tests/test_requests.py index 0b19940..ebdbfab 100644 --- a/tests/test_requests.py +++ b/tests/test_requests.py @@ -124,7 +124,9 @@ class TestRequestFactory(unittest.TestCase): expected = OpenAPIRequest( full_url_pattern=url, method="get", - parameters=RequestParameters(query=ImmutableMultiDict(parameters)), + parameters=RequestParameters( + query=ImmutableMultiDict(parameters), path={}, cookie={} + ), body=b"", mimetype="application/x-www-form-urlencoded", ) diff --git a/tornado_openapi3/requests.py b/tornado_openapi3/requests.py index 0af3581..09b430c 100644 --- a/tornado_openapi3/requests.py +++ b/tornado_openapi3/requests.py @@ -9,7 +9,7 @@ from openapi_core.validation.request.datatypes import ( # type: ignore ) from openapi_core.validation.request import validators # type: ignore from tornado.httpclient import HTTPRequest # type: ignore -from tornado.httputil import HTTPServerRequest # type: ignore +from tornado.httputil import HTTPServerRequest, parse_cookie # type: ignore from werkzeug.datastructures import ImmutableMultiDict, Headers from .util import parse_mimetype @@ -43,7 +43,9 @@ class TornadoRequestFactory: full_url_pattern=path, method=request.method.lower() if request.method else "get", parameters=RequestParameters( - query=query_arguments, header=Headers(request.headers.get_all()) + query=query_arguments, + header=Headers(request.headers.get_all()), + cookie=parse_cookie(request.headers.get("Cookie", "")), ), body=request.body if request.body else b"", mimetype=parse_mimetype(