Skip to content

Commit

Permalink
Merge f3c598a into 0263343
Browse files Browse the repository at this point in the history
  • Loading branch information
josephmancuso committed Aug 31, 2018
2 parents 0263343 + f3c598a commit 8f98fdc
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 6 deletions.
7 changes: 5 additions & 2 deletions masonite/request.py
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,6 @@ def load_environ(self, environ):
self.method = environ['REQUEST_METHOD']
self.path = environ['PATH_INFO']
self.request_variables = {}

self._set_standardized_request_variables(environ['QUERY_STRING'])

if self.has('__method'):
Expand All @@ -189,9 +188,14 @@ def _set_standardized_request_variables(self, variables):
variables {string|dict}
"""

if isinstance(variables, dict):
self.request_variables = variables
return

if isinstance(variables, str):
variables = parse_qs(variables)


for name in variables.keys():
value = self._get_standardized_value(variables[name])
self.request_variables[name] = value
Expand All @@ -205,7 +209,6 @@ def _get_standardized_value(self, value):
Returns:
string|bool
"""

if isinstance(value, list):
return value[0]

Expand Down
2 changes: 1 addition & 1 deletion masonite/routes.py
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ def set_post_params(self):

request_body = self.environ['wsgi.input'].read(
request_body_size)
return {'payload': json.loads(request_body)}
return json.loads(request_body)
else:
fields = cgi.FieldStorage(
fp=self.environ['wsgi.input'], environ=self.environ, keep_blank_values=1)
Expand Down
6 changes: 3 additions & 3 deletions tests/test_extends.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ def get_another_path2(self):
class MockWsgiInput():

def read(self, value):
return '{"id": 1}'
return '{"id": 1, "test": "testing"}'


def get_third_path(self):
Expand Down Expand Up @@ -105,9 +105,9 @@ def test_get_json_input(self):
json_wsgi['CONTENT_TYPE'] = 'application/json'
json_wsgi['QUERY_STRING'] = ''
json_wsgi['wsgi.input'] = MockWsgiInput()

Route(json_wsgi)
request_obj = Request(json_wsgi)

assert isinstance(request_obj.request_variables, dict)
assert request_obj.input('payload') == {'id': 1}
assert request_obj.input('id') == 1
assert request_obj.input('test') == 'testing'

0 comments on commit 8f98fdc

Please sign in to comment.