node.js request to docker api gives always error 400

700 Views Asked by At

I get always an error 400 when I try to connect to docker api. When I try it with curl I get an response.

const request = require('request');


request('http://unix:/var/run/docker.sock:/v1.37/info', (error, response, body) => {
        console.log('error:', error);
        console.log('statusCode:', response && response.statusCode);
        console.log(body);
});

root@e014aa4c09ad:/docker-api# node test.js
error: null
statusCode: 400
400 Bad Request: malformed Host header
1

There are 1 best solutions below

0
On BEST ANSWER

According to https://github.com/request/request/issues/2327#issuecomment-298317737, you need to set the Host header to null.

  headers: {
    'host' : null
  },