Repository navigation
fix: send binary events without data with the HTTP transport - #681
Open
rida-ghreizy wants to merge 1 commit into
Open
rida-ghreizy wants to merge 1 commit into
rida-ghreizy wants to merge 1 commit into
Conversation
httpTransport always called req.write(message.body). For a binary-mode event without data the body is undefined, and Node throws ERR_INVALID_ARG_TYPE, so the event was never sent. Only write the body when there is one, and add a test against a real local server. Signed-off-by: rida <ghreizyrida1@gmail.com>
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Proposed Changes
The built-in
httpTransport(src/transport/http/index.ts) always callsreq.write(message.body). In binary mode, an event withoutdataproduces a message whosebodyisundefined. Node's HTTP client rejects that, so the emitter fails before anything is sent:Events without data are valid CloudEvents (for example notifications that only carry attributes). Structured mode already works because the body is the JSON envelope.
This PR only writes the body when there is one. The request is then sent with the
ce-*headers and an empty body.Description
New test in
test/integration/emitter_factory_test.ts, "Sends a binary event that has no data". It starts a local HTTP server, because thenockinterceptor used by the other tests acceptswrite(undefined)and would hide the error, then checks that the server received the event'sce-id.Without the change the test fails with the
chunkTypeError. With it, the full suite passes (npx mocha --exit --require ts-node/register ./test/integration/**/*.ts: 235 passing), and ESLint is clean on the changed files.#657 replaces this transport with the Fetch API. This is a small fix for the current transport in the meantime.