silas / node-consul

Consul client
https://www.npmjs.com/package/consul
MIT License
560 stars 83 forks source link

Omit x-consul-token from headers when token is not defined #151

Closed StanlieK closed 1 year ago

StanlieK commented 1 year ago

This PR resolves #150

This library allows the setting consul (authentication) token to be undefined. This is okay, but once you try to send an HTTP/s request with the header x-consul-token: undefined, it screams that undefined is not an allowed value.

[error="TypeError [ERR_HTTP_INVALID_HEADER_VALUE]: Invalid value "undefined" for header "x-consul-token""] I have studied consul lib in Go, and they don't set this header if the value is missing. Understand, that the token is the empty string (as it is the default value for undefined variable of type string in Go. See: https://github.com/hashicorp/consul/blob/78e3cbe1562165f891f56c93047031d608ac4ed4/api/api.go#L874C1-L876C3

I suggest not setting it on the empty string and undefined as well.

silas commented 1 year ago

@StanlieK Thanks for the PR, released in consul@2.0.0-next.2