Merge pull request #2916 from gtmanfred/master
Make all CallbackResponse requests into a Werkzeug Request
This commit is contained in:
commit
cca3ea9ddf
@ -12,6 +12,8 @@ from io import BytesIO
|
||||
from collections import defaultdict
|
||||
from botocore.handlers import BUILTIN_HANDLERS
|
||||
from botocore.awsrequest import AWSResponse
|
||||
from six.moves.urllib.parse import urlparse
|
||||
from werkzeug.wrappers import Request
|
||||
|
||||
import mock
|
||||
from moto import settings
|
||||
@ -175,6 +177,26 @@ class CallbackResponse(responses.CallbackResponse):
|
||||
"""
|
||||
Need to override this so we can pass decode_content=False
|
||||
"""
|
||||
if not isinstance(request, Request):
|
||||
url = urlparse(request.url)
|
||||
if request.body is None:
|
||||
body = None
|
||||
elif isinstance(request.body, six.text_type):
|
||||
body = six.BytesIO(six.b(request.body))
|
||||
else:
|
||||
body = six.BytesIO(request.body)
|
||||
req = Request.from_values(
|
||||
path="?".join([url.path, url.query]),
|
||||
input_stream=body,
|
||||
content_length=request.headers.get("Content-Length"),
|
||||
content_type=request.headers.get("Content-Type"),
|
||||
method=request.method,
|
||||
base_url="{scheme}://{netloc}".format(
|
||||
scheme=url.scheme, netloc=url.netloc
|
||||
),
|
||||
headers=[(k, v) for k, v in six.iteritems(request.headers)],
|
||||
)
|
||||
request = req
|
||||
headers = self.get_headers()
|
||||
|
||||
result = self.callback(request)
|
||||
|
@ -5,7 +5,6 @@ import sys
|
||||
|
||||
import six
|
||||
from botocore.awsrequest import AWSPreparedRequest
|
||||
from werkzeug.wrappers import Request
|
||||
|
||||
from moto.core.utils import str_to_rfc_1123_datetime, py2_strip_unicode_keys
|
||||
from six.moves.urllib.parse import parse_qs, urlparse, unquote, parse_qsl
|
||||
@ -797,14 +796,6 @@ class ResponseObject(_TemplateEnvironmentMixin, ActionAuthenticatorMixin):
|
||||
if hasattr(request, "form"):
|
||||
# Not HTTPretty
|
||||
form = request.form
|
||||
elif request.headers.get("Content-Type").startswith("multipart/form-data"):
|
||||
request = Request.from_values(
|
||||
input_stream=six.BytesIO(request.body),
|
||||
content_length=request.headers["Content-Length"],
|
||||
content_type=request.headers["Content-Type"],
|
||||
method="POST",
|
||||
)
|
||||
form = request.form
|
||||
else:
|
||||
# HTTPretty, build new form object
|
||||
body = body.decode()
|
||||
|
Loading…
Reference in New Issue
Block a user