tmate-io / tmate-websocket

16 stars 13 forks source link

MasterApi: HTTP header names are case insensitive #8

Open pini-gh opened 3 years ago

pini-gh commented 3 years ago

Fixes #7.

nviennot commented 3 years ago

That should not be needed. https://github.com/tmate-io/tmate-websocket/blob/master/lib/tmate/master_api.ex#L7 enables the json transforms https://github.com/tmate-io/tmate-websocket/blob/master/lib/tmate/util/json_api.ex#L37 decoding should happen here.

If your PR is fixing a bug, how can I reproduce it?

pini-gh commented 3 years ago

If your PR is fixing a bug, how can I reproduce it?

This is explained in #7. See the console part.

nviennot commented 3 years ago

image

Seems fine here

pini-gh commented 3 years ago

Thanks to your pointers I've found out where the actual problem lies: https://github.com/tmate-io/tmate-websocket/blob/master/lib/tmate/util/json_api.ex#L35

For the tmate-websocket instance I used the same value for MASTER_BASE_URL and USER_FACING_BASE_URL. Then the /named_session_prefix request was going through my reverse-proxy, which uses Content-Type instead of content-type as header name.

It works if I set MASTER_BASE_URL to the internal URL http://tmate-master:4000/. In this case the header name is content-type (all lowercase). But it might be worth making the header name lookup case insensitive:

        content_type_hdr = Enum.find(headers, fn {name, _} -> String.downcase(name) == "content-type" end)