XmlBodyMiddleware logic causes an unnecessary JSON to dict conversion
Affects | Status | Importance | Assigned to | Milestone | |
---|---|---|---|---|---|
OpenStack Identity (keystone) |
Won't Fix
|
Low
|
Venkat Sundaram |
Bug Description
The XmlBodyMiddleware converts request body from XML string to JSON string and passes it on to the JsonBodyMiddleware next in chain.
Observe the following line in the XmlBodyMiddlewa
serializer.from_xml already converts the body to a python dict, but it dumps it again as a JSON string to the request body.
Now, observe the following lines in JsonBodyMiddleware .process_request method:
# Abort early if we don't have any work to do
params_json = request.body
if not params_json:
return
...
params = {}
for k, v in params_
if k in ('self', 'context'):
if k.startswith('_'):
...
The JsonBodyMiddleware converts JSON string to dict and then stores the dict in request.environ (It does some additional filtering of the dict before storing, but that doesn't look like it is JSON specific)
So, if the input request body has XML and the xml_body/json_body middlware are used in the paste pipeline, the effective conversion is: XML string => dict => JSON string => dict
This may induce a performance penalty (however minor it is) due to the unnecessary JSON to dict conversion. The following is the required conversion: XML string => dict
To achieve this, the following could be done:
Refactor the following lines from JsonBodyMiddlwa
params = {}
for k, v in params_
if k in ('self', 'context'):
if k.startswith('_'):
Then, call that method from XmlBodyMiddlewa
With this change, the JsonBodyMiddlware next in chain would not process the request due to the following initial check:
# Abort early if we don't have any work to do
params_json = request.body
if not params_json:
return
summary: |
- XmlBodyMiddleware logic causes an unnecessary JSON string to dict - conversion + XmlBodyMiddleware logic causes an unnecessary JSON to dict conversion |
Changed in keystone: | |
importance: | Undecided → Low |
tags: | added: xml |
Fix proposed to branch: master /review. openstack. org/67727
Review: https:/