@@ -3,15 +3,15 @@ var axios = require("axios");
33const Constants = require ( "./constants.js" ) ;
44
55function HTTPBinary ( configuration ) {
6- this . config = configuration ;
6+ this . config = JSON . parse ( JSON . stringify ( configuration ) ) ;
77
88 if ( ! this . config [ "headers" ] ) {
99 this . config [ "headers" ] = { } ;
1010 }
1111
1212 this . config [ "headers" ]
1313 [ Constants . HEADER_CONTENT_TYPE ] =
14- Constants . MIME_CE_JSON + "; charset=" + Constants . CHARSET_DEFAULT ;
14+ Constants . MIME_JSON + "; charset=" + Constants . CHARSET_DEFAULT ;
1515}
1616
1717HTTPBinary . prototype . emit = function ( cloudevent ) {
@@ -22,25 +22,39 @@ HTTPBinary.prototype.emit = function(cloudevent){
2222 // Always set stuff in _config
2323 var _headers = _config [ "headers" ] ;
2424
25+ // OPTIONAL CONTENT TYPE ATTRIBUTE
2526 if ( cloudevent . getContenttype ( ) ) {
2627 _headers [ Constants . HEADER_CONTENT_TYPE ] = cloudevent . getContenttype ( ) ;
2728 }
2829
2930 _headers [ "CE-EventType" ] = cloudevent . getType ( ) ;
30- if ( cloudevent . getEventTypeVersion ( ) ) {
31- _headers [ "CE-EventTypeVersion" ] = cloudevent . getEventTypeVersion ( ) ;
32- }
3331 _headers [ "CE-CloudEventsVersion" ] = cloudevent . getSpecversion ( ) ;
3432 _headers [ "CE-Source" ] = cloudevent . getSource ( ) ;
3533 _headers [ "CE-EventID" ] = cloudevent . getId ( ) ;
34+
35+ if ( cloudevent . getEventTypeVersion ( ) ) {
36+ _headers [ "CE-EventTypeVersion" ] = cloudevent . getEventTypeVersion ( ) ;
37+ }
38+
3639 if ( cloudevent . getTime ( ) ) {
3740 _headers [ "CE-EventTime" ] = cloudevent . getTime ( ) ;
3841 }
39- _headers [ "CE-SchemaURL" ] = cloudevent . getSchemaurl ( ) ;
42+ if ( cloudevent . getSchemaurl ( ) ) {
43+ _headers [ "CE-SchemaURL" ] = cloudevent . getSchemaurl ( ) ;
44+ }
4045
4146 // Set the cloudevent payload
4247 _config [ "data" ] = cloudevent . format ( ) . data ;
4348
49+ // EXTENSION CONTEXT ATTRIBUTES
50+ var exts = cloudevent . getExtensions ( ) ;
51+ for ( var ext in exts ) {
52+ if ( { } . hasOwnProperty . call ( exts , ext ) ) {
53+ let capsExt = ext . charAt ( 0 ) . toUpperCase ( ) + ext . slice ( 1 )
54+ _headers [ "CE-X-" + capsExt ] = exts [ ext ] ;
55+ }
56+ }
57+
4458 // Return the Promise
4559 return axios . request ( _config ) ;
4660} ;
0 commit comments