bent icon indicating copy to clipboard operation
bent copied to clipboard

Support limit of redirects

Open mk-pmb opened this issue 4 years ago • 4 comments

In my case, I want to follow no redirects at all, so I'd set that limit to 0.

mk-pmb avatar Apr 02 '20 03:04 mk-pmb

Looks like following no redirects is actually the default, and I just made a typo in the URL. Could you please clarify the intended redirect behaviour in the Readme then?

mk-pmb avatar Apr 02 '20 03:04 mk-pmb

bent doesn’t implement redirect following, although I have considered adding it. But in the browser we use fetch which does its own redirect following, which is why it’s been a bit awkward to figure out how to add this feature to bent in a cross-platform way.

mikeal avatar Apr 02 '20 16:04 mikeal

I guess we could follow the convention of up to 20 redirects in node side.

amio avatar Apr 02 '20 17:04 amio

I'd mirror the fetch spec here and support the three modes also in nodejs:

A request has an associated redirect mode, which is "follow", "error", or "manual". Unless stated otherwise, it is "follow".

"follow" Follow all redirects incurred when fetching a resource. "error" Return a network error when a request is met with a redirect. "manual" Retrieves an opaque-redirect filtered response when a request is met with a redirect, to allow a service worker to replay the redirect offline. The response is otherwise indistinguishable from a network error, to not violate atomic HTTP redirect handling.

source: https://fetch.spec.whatwg.org/#requests

It's also specced that:

A redirect status is a status that is 301, 302, 303, 307, or 308.

source: https://fetch.spec.whatwg.org/#statuses

The 20 redirect limit is in the spec:

If request’s redirect count is twenty, return a network error.

source: https://fetch.spec.whatwg.org/#http-redirect-fetch

The browser impl would be just passing that parameter to the fetch, and then tackle the nodejs side with up to 20 redirects. Then it would have full parity.

swftvsn avatar Apr 09 '20 09:04 swftvsn