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

Naked arrays in request body erase meta-information. #32

Open
jhorbulyk opened this issue Apr 20, 2020 · 1 comment
Open

Naked arrays in request body erase meta-information. #32

jhorbulyk opened this issue Apr 20, 2020 · 1 comment
Labels
bug Ready For ToDo Task is ready for development

Comments

@jhorbulyk
Copy link
Contributor

jhorbulyk commented Apr 20, 2020

Bug Report

Description

When the body of a webhook request has a naked array, then other information in the request is not included in the outbound message.

Steps to reproduce

  1. Create a flow of the following form. Publish and start this flow.
  • Webhook to code component
  • No Auth for the webhook component
  • Use {} as sample data for both components.
  • Use the following code for code component:
// Please note only Node.js code is supported here
async function run(msg, cfg, snapshot) {
 this.logger.info('Incoming message is %s', JSON.stringify(msg));
 const body = { result : 'Hello world!' };
 // You can emit as many data messages as required
 await this.emit('data', { body });
 this.logger.info('Execution finished');
}
  1. Send a POST request with a JSON body of the following two forms and observe the data that is logged by the code component.
  • {"foo":"bar"}
  • [{"foo":"bar"}]

Actual result

Object Case ``` { "id": "3b69ae10-832d-11ea-9e1e-dd9d4ea250fb", "attachments": {}, "body": { "foo": "bar", "_query": {}, "_headers": { "host": "in.elastic.io", "x-request-id": "6b26ff54e5f7ad104c7a59e8f97be954", "x-real-ip": "76.64.72.41", "x-forwarded-for": "76.64.72.41", "x-forwarded-host": "in.elastic.io", "x-forwarded-port": "443", "x-forwarded-proto": "https", "x-original-uri": "/hook/5e9dc879923c3668e3160de8", "x-scheme": "https", "content-length": "17", "content-type": "application/json", "user-agent": "PostmanRuntime/7.24.1", "accept": "*/*", "cache-control": "no-cache", "postman-token": "e8757d6f-1f45-4482-aa04-9a1176a142a8", "accept-encoding": "gzip, deflate, br" }, "_method": "POST", "_url": "/hook/5e9dc879923c3668e3160de8" }, "headers": { "host": "in.elastic.io", "x-request-id": "6b26ff54e5f7ad104c7a59e8f97be954", "x-real-ip": "76.64.72.41", "x-forwarded-for": "76.64.72.41", "x-forwarded-host": "in.elastic.io", "x-forwarded-port": "443", "x-forwarded-proto": "https", "x-original-uri": "/hook/5e9dc879923c3668e3160de8", "x-scheme": "https", "content-length": "17", "content-type": "application/json", "user-agent": "PostmanRuntime/7.24.1", "accept": "*/*", "cache-control": "no-cache", "postman-token": "e8757d6f-1f45-4482-aa04-9a1176a142a8", "accept-encoding": "gzip, deflate, br" }, "metadata": {}, "url": "/hook/5e9dc879923c3668e3160de8", "method": "POST", "originalUrl": "/hook/5e9dc879923c3668e3160de8", "query": {}, "params": {}, "pathSuffix": "/hook/5e9dc879923c3668e3160de8", "taskId": "5e9dc879923c3668e3160de8", "passthrough": { "step_1": { "id": "3b69ae10-832d-11ea-9e1e-dd9d4ea250fb", "attachments": {}, "body": { "foo": "bar", "_query": {}, "_headers": { "host": "in.elastic.io", "x-request-id": "6b26ff54e5f7ad104c7a59e8f97be954", "x-real-ip": "76.64.72.41", "x-forwarded-for": "76.64.72.41", "x-forwarded-host": "in.elastic.io", "x-forwarded-port": "443", "x-forwarded-proto": "https", "x-original-uri": "/hook/5e9dc879923c3668e3160de8", "x-scheme": "https", "content-length": "17", "content-type": "application/json", "user-agent": "PostmanRuntime/7.24.1", "accept": "*/*", "cache-control": "no-cache", "postman-token": "e8757d6f-1f45-4482-aa04-9a1176a142a8", "accept-encoding": "gzip, deflate, br" }, "_method": "POST", "_url": "/hook/5e9dc879923c3668e3160de8" }, "headers": { "host": "in.elastic.io", "x-request-id": "6b26ff54e5f7ad104c7a59e8f97be954", "x-real-ip": "76.64.72.41", "x-forwarded-for": "76.64.72.41", "x-forwarded-host": "in.elastic.io", "x-forwarded-port": "443", "x-forwarded-proto": "https", "x-original-uri": "/hook/5e9dc879923c3668e3160de8", "x-scheme": "https", "content-length": "17", "content-type": "application/json", "user-agent": "PostmanRuntime/7.24.1", "accept": "*/*", "cache-control": "no-cache", "postman-token": "e8757d6f-1f45-4482-aa04-9a1176a142a8", "accept-encoding": "gzip, deflate, br" }, "metadata": {}, "url": "/hook/5e9dc879923c3668e3160de8", "method": "POST", "originalUrl": "/hook/5e9dc879923c3668e3160de8", "query": {}, "params": {}, "pathSuffix": "/hook/5e9dc879923c3668e3160de8", "taskId": "5e9dc879923c3668e3160de8" } } } ```
Array Case ``` { "id": "65089880-833c-11ea-9e1e-dd9d4ea250fb", "attachments": {}, "body": [ { "foo": "bar" } ], "headers": { "host": "in.elastic.io", "x-request-id": "dabf832f68a8297957a4c3a841357253", "x-real-ip": "76.64.72.41", "x-forwarded-for": "76.64.72.41", "x-forwarded-host": "in.elastic.io", "x-forwarded-port": "443", "x-forwarded-proto": "https", "x-original-uri": "/hook/5e9dc879923c3668e3160de8", "x-scheme": "https", "content-length": "19", "content-type": "application/json", "user-agent": "PostmanRuntime/7.24.1", "accept": "*/*", "cache-control": "no-cache", "postman-token": "6e4220f2-3e54-4957-9809-d55b0e586988", "accept-encoding": "gzip, deflate, br" }, "metadata": {}, "url": "/hook/5e9dc879923c3668e3160de8", "method": "POST", "originalUrl": "/hook/5e9dc879923c3668e3160de8", "query": {}, "params": {}, "pathSuffix": "/hook/5e9dc879923c3668e3160de8", "taskId": "5e9dc879923c3668e3160de8", "passthrough": { "step_1": { "id": "65089880-833c-11ea-9e1e-dd9d4ea250fb", "attachments": {}, "body": [ { "foo": "bar" } ], "headers": { "host": "in.elastic.io", "x-request-id": "dabf832f68a8297957a4c3a841357253", "x-real-ip": "76.64.72.41", "x-forwarded-for": "76.64.72.41", "x-forwarded-host": "in.elastic.io", "x-forwarded-port": "443", "x-forwarded-proto": "https", "x-original-uri": "/hook/5e9dc879923c3668e3160de8", "x-scheme": "https", "content-length": "19", "content-type": "application/json", "user-agent": "PostmanRuntime/7.24.1", "accept": "*/*", "cache-control": "no-cache", "postman-token": "6e4220f2-3e54-4957-9809-d55b0e586988", "accept-encoding": "gzip, deflate, br" }, "metadata": {}, "url": "/hook/5e9dc879923c3668e3160de8", "method": "POST", "originalUrl": "/hook/5e9dc879923c3668e3160de8", "query": {}, "params": {}, "pathSuffix": "/hook/5e9dc879923c3668e3160de8", "taskId": "5e9dc879923c3668e3160de8" } } } ```

Observe the presence of the following fields that are present in the body of the message for the object case but not the array case:

  • _url
  • _method
  • _headers
  • _query

Expected results

It is possible to read URL, Method, Headers and Query from the body of the message even if the request body is an array.

Proposed Solution

Create a new (backwards incompatible) receive method and depricate the existing method. The message structure of the body of the new method should be:

{
  "body": [{"foo":"bar"}],
  "method": "POST",
  "query": {},
  "attachments": {},
  "url": "....",
  "headers": {...}
}
@jhorbulyk
Copy link
Contributor Author

The proposed solution is potentially blocked by https://github.com/elasticio/elasticio/issues/2057

@andrewreshitko andrewreshitko added Ready For ToDo Task is ready for development bug labels Jun 12, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Ready For ToDo Task is ready for development
Projects
None yet
Development

No branches or pull requests

2 participants