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

Unable to find parser given the encoding and headers provided #133

Closed
deewhyweb opened this issue May 7, 2020 · 1 comment · Fixed by #134
Closed

Unable to find parser given the encoding and headers provided #133

deewhyweb opened this issue May 7, 2020 · 1 comment · Fixed by #134
Assignees
Labels
type/bug Something isn't working version/1.x Issues related to version 1.x of this library

Comments

@deewhyweb
Copy link
Contributor

deewhyweb commented May 7, 2020

Using the latest code from master, I'm creating an event from Kafka which is coming into my app as:
body: "{"specversion":"1.0","id":"3","type":"type","source":"123"}"

headers: {"host":"event-display.kafka.svc.cluster.local","user-agent":"Go-http-client/1.1","content-length":"59","accept-encoding":"gzip","ce-id":"partition:1/offset:23","ce-source":"/apis/v1/namespaces/kafka/kafkasources/kafka-source#knative-demo-topic","ce-specversion":"1.0","ce-subject":"partition:1#23","ce-time":"2020-05-07T14:16:30.245Z","ce-type":"dev.knative.kafka.event","forwarded":"for=10.131.0.72;proto=http","k-proxy-request":"activator","kourier-random-header":"558c917a-906d-11ea-96ab-0a580a830047","traceparent":"00-73df58d7c1383e17dabe515dfd68d05a-b00799e628f49cbe-00","x-envoy-expected-rq-timeout-ms":"600000","x-forwarded-for":"10.131.0.72, 10.128.2.99","x-forwarded-proto":"http","x-request-id":"d3649c1b-a968-40bf-a9da-3e853abc0c8b"}

The code I'm using is as follows:

const express = require('express');
const app = express();
const { HTTPReceiver, CloudEvent } = require('cloudevents-sdk');

const receiver = new HTTPReceiver();
app.use((req, res, next) => {
  let data = "";

  //req.setEncoding("utf8");
  req.on("data", function(chunk) {
      data += chunk;
  });
  req.on("end", function() {
      req.body = data;
      next();
  });
});
app.post('/', (req, res) => {
  console.log('Version 1.20');
  console.log('body:',JSON.stringify(req.body))
  console.log('headers:',JSON.stringify(req.headers))
  try {
    let myevent = receiver.accept(req.headers,req.body);
    console.log(JSON.stringify(myevent))
    res.status(201).send("Event Accepted");

  } catch(err) {
    // TODO deal with errors
    console.error(err);
    res.status(415)
          .header("Content-Type", "application/json")
          .send(JSON.stringify(err));
  }
});
const port = process.env.PORT || 8080;
app.listen(port, () => {
  console.log('Hello world listening on port', port);
});

I receive the following error:

TypeError: Cannot read property 'parse' of undefined
at BinaryHTTPReceiver.parse (/usr/src/app/node_modules/cloudevents-sdk/lib/bindings/http/receiver_binary.js:115:9)
at Receiver.parse (/usr/src/app/node_modules/cloudevents-sdk/lib/bindings/http/receiver_binary_1.js:111:24)
at HTTPReceiver.accept (/usr/src/app/node_modules/cloudevents-sdk/lib/bindings/http/http_receiver.js:26:40)
at /usr/src/app/index.js:26:28
at Layer.handle [as handle_request] (/usr/src/app/node_modules/express/lib/router/layer.js:95:5)
at next (/usr/src/app/node_modules/express/lib/router/route.js:137:13)
at Route.dispatch (/usr/src/app/node_modules/express/lib/router/route.js:112:3)
at Layer.handle [as handle_request] (/usr/src/app/node_modules/express/lib/router/layer.js:95:5)
at /usr/src/app/node_modules/express/lib/router/index.js:281:22
at Function.process_params (/usr/src/app/node_modules/express/lib/router/index.js:335:12)

@lance lance self-assigned this May 7, 2020
@lance lance added type/bug Something isn't working version/1.x Issues related to version 1.x of this library labels May 7, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type/bug Something isn't working version/1.x Issues related to version 1.x of this library
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants