dpsu84620 2014-03-09 14:36
浏览 20
已采纳

大量下载文件并传递给客户端(代理)

I have a small Martini-based application and am faced with an issue that I can't solve.

I want to add an application feature that would allow the user to get files from a 3rd server with some changes in HTTP headers. Some kind of proxy. The files are quite big (200+Mb each) and I want these files to be "streamed" to the client. By "stream" I mean that file data should start to return to the client right after the first bytes were recieved by the application without keeping the whole file on disk and/or in memory.

Is this possible with Martini and Go?

  • 写回答

1条回答 默认 最新

  • dongnu4254 2014-03-09 15:14
    关注

    Yes, it is possible in general with Go, I'm not that familiar with Martini specifically. The http response from calling the remote file returns a Reader interface, and your request handler has a Writer interface. This means you can read a stream of data, and write a stream of data. Making your responsibility only to manipulate what you want, and "patch" the forwarded stream to the request stream.

    Go even has a ReverseProxy utility built into the standard library:

    http://golang.org/pkg/net/http/httputil/#ReverseProxy

    You can probably mix Martini and the standard http library if you want.

    [EDIT] Reading the martini docs, you can add raw http handlers like the standrad library has, meaning you can indeed do that: https://github.com/codegangsta/martini#service-injection

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 springboot 3.0 实现Security 6.x版本集成
  • ¥15 PHP-8.1 镜像无法用dockerfile里的CMD命令启动 只能进入容器启动,如何解决?(操作系统-ubuntu)
  • ¥15 请帮我解决一下下面六个代码
  • ¥15 关于资源监视工具的e-care有知道的嘛
  • ¥35 MIMO天线稀疏阵列排布问题
  • ¥60 用visual studio编写程序,利用间接平差求解水准网
  • ¥15 Llama如何调用shell或者Python
  • ¥20 谁能帮我挨个解读这个php语言编的代码什么意思?
  • ¥15 win10权限管理,限制普通用户使用删除功能
  • ¥15 minnio内存占用过大,内存没被回收(Windows环境)