Bun 遇到的一个 Bug,请求大佬分析分析,非常感谢

1次阅读

共计 1241 个字符,预计需要花费 4 分钟才能阅读完成。

Bun 的 1.1.12 和最新的 1.1.24 都试过了,均出现问题。

我调用原生的 fetch 方法,并设置 proxy 参数,我的环境变量没有设置 http_proxyhttps_proxy

Bun 官方对 proxy 的说明:https://bun.sh/guides/http/proxy

我的代码如下(xxx.js):

// https 请求,在有 proxy 参数情况下,会先发一个 CONNECT 并且就此报错
fetch('https://www.google.com', {proxy: 'http://127.0.0.1:7890',})

// 如果换成 http,就不会发 CONNECT,正常拿响应
fetch('https://www.google.com', {proxy: 'http://127.0.0.1:7890',})

只要是 https,就会出现下面的问题,而 http 没有:

> bun index.ts
[fetch] > HTTP/1.1 GET https://www.google.com/
[fetch] > Connection: keep-alive
[fetch] > User-Agent: Bun/1.1.24
[fetch] > Accept: */*
[fetch] > Host: www.google.com
[fetch] > Accept-Encoding: gzip, deflate, br

[fetch] < 200 Connection established

Syscall: Syscall fetching "https://www.google.com/". For more information, pass `verbose: true` in the second argument to fetch()
 path: "https://www.google.com/"

上面是原生 fetch 的操作,我下面换成 axios:

import axios from 'axios'
import https from 'https'

const instance = axios.create({
    httpsAgent: new https.Agent({rejectUnauthorized: false}),
    proxy: {
        host: '127.0.0.1',
        port: 7890
    }
})

instance.get('https://www.google.com').catch(err => {console.log(err.message)
})

这里报错:unable to get issuer certificate

大概就是个证书有关,可是我如果不使用 proxy,就不会有这个问题,所以这个不知道是 Bun 问题,还是 Clash 问题。

这个是我在 Bun 提的 ISSUES:https://github.com/oven-sh/bun/issues/13344

这个 40 秒的视频复现了问题:https://files.imdodo.com/dodo/083cecbf0bcc0b8f362c35b11d7e910e.mp4

正文完
 0