@@ -129,32 +129,34 @@ def UnmarshalJSON(self, b: typing.IO,
129
129
130
130
def UnmarshalBinary (self , headers : dict , body : typing .IO ,
131
131
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
+
144
145
self .Set ("data" , data_unmarshaller (body ))
145
146
146
147
def MarshalBinary (
147
148
self , data_marshaller : typing .Callable ) -> (dict , object ):
148
149
headers = {}
150
+ if self .ContentType ():
151
+ headers ["content-type" ] = self .ContentType ()
149
152
props = self .Properties ()
150
153
for key , value in props .items ():
151
- if key not in ["data" , "extensions" ]:
154
+ if key not in ["data" , "extensions" , "contenttype" ]:
152
155
if value is not None :
153
156
headers ["ce-{0}" .format (key )] = value
154
157
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
158
160
159
161
data , _ = self .Get ("data" )
160
162
return headers , io .BytesIO (
0 commit comments