sindresorhus / got

🌐 Human-friendly and powerful HTTP request library for Node.js
MIT License
14.27k stars 935 forks source link

Unix sockets don't support "body" #1194

Closed OmgImAlexis closed 4 years ago

OmgImAlexis commented 4 years ago

Describe the bug

Actual behavior

 GotError: The "source" argument must be of type function or an instance of Stream, Iterable, or AsyncIterable. Received undefined
    at onError (/usr/local/node/graphql-api/node_modules/got/dist/source/request-as-event-emitter.js:140:29)
    at handleRequest (/usr/local/node/graphql-api/node_modules/got/dist/source/request-as-event-emitter.js:173:17)
    at pipeline (internal/streams/pipeline.js:208:15)
    at internal/util.js:297:30
    at new Promise (<anonymous>)
    at pipeline (internal/util.js:296:12)
    at handleRequest (/usr/local/node/graphql-api/node_modules/got/dist/source/request-as-event-emitter.js:165:23)
    at get (/usr/local/node/graphql-api/node_modules/got/dist/source/request-as-event-emitter.js:197:17)
    at /usr/local/node/graphql-api/node_modules/got/dist/source/request-as-event-emitter.js:264:13 {
  name: 'RequestError',
  code: 'ERR_INVALID_ARG_TYPE'
}

When trying this against any HTTP endpoint the request works as expected.

Expected behavior

No error and the request to finish.

Code to reproduce

Removing the body options stops the error being thrown.

import got from 'got';
got.post('unix:/var/run/graphql-api.sock:/graphql', {
    headers: {
        'x-api-key': 'test123'
    },
    body: 'this is the body'
}).then(console.info).catch(console.error);

Checklist

OmgImAlexis commented 4 years ago

This works with requests for example.

const request = require('request');

request.post('http://unix:/var/run/graphql-api.sock:/graphql', {
    headers: {
        'x-api-key': 'test123'
    },
    body: 'this is the body'
}, (error, response) => {
    if (error) {
        console.error(error);
    }
    console.info(response);
});
szmarczak commented 4 years ago

You're using an outdated version of Got. Please try upgrading to Got 11.