dfuse-eosio icon indicating copy to clipboard operation
dfuse-eosio copied to clipboard

Double slashes after hostname in URL causes all sort of weird behavior

Open maoueh opened this issue 4 years ago • 1 comments

If someone tries to hit /v1/chain API proxied calls via a POST there is a double trailing slash between the hostname and the path element of the URL, the HTTP response will be a 301 Moved Permanently```. However, returning a 301in case of HTT POST is problematic for client that respect the HTTP spec as a redirect 301 using aPOSTshould be retried using aGET` instead.

The HTTP code 307 was added exactly for this, so that client retry the request with the exact original request instead.

One would argue that it's easy to just remove the trailing slash, but sometimes it's kind of just hard to see it:

const rpc = new JsonRpc("https://kylin.eos.dfuse.io/")

In this case, when the developer will do rpc.get_block(...), the endpoint will be of the form https://kylin.eos.dfuse.io//v1/chain/get_block which is not spotted easily. For the record, it's probably the third time we got bitten by this problem.

This seems to be coming from github.com/gorilla/mux library and the StrictSlash handling that returns a 301 by default: https://godoc.org/github.com/gorilla/mux#Router.StrictSlash

We should instead send a 307 in those cases so there is no problem with POST request.

maoueh avatar May 27 '20 19:05 maoueh

Issue being discussed on https://github.com/gorilla/mux/issues/561

Didn't know 308 was in proposal to be added to HTTP spec. Probably lots of client out there that does not handle it yet.

The mux issue talks about middleware, we could take this approach while it's available somehow in the upstream library.

maoueh avatar May 28 '20 14:05 maoueh