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

node/http.ts http.request should support socketPath option #17910

Open
loynoir opened this issue Feb 16, 2023 · 5 comments
Open

node/http.ts http.request should support socketPath option #17910

loynoir opened this issue Feb 16, 2023 · 5 comments
Labels
bug Something isn't working correctly

Comments

@loynoir
Copy link

loynoir commented Feb 16, 2023

Describe the bug

Steps to Reproduce

> var Docker = (await import('npm:[email protected]')).default
undefined
> var docker = new Docker({socketPath: '/var/run/docker.sock'});
undefined
> await docker.listContainers()
Uncaught TypeError: error sending request for url (http://localhost/containers/json): error trying to connect: tcp connect error: Connection refused (os error 111)
    at async mainFetch (internal:ext/fetch/26_fetch.js:267:14)
    at async fetch (internal:ext/fetch/26_fetch.js:491:9)
    at async ClientRequest._final (https://deno.land/[email protected]/node/http.ts:147:7)

Expected behavior

> var Docker = (await import('dockerode')).default
undefined
> var docker = new Docker({socketPath: '/var/run/docker.sock'});
undefined
> await docker.listContainers()
[
  {
    Id: ...

Environment

@loynoir loynoir added bug Something isn't working correctly needs triage labels Feb 16, 2023
@kt3k kt3k removed the needs triage label Feb 17, 2023
@loynoir loynoir changed the title npm:[email protected] got type error [node/http] npm:[email protected] got type error Feb 18, 2023
@loynoir
Copy link
Author

loynoir commented Feb 24, 2023

minimal reproduce

void http.request(
  'http://localhost/version',
  {
    socketPath: '/var/run/docker.sock',
  },
  (res) => res.on('data', (c) => console.log('' + c)),
).end()

Expected

$ node
> void http.request('http://localhost/version', {socketPath: '/var/run/docker.sock'}, (res)=>res.on('data',c=>console.log(''+c))).end()
// {"Platform": ...

Actual

$ deno
> import http from 'node:http'
> void http.request('http://localhost/version', {socketPath: '/var/run/docker.sock'}, (res)=>res.on('data',c=>console.log(''+c))).end()
// nothing

@loynoir loynoir changed the title [node/http] npm:[email protected] got type error node/http.ts http.request should support socketPath option Feb 24, 2023
@kt3k kt3k transferred this issue from denoland/std Feb 24, 2023
@loynoir
Copy link
Author

loynoir commented Mar 21, 2023

@kt3k

#8821 (comment)

https://deno.land/x/[email protected]/mod.ts

Maybe can merge that library into node/http.ts logic?

@danopia
Copy link
Contributor

danopia commented Mar 25, 2023

https://deno.land/x/[email protected]/mod.ts

Maybe can merge that library into node/http.ts logic?

Unfortunately my socket_fetch library is incomplete :( It can only perform GET requests and is not optimized. I use it to query specific things but it's not in a shape to be dropped into npm libraries I think.

Ideally Deno ships some sort of Unix socket fetch client instead :)

@loynoir
Copy link
Author

loynoir commented Aug 2, 2023

Workaround

import { fetch, Agent } from 'undici'

const resp = await fetch('http://localhost/version', {
  dispatcher: new Agent({
    connect: {
      socketPath: '/var/run/docker.sock'
    }
  })
})

console.log(await resp.text())
$ deno run --unstable -A ./reproduce.mjs
{"Platform":...

@loynoir
Copy link
Author

loynoir commented Oct 16, 2023

Related

[feat] Make backend js ecosystem future better

nodejs/node#50195

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working correctly
Projects
None yet
Development

No branches or pull requests

4 participants