fix: improve binary data detection in HTTP transport (#468)

This commit is contained in:
Lance Ball 2022-02-02 07:18:08 -05:00 committed by GitHub
parent 8abbc114af
commit cd4dea954b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 9007 additions and 71 deletions

9068
package-lock.json generated

File diff suppressed because it is too large Load Diff

View File

@ -107,6 +107,7 @@
"homepage": "https://github.com/cloudevents/sdk-javascript#readme",
"dependencies": {
"ajv": "~6.12.3",
"util": "^0.12.4",
"uuid": "~8.3.0"
},
"devDependencies": {

View File

@ -3,6 +3,8 @@
SPDX-License-Identifier: Apache-2.0
*/
import { types } from "util";
import { CloudEvent, CloudEventV1, CONSTANTS, Mode, Version } from "../..";
import { Message, Headers, Binding } from "..";
@ -29,7 +31,7 @@ function binary<T>(event: CloudEventV1<T>): Message {
const contentType: Headers = { [CONSTANTS.HEADER_CONTENT_TYPE]: CONSTANTS.DEFAULT_CONTENT_TYPE };
const headers: Headers = { ...contentType, ...headersFor(event) };
let body = event.data;
if (typeof event.data === "object" && !(event.data instanceof Uint32Array)) {
if (typeof event.data === "object" && !types.isTypedArray(event.data)) {
// we'll stringify objects, but not binary data
body = (JSON.stringify(event.data) as unknown) as T;
}

View File

@ -4,6 +4,11 @@ module.exports = {
entry: {
"cloudevents": "./browser/index.js"
},
resolve: {
fallback: {
util: require.resolve("util/")
},
},
output: {
path: path.resolve(__dirname, "bundles"),
filename: "[name].js",