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

WHATWG URL not working #15

Closed
fraxken opened this issue Mar 15, 2019 · 4 comments
Closed

WHATWG URL not working #15

fraxken opened this issue Mar 15, 2019 · 4 comments

Comments

@fraxken
Copy link

fraxken commented Mar 15, 2019

Hi,

The Type definition for your method take string | Url but you seem to have forgotten to transform the URL to a standard string. If we send an URL, it throw the following error:

TypeError: Cannot read property 'startsWith' of undefined
    at urlToOptions (internal/url.js:1260:28)
    at request (https.js:293:15)
    at Promise (F:\Code\orders\node_modules\httpie\dist\httpie.js:13:13)
    at new Promise (<anonymous>)
    at send (F:\Code\orders\node_modules\httpie\dist\httpie.js:6:9)
    at test (F:\Code\orders\test\test.js:48:19)
    at asPromise (F:\Code\orders\node_modules\japa\build\src\Callable\index.js:7:18)
    at Callable.Promise (F:\Code\orders\node_modules\japa\build\src\Callable\index.js:64:9)
    at new Promise (<anonymous>)
    at Object.Callable (F:\Code\orders\node_modules\japa\build\src\Callable\index.js:10:12)

Best Regards,
Thomas

@lukeed
Copy link
Owner

lukeed commented Mar 15, 2019

Hey, can you show me exactly what you're sending? Any URL objects are left as they are. Strings are parsed into URL object via url.parse.

@fraxken
Copy link
Author

fraxken commented Mar 15, 2019

hi,

A Node.js WHATWG URL:
https://nodejs.org/api/url.html#url_the_whatwg_url_api

const { get } = require("httpie");
async function main() {
    const { statusCode } = await get(new URL("https://www.google.fr/"));
    console.log(statusCode);
}
main().catch(console.error);

Best Regards,
Thomas

@lukeed
Copy link
Owner

lukeed commented Mar 15, 2019

Thanks, I knew what it was 😄 But you're right, I was handling it incorrectly. Turns out that when you merge a URL into an object, it merges its "URLContext" and not the formatted object you see when printing/reading it directly. TIL

let foo = new URL("https://www.google.fr/");

console.log(foo);
/*
URL {
  href: 'https://www.google.fr/',
  origin: 'https://www.google.fr',
  protocol: 'https:',
  username: '',
  password: '',
  host: 'www.google.fr',
  hostname: 'www.google.fr',
  port: '',
  pathname: '/',
  search: '',
  searchParams: URLSearchParams {},
  hash: '' }
*/

console.log({ ...foo });
/*
{ [Symbol(context)]:
   URLContext {
     flags: 400,
     scheme: 'https:',
     username: '',
     password: '',
     host: 'www.google.fr',
     port: null,
     path: [ '' ],
     query: null,
     fragment: null },
  [Symbol(query)]: URLSearchParams {} }
*/

This is also a different behavior than the (legacy) Url class, which behaved as described.

lukeed added a commit that referenced this issue Mar 15, 2019
@lukeed lukeed closed this as completed in 4fa89f8 Mar 15, 2019
@lukeed
Copy link
Owner

lukeed commented Mar 15, 2019

Released in v1.1.1 – thank you 🙌

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