Ky: Passing a Request object as first argument to ky fails

Created on 9 May 2019  路  1Comment  路  Source: sindresorhus/ky

I don't know if this is intentional, but the README - and the TypeScript definitions - state that in ky(input, options) ky accepts the same values as fetch.

However, passing a Request instance as the value for input does not work, since it's stringified here and it turns into [object Request].

bug

Most helpful comment

Yep, confirmed, this is a bug introduced by PR #11. Thanks for reporting it!

The reason we stringify the input is to support passing in a WHATWG URL instance. Those objects stringify to the appropriate URL, whereas Request objects do not.

The solution will involve checking this._input instanceof Request, and if true, use the value of this._input.url during construction of the prefix URL.

>All comments

Yep, confirmed, this is a bug introduced by PR #11. Thanks for reporting it!

The reason we stringify the input is to support passing in a WHATWG URL instance. Those objects stringify to the appropriate URL, whereas Request objects do not.

The solution will involve checking this._input instanceof Request, and if true, use the value of this._input.url during construction of the prefix URL.

Was this page helpful?
0 / 5 - 0 ratings