Got: How is the URL build in got?

Created on 1 Dec 2020  Â·  3Comments  Â·  Source: sindresorhus/got

What would you like to discuss?

Dear maintainers of got,

I use your tool for an automated API testing.

I recently analysed, when I use the WHATWG-URL https://127.0.0.1/v1/users? I get this response:

URL {
    href: 'https://127.0.0.1/v1/users?',
    origin: 'https://127.0.0.1',
    protocol: 'https:',
    username: '',
    password: '',
    host: '127.0.0.1',
    hostname: '127.0.0.1',
    port: '',
    pathname: '/v1/users',
    search: '',
    searchParams: URLSearchParams {},
    hash: ''
}

response.req._header
----------------
GET /v1/users HTTP/1.1
user-agent: got (https://github.com/sindresorhus/got)
accept-encoding: gzip, deflate, br
Host: 127.0.0.1
Connection: close

The reason is, when I enter the URL by myself in the browser or the RESTClient, I get a different response than got represents.

My question is now, how the response.req._header gets the URL?
Is the URL build from the URL.pathname and URL.search?
If so, why don't you use the simple URL.href attribute?

I hope we'll find a solution.
Many thanks for your effort in advance.

Checklist

  • [x] I have read the documentation.

All 3 comments

My question is now, how the response.req._header gets the URL?

This is a Node.js internal property. Have a look at their source code.

Is the URL build from the URL.pathname and URL.search?

WDYM? Those are properties of a WHATWG URL object.

If so, why don't you use the simple URL.href attribute?

I don't understand the question. We store the URL in a WHATWG URL instance.

You can always look at the source code of Got and figure things out.

Why did you closed my topic? I still have a problem and I urgently needs to fix it.

Why did you closed my topic?

Closed ≠ Locked. Everybody can still keep going on.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

pvdlg picture pvdlg  Â·  3Comments

framerate picture framerate  Â·  4Comments

dAnjou picture dAnjou  Â·  3Comments

khizarsonu picture khizarsonu  Â·  3Comments

erfanium picture erfanium  Â·  3Comments