-
Notifications
You must be signed in to change notification settings - Fork 69
/
Copy pathbinary_0_1.js
42 lines (32 loc) · 1.16 KB
/
binary_0_1.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
var axios = require("axios");
function HTTPBinary(configuration){
this.config = JSON.parse(JSON.stringify(configuration));
this.config["headers"] = {
"Content-Type":"application/cloudevents+json; charset=utf-8"
};
}
HTTPBinary.prototype.emit = function(cloudevent){
// Create new request object
var _config = JSON.parse(JSON.stringify(this.config));
// Always set stuff in _config
var _headers = _config["headers"];
if(cloudevent.getContenttype()) {
_headers["Content-Type"] = cloudevent.getContenttype();
}
_headers["CE-EventType"] = cloudevent.getType();
if(cloudevent.getEventTypeVersion()) {
_headers["CE-EventTypeVersion"] = cloudevent.getEventTypeVersion();
}
_headers["CE-CloudEventsVersion"] = cloudevent.getSpecversion();
_headers["CE-Source"] = cloudevent.getSource();
_headers["CE-EventID"] = cloudevent.getId();
if(cloudevent.getTime()) {
_headers["CE-EventTime"] = cloudevent.getTime();
}
_headers["CE-SchemaURL"] = cloudevent.getSchemaurl();
// Set the cloudevent payload
_config["data"] = cloudevent.format().data;
// Return the Promise
return axios.request(_config);
};
module.exports = HTTPBinary;