Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Got doesn't pass query-string when calling via unix-socket #1036

Closed
2 tasks done
izonder opened this issue Jan 23, 2020 · 4 comments · Fixed by #1051
Closed
2 tasks done

Got doesn't pass query-string when calling via unix-socket #1036

izonder opened this issue Jan 23, 2020 · 4 comments · Fixed by #1051
Labels
bug Something does not work as it should ✭ help wanted ✭

Comments

@izonder
Copy link

izonder commented Jan 23, 2020

Describe the bug

  • Node.js version: v10.16.3+ (at least)
  • OS & version: Ubuntu 18.04 Linux 4.15.0-72-generic (probably any other OS)
  • Got: v10.2.2

Actual behavior

Making a call via UNIX-socket results in not passing query string in URL. When making a call via normal TCP/IP port it works correctly. For example, for the code below we have received the output:

call to /tmp/app.sock, URL = /tmp/app.sock:/http?foo=bar
call to /tmp/app.sock, URL = /got # here should be a query-string
call to 3000, URL = /http?foo=bar
call to 3000, URL = /got?foo=bar

Expected behavior

Having query string in request in both cases. For example, for the code below it's expected the output:

call to /tmp/app.sock, URL = /tmp/app.sock:/http?foo=bar
call to /tmp/app.sock, URL = /tmp/app.sock:/got?foo=bar # here should be a query-string
call to 3000, URL = /http?foo=bar
call to 3000, URL = /got?foo=bar

or at least:

call to /tmp/app.sock, URL = /tmp/app.sock:/http?foo=bar
call to /tmp/app.sock, URL = /got?foo=bar # here should be a query-string
call to 3000, URL = /http?foo=bar
call to 3000, URL = /got?foo=bar

Code to reproduce

const fs = require('fs'),
    http = require('http'),
    got = require('got');

const port = 3000,
    socket = '/tmp/app.sock',
    search = '?foo=bar',
    handler = (listen) => (req, res) => {
        console.log(`call to ${listen}, URL = ${req.url}`);

        res.statusCode = 204;
        res.end();
    },
    cb = () => {};

//clean up and establish http server with unix-socket
if (fs.existsSync(socket)) fs.unlinkSync(socket);
http.createServer(handler(port)).listen(port);
http.createServer(handler(socket)).listen(socket);

//reference call with http via TCP/IP port
http.get(
    new URL(`http://localhost:${port}/http${search}`),
    {headers: {authorization: 'Basic aaa'}},
    cb
);

//reference call with got via TCP/IP port
got
    .get(`http://localhost:${port}/got${search}`, {headers: {authorization: 'Basic aaa'}})
    .then(cb);

//reference call with http via unix-socket
http.get(
    new URL(`http://unix:${socket}:/http${search}`),
    {socketPath: '/tmp/app.sock', headers: {authorization: 'Basic aaa'}},
    cb
);

//testing call with got via unix-socket
got
    .get(`http://unix:${socket}:/got${search}`, {headers: {authorization: 'Basic aaa'}})
    .then(cb);

Checklist

  • I have read the documentation.
  • I have tried my code with the latest version of Node.js and Got.
@izonder
Copy link
Author

izonder commented Jan 23, 2020

If make the reproducing code consistent and pass WHATWG-URL objects as a parameter everywhere, nothing will change:

//reference call with http via TCP/IP port
http.get(
    new URL(`http://localhost:${port}/http${search}`),
    {headers: {authorization: 'Basic aaa'}},
    cb
);

//reference call with got via TCP/IP port
got
    .get(new URL(`http://localhost:${port}/got${search}`), {headers: {authorization: 'Basic aaa'}})
    .then(cb);

//reference call with http via unix-socket
http.get(
    new URL(`http://unix:${socket}:/http${search}`),
    {socketPath: '/tmp/app.sock', headers: {authorization: 'Basic aaa'}},
    cb
);

//testing call with got via unix-socket
got
    .get(new URL(`http://unix:${socket}:/got${search}`), {headers: {authorization: 'Basic aaa'}})
    .then(cb);

The output is the same:

$ node ./test.js 
call to /tmp/app.sock, URL = /tmp/app.sock:/http?foo=bar
call to /tmp/app.sock, URL = /got
call to 3000, URL = /http?foo=bar
call to 3000, URL = /got?foo=bar

@izonder izonder changed the title Got suppresses passing query-string when calling via unix-socket Got doesn't pass query-string when calling via unix-socket Jan 24, 2020
@psylence303
Copy link

Confirmed for macOS as well:

Node.js version: v12.13.1
OS & version: macOS 10.14.6 (Darwin 18.7.0)
Got: v10.2.2

@szmarczak szmarczak added bug Something does not work as it should ✭ help wanted ✭ labels Jan 27, 2020
@szmarczak szmarczak mentioned this issue Feb 6, 2020
18 tasks
szmarczak added a commit to szmarczak/got that referenced this issue Feb 29, 2020
szmarczak added a commit to szmarczak/got that referenced this issue Mar 3, 2020
szmarczak added a commit to szmarczak/got that referenced this issue Mar 4, 2020
@silverwind
Copy link

Also noticed this. This is a regression, v9.6.0 does work.

@thedillonb
Copy link

Is there any workaround for this?

# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
bug Something does not work as it should ✭ help wanted ✭
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants