Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: make application/json the default content type in binary mode #118

Merged
merged 1 commit into from
May 5, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions lib/bindings/http/receiver_binary.js
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,11 @@ BinaryHTTPReceiver.prototype.check = function(payload, headers) {
// Clone and low case all headers names
const sanityHeaders = Commons.sanityAndClone(headers);

// If no content type is provided, default to application/json
if (!sanityHeaders[Constants.HEADER_CONTENT_TYPE]) {
sanityHeaders[Constants.HEADER_CONTENT_TYPE] = Constants.MIME_JSON;
}

// Validation Level 1
if (!this.allowedContentTypes
.includes(sanityHeaders[Constants.HEADER_CONTENT_TYPE])) {
Expand Down
14 changes: 14 additions & 0 deletions test/bindings/http/receiver_binary_0_3_tests.js
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,20 @@ describe("HTTP Transport Binding Binary Receiver for CloudEvents v0.3", () => {
expect(receiver.check.bind(receiver, payload, attributes))
.to.not.throw();
});

it("No error when content-type is unspecified", () => {
const payload = {};
const attributes = {
"ce-type": "type",
"ce-specversion": "0.3",
"ce-source": "source",
"ce-id": "id"
};

// act and assert
expect(receiver.check.bind(receiver, payload, attributes))
.to.not.throw();
});
});

describe("Parse", () => {
Expand Down
14 changes: 14 additions & 0 deletions test/bindings/http/receiver_binary_1_tests.js
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,20 @@ describe("HTTP Transport Binding Binary Receiver for CloudEvents v1.0", () => {
.to.throw("invalid content type");
});

it("No error when content-type is unspecified", () => {
const payload = {};
const attributes = {
"ce-type": "type",
"ce-specversion": "1.0",
"ce-source": "source",
"ce-id": "id"
};

// act and assert
expect(receiver.check.bind(receiver, payload, attributes))
.to.not.throw();
});

it("No error when all required headers are in place", () => {
// setup
const payload = {};
Expand Down