fix: improve binary data detection in HTTP transport (#468)
This commit is contained in:
parent
8abbc114af
commit
cd4dea954b
File diff suppressed because it is too large
Load Diff
|
@ -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": {
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
|
|
@ -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",
|
||||
|
|
Loading…
Reference in New Issue