extism / js-pdk

Write Extism plugins in JavaScript & TypeScript
42 stars 16 forks source link

HTTP headers are never sent with the HTTP Client API #47

Closed mathieuancelin closed 4 months ago

mathieuancelin commented 4 months ago

When using the HTTP Client API from a JS plugin like this:

const task = {
  "userId":1, 
  "id":2345,
  "title":"title",
  "completed":false
};
const request = {
  method: "POST",
  url: "https://jsonplaceholder.typicode.com/todos",
  headers: {
    "Accept": "application/json",
    "Content-Type": "application/json",
  },
};

const response = Http.request(
  request, 
  JSON.stringify(task),
);

it appears that the headers were never sent, hence the target server not being able to parse the body correctly and creating an empty task.

This pull request fix this behavior

zshipko commented 4 months ago

Thanks!