Skip to content

Commit bf4967d

Browse files
committed
supporting the data_base64
Signed-off-by: Fabio José <[email protected]>
1 parent 1f8940c commit bf4967d

File tree

2 files changed

+24
-1
lines changed

2 files changed

+24
-1
lines changed

lib/bindings/http/emitter_binary.js

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,11 @@ BinaryHTTPEmitter.prototype.emit = function(cloudevent) {
3838
});
3939

4040
// Set the cloudevent payload
41-
_config[Constants.DATA_ATTRIBUTE] = cloudevent.format().data;
41+
let formatted = cloudevent.format();
42+
let data = formatted.data;
43+
data = (formatted.data_base64 ? formatted.data_base64: data);
44+
45+
_config[Constants.DATA_ATTRIBUTE] = data;
4246

4347
// Have extensions?
4448
var exts = cloudevent.getExtensions();

test/http_binding_1.js

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -135,6 +135,25 @@ describe("HTTP Transport Binding - Version 1.0", () => {
135135
});
136136
});
137137

138+
it("the request payload should be correct when event data is binary", () => {
139+
let bindata = Uint32Array.from(dataString, (c) => c.codePointAt(0));
140+
let expected = asBase64(bindata);
141+
let binevent =
142+
new Cloudevent(v1.Spec)
143+
.type(type)
144+
.source(source)
145+
.dataContentType("text/plain")
146+
.data(bindata)
147+
.addExtension(ext1Name, ext1Value)
148+
.addExtension(ext2Name, ext2Value);
149+
150+
return binary.emit(binevent)
151+
.then((response) => {
152+
expect(response.config.data)
153+
.to.equal(expected);
154+
});
155+
});
156+
138157
it("HTTP Header contains 'ce-type'", () => {
139158
return binary.emit(cloudevent)
140159
.then((response) => {

0 commit comments

Comments
 (0)