dqqn32019 2019-08-19 21:02
浏览 119

文件服务器无法提供超过32 KB的文件

I have a go program running in a docker container. I have set it up so that when you go to localhost:8080 (the port that the program is running on) it serves up the documentation files which were created using swagger-ui. The index.html file shows up, and in that file it imports one css file, one png file, and two javascript files. The png gets imported correctly (it is only 628 bytes); however, the other three files don't get served correctly (they are all a few hundred KB). I believe the problem is that they are too big as if I delete part of the files to get them under 32 KB, they are served correctly. I am not sure how to increase this file limit, though.

I've looked through all of my code and a fair amount of the http package to see where this hard limit might be set, but can't find it anywhere.

Here's the code that creates my fileserver and serves the files


fs := http.FileServer(http.Dir(docRoot)) // docRoot is a config variable
for _, f := range files {
    path := fmt.Sprintf("/%s", f.Name())
    serveFile := func(w http.ResponseWriter, r *http.Request) {
        if r.URL.Path == path || r.URL.Path == "/index.html" && path == "/" {
            fs.ServeHTTP(w, r)
        } else {
            origHandler.ServeHTTP(w, r)
        }
    }
    docHandler.HandleFunc(path, serveFile)
}

I would think that there would be some Handler.SetMaxSize() or maybe ResponseWriter.SetMaxSize() method, but I can't find anything like this in the http package. Does anyone know how to increase this hard limit or where it might be set?

  • 写回答

1条回答 默认 最新

  • doubingling4706 2019-08-21 16:01
    关注

    So I found out the problem and it turned out to have nothing to do with the function itself, just where I was calling it. I was calling it in a function to create a gateway proxy, and was modifying the handler afterwards to add other stuff such as metrics reporting. I just had to make the call to add this stuff the last call of the parent function, and it works now.

    评论

报告相同问题?

悬赏问题

  • ¥15 nginx中的CORS策略应该如何配置
  • ¥30 信号与系统实验:采样定理分析
  • ¥100 我想找人帮我写Python 的股票分析代码,有意请加mathtao
  • ¥20 Vite 打包的 Vue3 组件库,图标无法显示
  • ¥15 php 同步电商平台多个店铺增量订单和订单状态
  • ¥15 关于logstash转发日志时发生的部分内容丢失问题
  • ¥17 pro*C预编译“闪回查询”报错SCN不能识别
  • ¥15 微信会员卡接入微信支付商户号收款
  • ¥15 如何获取烟草零售终端数据
  • ¥15 数学建模招标中位数问题