supporting the data_base64

Signed-off-by: Fabio José <fabiojose@gmail.com>
This commit is contained in:
Fabio José 2019-11-04 13:50:22 -03:00
parent 1f8940c8a7
commit bf4967d30c
2 changed files with 24 additions and 1 deletions

View File

@ -38,7 +38,11 @@ BinaryHTTPEmitter.prototype.emit = function(cloudevent) {
});
// Set the cloudevent payload
_config[Constants.DATA_ATTRIBUTE] = cloudevent.format().data;
let formatted = cloudevent.format();
let data = formatted.data;
data = (formatted.data_base64 ? formatted.data_base64: data);
_config[Constants.DATA_ATTRIBUTE] = data;
// Have extensions?
var exts = cloudevent.getExtensions();

View File

@ -135,6 +135,25 @@ describe("HTTP Transport Binding - Version 1.0", () => {
});
});
it("the request payload should be correct when event data is binary", () => {
let bindata = Uint32Array.from(dataString, (c) => c.codePointAt(0));
let expected = asBase64(bindata);
let binevent =
new Cloudevent(v1.Spec)
.type(type)
.source(source)
.dataContentType("text/plain")
.data(bindata)
.addExtension(ext1Name, ext1Value)
.addExtension(ext2Name, ext2Value);
return binary.emit(binevent)
.then((response) => {
expect(response.config.data)
.to.equal(expected);
});
});
it("HTTP Header contains 'ce-type'", () => {
return binary.emit(cloudevent)
.then((response) => {