Skip to content

Conversation

cskeppstedt
Copy link
Contributor

By using Content-Length: request.length, you risk telling the server the wrong byte‐count. Consider this payload:

const response = await client.registerAccount({
  Firstname: "Christöffer",
  Lastname: "Skeppstedt",
  ...
});

When the string contains an "ö" instead of "o", we have:

  • Byte count: 930
  • String length: 929

When this request is sent to the Trustly API, it responds back with:

{
  "name": "JSONRPCError",
  "code": 101,
  "message": "ERROR_MALFORMED_JSON"
}

This is likely because the content length header is incorrect (929 != 930). When instead using Content-Length: Buffer.byteLength(request, 'utf8'), we get the correct content lenght, and the request is accepted.

By using `Content-Length: request.length`, you risk telling the server the wrong byte‐count. Consider this payload:

```
    const response = await client.registerAccount({
      Firstname: "Christöffer",
      Lastname: "Skeppstedt",
      ...
    });
```

When the string contains an "ö" instead of "o", we have:
- Byte count: 930
- String length: 929

When this request is sent to the Trustly API, it responds back with:

```
{
  "name": "JSONRPCError",
  "code": 101,
  "message": "ERROR_MALFORMED_JSON"
}
```

This is likely because the content length header is incorrect. When instead using `Content-Length: Buffer.byteLength(request, 'utf8')`, the request is accepted.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

1 participant