Skip to content

Commit d84c51f

Browse files
committed
Decode the metadata response before sending it to the VM
The metadata server response can be encoded. The metadata proxy decodes it before crafting the HTTP message that will be delivered to the virtual machine. It requires that the HTTP message sent by the metadata server contains the proper "Context-Encoding" header, defining the encoding type used. This header is not provided by default (the content is not encoded) or is empty. NOTE: unless we provide a method to encode the Nova metadata server content, it would not be possible to properly test this patch. Closes-Bug: #2120723 Signed-off-by: Rodolfo Alonso Hernandez <[email protected]> Change-Id: I747872f031cc5a1a87ced69bb0af645c088143f3 (cherry picked from commit c031b59)
1 parent 3efe8dc commit d84c51f

File tree

1 file changed

+8
-0
lines changed

1 file changed

+8
-0
lines changed

neutron/common/metadata.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,8 @@
3333
PROXY_SERVICE_NAME = 'haproxy'
3434
PROXY_SERVICE_CMD = 'haproxy'
3535

36+
CONTENT_ENCODERS = ('gzip', 'deflate')
37+
3638

3739
class InvalidUserOrGroupException(Exception):
3840
pass
@@ -162,6 +164,12 @@ def _http_response(http_response, request):
162164
status=http_response.status_code,
163165
content_type=http_response.headers['content-type'],
164166
charset=http_response.encoding)
167+
# The content of the response is decoded depending on the
168+
# "Context-Enconding" header, if present. The operation is limited to
169+
# ("gzip", "deflate"), as is in the ``webob.response.Response`` class.
170+
if _res.content_encoding in CONTENT_ENCODERS:
171+
_res.decode_content()
172+
165173
# NOTE(ralonsoh): there should be a better way to format the HTTP
166174
# response, adding the HTTP version to the ``webob.Response``
167175
# output string.

0 commit comments

Comments
 (0)