Fix - robust customer properties parsing
@@ -78,13 +78,15 @@ def _create_message(response, service_instance):
message_type = value
elif name.lower() == 'location':
message_location = value
- elif name.lower() not in ['content-type',
- 'brokerproperties',
- 'transfer-encoding',
+ # Exclude common HTTP headers to avoid noise. List
+ # is not exhaustive. At worst, custom properties will contains
+ # an unexpected content generated by the webserver and not the customer.
+ elif name.lower() not in ['transfer-encoding',
'server',
- 'location',
'date',
'strict-transport-security']:
+ # Follow the spec:
+ # https://docs.microsoft.com/rest/api/servicebus/message-headers-and-properties
if '"' in value:
value = value[1:-1].replace('\\"', '"')
try:
@@ -92,16 +94,23 @@ def _create_message(response, service_instance):
value, '%a, %d %b %Y %H:%M:%S GMT')
except ValueError:
custom_properties[name] = value
- else: # only int, float or boolean
- if value.lower() == 'true':
+ elif value.lower() == 'true':
custom_properties[name] = True
elif value.lower() == 'false':
custom_properties[name] = False
+ else: # in theory, only int or float
+ try:
# int('3.1') doesn't work so need to get float('3.14') first
- elif str(int(float(value))) == value:
+ float_value = float(value)
+ if str(int(float_value)) == value:
custom_properties[name] = int(value)
else:
- custom_properties[name] = float(value)
+ custom_properties[name] = float_value
+ except ValueError:
+ # If we are here, this header does not respect the spec.
+ # Could be an unexpected HTTP header or an invalid
+ # header value. In both case we ignore without failing.
+ pass
if message_type is None:
message = Message(
