Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Contribute to GitLab
Sign in
Toggle navigation
C
corepost
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Commits
Open sidebar
nexlab
corepost
Commits
942a67c0
Commit
942a67c0
authored
Jun 13, 2012
by
Mark Moissette
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
added handling of empty request data (for post, put etc)
parent
82912d8b
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
4 additions
and
3 deletions
+4
-3
routing.py
corepost/routing.py
+4
-3
No files found.
corepost/routing.py
View file @
942a67c0
...
@@ -380,19 +380,20 @@ class RequestRouter:
...
@@ -380,19 +380,20 @@ class RequestRouter:
'''Automatically parses JSON,XML,YAML if present'''
'''Automatically parses JSON,XML,YAML if present'''
if
request
.
method
in
(
Http
.
POST
,
Http
.
PUT
)
and
HttpHeader
.
CONTENT_TYPE
in
request
.
received_headers
.
keys
():
if
request
.
method
in
(
Http
.
POST
,
Http
.
PUT
)
and
HttpHeader
.
CONTENT_TYPE
in
request
.
received_headers
.
keys
():
contentType
=
request
.
received_headers
[
"content-type"
]
contentType
=
request
.
received_headers
[
"content-type"
]
data
=
request
.
content
.
read
()
if
contentType
==
MediaType
.
APPLICATION_JSON
:
if
contentType
==
MediaType
.
APPLICATION_JSON
:
try
:
try
:
request
.
json
=
json
.
loads
(
request
.
content
.
read
())
request
.
json
=
json
.
loads
(
data
)
if
data
else
{}
except
Exception
as
ex
:
except
Exception
as
ex
:
raise
TypeError
(
"Unable to parse JSON body:
%
s"
%
ex
)
raise
TypeError
(
"Unable to parse JSON body:
%
s"
%
ex
)
elif
contentType
in
(
MediaType
.
APPLICATION_XML
,
MediaType
.
TEXT_XML
):
elif
contentType
in
(
MediaType
.
APPLICATION_XML
,
MediaType
.
TEXT_XML
):
try
:
try
:
request
.
xml
=
ElementTree
.
XML
(
request
.
content
.
read
()
)
request
.
xml
=
ElementTree
.
XML
(
data
)
except
Exception
as
ex
:
except
Exception
as
ex
:
raise
TypeError
(
"Unable to parse XML body:
%
s"
%
ex
)
raise
TypeError
(
"Unable to parse XML body:
%
s"
%
ex
)
elif
contentType
==
MediaType
.
TEXT_YAML
:
elif
contentType
==
MediaType
.
TEXT_YAML
:
try
:
try
:
request
.
yaml
=
yaml
.
safe_load
(
request
.
content
.
read
()
)
request
.
yaml
=
yaml
.
safe_load
(
data
)
except
Exception
as
ex
:
except
Exception
as
ex
:
raise
TypeError
(
"Unable to parse YAML body:
%
s"
%
ex
)
raise
TypeError
(
"Unable to parse YAML body:
%
s"
%
ex
)
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment