关于 Git clone HTTP 协议代理的问题请教 - V2EX
V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
git
Pro Git
Atlassian Git Tutorial
Pro Git 简体中文翻译
GitX
iSecret
V2EX    git

关于 Git clone HTTP 协议代理的问题请教

  •  
  •   iSecret 2023-11-23 10:55:29 +08:00 1278 次点击
    这是一个创建于 738 天前的主题,其中的信息可能已经有所发展或是发生改变。

    最近在实现一个类似 gh-proxy 样的项目,本质上是代理转发流量,然后将源站的响应通过代理返回给客户端,目前 HTTP GET 和 POST 请求均能正常代理,但是 Git clone HTTP 不能正常执行。

    git clone https://proxy.local/https://github.com/user/repos.git Cloning into 'repos'... error: 1 bytes of length header were received fatal: protocol error: bad line length character: 005 

    通过抓包比较发现共发出两个请求,分别是:

    GET https://proxy.local/https://github.com/user/repos.git/info/refs?service=git-upload-pack HTTP/1.1 Host: proxy.local User-Agent: git/2.30.1 (Apple Git-130) Accept: */* Accept-Encoding: deflate, gzip Pragma: no-cache Git-Protocol: version=2 --- HTTP/1.1 200 OK Date: Thu, 23 Nov 2023 02:40:38 GMT Content-Type: application/x-git-upload-pack-advertisement Transfer-Encoding: chunked Connection: keep-alive expires: Fri, 01 Jan 1980 00:00:00 GMT pragma: no-cache Cache-Control: no-cache, max-age=0, must-revalidate vary: Accept-Encoding x-frame-options: DENY x-github-request-id: DE6A:5407:B244AD:BB74E2:XXXXXXXX access-control-expose-headers: * access-control-allow-origin: * strict-transport-security: max-age=2592000; includeSubDomains; preload 001e# service=git-upload-pack 0000000eversion 2 0022agent=git/github-cbc05ce31956 0013ls-refs=unborn 0027fetch=shallow wait-for-done filter 0012server-option 0017object-format=sha1 0000 

    POST https://proxy.local/https://github.com/user/repos.git/git-upload-pack HTTP/1.1 Host: proxy.local User-Agent: git/2.30.1 (Apple Git-130) Accept-Encoding: deflate, gzip Content-Type: application/x-git-upload-pack-request Accept: application/x-git-upload-pack-result Git-Protocol: version=2 Content-Length: 180 0014command=ls-refs 0024agent=git/2.30.1.(Apple.Git-130)0016object-format=sha100010009peel 000csymrefs 0014ref-prefix HEAD 001bref-prefix refs/heads/ 001aref-prefix refs/tags/ 0000 --- HTTP/1.1 200 OK Date: Thu, 23 Nov 2023 02:40:38 GMT Content-Type: application/x-git-upload-pack-result Transfer-Encoding: chunked Connection: keep-alive expires: Fri, 01 Jan 1980 00:00:00 GMT pragma: no-cache Cache-Control: no-cache, max-age=0, must-revalidate vary: Accept-Encoding x-github-request-id: 4CD0:60C4:A2B144:E33C9D:XXXXXXXX x-frame-options: DENY access-control-expose-headers: * access-control-allow-origin: * strict-transport-security: max-age=2592000; includeSubDomains; preload 0050c1e8f715543c3d40150ba757aa91c65671570b19 HEAD symref-target:refs/heads/main 003dc1e8f715543c3d40150ba757aa91c65671570b19 refs/heads/main 0000 

    上面 git clone 失败时的错误字符 005 应该是第二个请求 body 中的内容,但是我比对直接 clone GitHub 源仓库地址 https://github.com/user/repos.git,第二个请求响应的格式均一致,源站能直接 clone 完整,但是为什么通过代理 clone 就会报错呢?

    2 条回复    2023-11-23 15:02:34 +08:00
    pagxir
        1
    pagxir  
       2023-11-23 12:45:56 +08:00 via Android
    用了 chunked 编码,你查查你代理有正确处理 chunk 吗
    iSecret
        2
    iSecret  
    OP
       2023-11-23 15:02:34 +08:00
    @pagxir 感谢提供思路,我查看了下 `Transfer-Encoding: chunked` 似乎是我使用流( stream )方式请求后响应给客户端时自动在 header 头添加的 `Transfer-Encoding: chunked`,感觉看上去没问题,我是用 ghproxy.com 克隆仓库时也是有这个 header 头,也就是说 Git 客户端是支持分片传输的,奇怪。
    关于     帮助文档     自助推广系统     博客     API     FAQ     Solana     2514 人在线   最高记录 6679       Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 24ms UTC 10:40 PVG 18:40 LAX 02:40 JFK 05:40
    Do have faith in what you're doing.
    ubao msn snddm index pchome yahoo rakuten mypaper meadowduck bidyahoo youbao zxmzxm asda bnvcg cvbfg dfscv mmhjk xxddc yybgb zznbn ccubao uaitu acv GXCV ET GDG YH FG BCVB FJFH CBRE CBC GDG ET54 WRWR RWER WREW WRWER RWER SDG EW SF DSFSF fbbs ubao fhd dfg ewr dg df ewwr ewwr et ruyut utut dfg fgd gdfgt etg dfgt dfgd ert4 gd fgg wr 235 wer3 we vsdf sdf gdf ert xcv sdf rwer hfd dfg cvb rwf afb dfh jgh bmn lgh rty gfds cxv xcv xcs vdas fdf fgd cv sdf tert sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf shasha9178 shasha9178 shasha9178 shasha9178 shasha9178 liflif2 liflif2 liflif2 liflif2 liflif2 liblib3 liblib3 liblib3 liblib3 liblib3 zhazha444 zhazha444 zhazha444 zhazha444 zhazha444 dende5 dende denden denden2 denden21 fenfen9 fenf619 fen619 fenfe9 fe619 sdf sdf sdf sdf sdf zhazh90 zhazh0 zhaa50 zha90 zh590 zho zhoz zhozh zhozho zhozho2 lislis lls95 lili95 lils5 liss9 sdf0ty987 sdft876 sdft9876 sdf09876 sd0t9876 sdf0ty98 sdf0976 sdf0ty986 sdf0ty96 sdf0t76 sdf0876 df0ty98 sf0t876 sd0ty76 sdy76 sdf76 sdf0t76 sdf0ty9 sdf0ty98 sdf0ty987 sdf0ty98 sdf6676 sdf876 sd876 sd876 sdf6 sdf6 sdf9876 sdf0t sdf06 sdf0ty9776 sdf0ty9776 sdf0ty76 sdf8876 sdf0t sd6 sdf06 s688876 sd688 sdf86