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

/v1/catalog/register is broken after upgrade to v2.1.2 #189

Closed
neufeldtech opened this issue Mar 19, 2019 · 1 comment
Closed

/v1/catalog/register is broken after upgrade to v2.1.2 #189

neufeldtech opened this issue Mar 19, 2019 · 1 comment

Comments

@neufeldtech
Copy link

neufeldtech commented Mar 19, 2019

Hi there,
I'm experiencing an issue with version 2.1.2 of this gem that I'm not seeing with v2.1.1.

We're currently using consul v0.7.0 in our environment, and I'm using this gem to make calls to the /v1/catalog/register endpoint.

I'm making calls similar to this:

Diplomat::Service.register_external(
    Node: 'mynode01',
    Address: '192.168.34.34',
    Service: {
      Service: 'foo_service',
      Address: '192.168.34.34',
      Port: '9100',
      Tags: ['consul_registrator']
    }
  )

I've captured the HTTP payloads of a request and response on working example (gem v2.1.1) and on a broken example (gem v2.1.2) for you:

v2.1.1 (working as expected)

HTTP Request

PUT /v1/catalog/register HTTP/1.1
User-Agent: Faraday v0.15.4
Content-Type: application/x-www-form-urlencoded
Accept-Encoding: gzip;q=1.0,deflate;q=0.6,identity;q=0.3
Accept: */*
Connection: close
Host: localhost:8500
Content-Length: 186

{"Node":"mynode01_consul_registrator","Address":"192.168.34.34","Service":{"Service":"role_base","Address":"192.168.34.34","Port":9100,"Tags":["role_base","consul_registrator"]}}

HTTP Response:

HTTP/1.1 200 OK
Content-Type: application/json
Date: Tue, 19 Mar 2019 21:58:45 GMT
Content-Length: 4
Connection: close

true

v2.1.2 (Not working - Consul returns HTTP 400)

HTTP Request:

PUT /v1/catalog/register HTTP/1.1
User-Agent: Faraday v0.15.4
Content-Type: application/x-www-form-urlencoded
Accept-Encoding: gzip;q=1.0,deflate;q=0.6,identity;q=0.3
Accept: */*
Connection: close
Host: localhost:8500
Content-Length: 228

Address=192.168.34.34&Node=mynode01_consul_registrator&Service%5BAddress%5D=192.168.34.34&Service%5BPort%5D=9100&Service%5BService%5D=role_base&Service%5BTags%5D%5B%5D=role_base&Service%5BTags%5D%5B%5D=consul_registrator

HTTP Response:

HTTP/1.1 400 Bad Request
Date: Tue, 19 Mar 2019 21:46:15 GMT
Content-Length: 75
Content-Type: text/plain; charset=utf-8
Connection: close

Request decode failed: invalid character 'A' looking for beginning of value

As you can see above, in both requests Faraday is sending Content-Type: application/x-www-form-urlencoded.

In the first request (v2.1.1) the gem is sending the body as a JSON payload.
In the second request (v2.1.2) the gem is sending the body as a x-www-form-urlencoded payload.

If we make assumptions about what ought to be happening, v2.1.1 is arguably sending the 'incorrect' content-type header with its JSON payload, even though consul successfully accepts the JSON payload with the mismatched header.

However, when we attempt to send it a form-urlencoded payload with an x-www-form-urlencoded content-type header, consul rejects it.

I suspect that it's related to the JSON.dump() at https://github.com/WeAreFarmGeek/diplomat/compare/v2.1.1...v2.1.2?diff=split#diff-8f9f0d1ed7f32ce8ac36895fa3a85486R50

Let me know if you require any more information regarding this behaviour, and thanks for your work on this gem!

@pierresouchay
Copy link
Member

Should be fixed with 2.1.3. Sorry about this and thank you for the bug report

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