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

HPE_INVALID_HEADER_TOKEN - NodeJS v12 #75

Open
gabrielgiorisatto opened this issue Aug 4, 2020 · 5 comments
Open

HPE_INVALID_HEADER_TOKEN - NodeJS v12 #75

gabrielgiorisatto opened this issue Aug 4, 2020 · 5 comments

Comments

@gabrielgiorisatto
Copy link

All my requests using NodeJS v12 are returning Parse Error, and I think this is probably because of space in the header.

There are some discussions related here.

I had to downgrade my NodeJS to v10 and use the flag --insecure-http-parser to make it work.

@climba03003
Copy link
Contributor

climba03003 commented Aug 7, 2020

As you can see the discussion, it is related to the core package brings by node. Nothing we can do here to solve the issue.
My suggestion would be check which header cause the issue, then disable that plugins which generate the header.

@gabrielgiorisatto
Copy link
Author

But the header is auto-generated from the Woocommerce rest API.
Is it possible to change the header manually?

@climba03003
Copy link
Contributor

I do not think the invalid header is generated by this package.

For the header, you can change the header by passing axiosConfig to the constructor.
Example:

import WooCommerceRestApi from "@woocommerce/woocommerce-rest-api";

const api = new WooCommerceRestApi({
  url: "http://example.com",
  consumerKey: "ck_XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX",
  consumerSecret: "cs_XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX",
  version: "wc/v3",
  axiosConfig: {
    header: {
        'content-type': 'application/json'
    }
  }
});

@gabrielgiorisatto
Copy link
Author

Thank you for your help, but I removed this flag and used the axiosConfig that you recommended, and I'm still getting this error. Obs: I replaced some private infos with 'x'

The only way that it worked for me was using the --insecure-http-parser flag.

@climba03003
Copy link
Contributor

In this case, I think the invalid header is come from the response. As node v12 changed the behavior of http parser to be more strict than before, adding the flags seem to be the only options.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants