@@ -129,32 +129,34 @@ def UnmarshalJSON(self, b: typing.IO,
129129
130130 def UnmarshalBinary (self , headers : dict , body : typing .IO ,
131131 data_unmarshaller : typing .Callable ):
132- props = self .Properties (with_nullable = True )
133- exts = props .get ("extensions" )
134- for key in props :
135- formatted_key = "ce-{0}" .format (key )
136- if key != "extensions" :
137- self .Set (key , headers .get ("ce-{0}" .format (key )))
138- if formatted_key in headers :
139- del headers [formatted_key ]
140-
141- # rest of headers suppose to an extension?
142- exts .update (** headers )
143- self .Set ("extensions" , exts )
132+ BINARY_MAPPING = {
133+ 'content-type' : 'contenttype' ,
134+ # TODO(someone): add Distributed Tracing. It's not clear
135+ # if this is one extension or two.
136+ # https://github.com/cloudevents/spec/blob/master/extensions/distributed-tracing.md
137+ }
138+ for header , value in headers .items ():
139+ header = header .lower ()
140+ if header in BINARY_MAPPING :
141+ self .Set (BINARY_MAPPING [header ], value )
142+ elif header .startswith ("ce-" ):
143+ self .Set (header [3 :], value )
144+
144145 self .Set ("data" , data_unmarshaller (body ))
145146
146147 def MarshalBinary (
147148 self , data_marshaller : typing .Callable ) -> (dict , object ):
148149 headers = {}
150+ if self .ContentType ():
151+ headers ["content-type" ] = self .ContentType ()
149152 props = self .Properties ()
150153 for key , value in props .items ():
151- if key not in ["data" , "extensions" ]:
154+ if key not in ["data" , "extensions" , "contenttype" ]:
152155 if value is not None :
153156 headers ["ce-{0}" .format (key )] = value
154157
155- exts = props .get ("extensions" )
156- if len (exts ) > 0 :
157- headers .update (** exts )
158+ for key , value in props .get ("extensions" ):
159+ headers ["ce-{0}" .format (key )] = value
158160
159161 data , _ = self .Get ("data" )
160162 return headers , io .BytesIO (
0 commit comments