![](/img/trans.png)
[英]"File with content-type application/octet-stream is not supported" returned on sending CSV file in Golang
[英]How do I manually proxy application/octet-stream (live video) in Go?
我正在尝试构建一个应用程序,它将充当具有缓存功能的流代理服务器。 问题是,我想在不使用NewSingleHostReverseProxy
情况下手动NewSingleHostReverseProxy
。 手动意味着执行以下步骤:
GET
请求resp.Body
以缓冲并写入连接的客户端问题是 VLC 不播放任何内容。 如果我直接访问流 - VLC 播放它没有问题,但如果我通过 GO 进行 - VLC(以及 Kodi)只是保持缓冲并且永远不会开始播放。
我尝试过但没有奏效的事情:
io.Copy(...)
bufio
阅读器/扫描器并写入连接的客户端。 冲洗也没有帮助。 这就是curl -v <stream_url>
所说的(直接访问流媒体网址):
...
* Mark bundle as not supporting multiuse
< HTTP/1.1 200 Ok
< Server: Myserver
< Cache-Control: no-cache
< Pragma: no-cache
< Content-Type: application/octet-stream
< Access-Control-Allow-Origin: *
< Connection: close
<
Warning: Binary output can mess up your terminal. Use "--output -" to tell
Warning: curl to output it to your terminal anyway, or consider "--output
Warning: <FILE>" to save to a file.
* Failed writing body (0 != 2896)
* Closing connection 0
这就是curl -v <my_app_url>
所说的:
...
* Mark bundle as not supporting multiuse
< HTTP/1.1 200 OK
< Access-Control-Allow-Origin: *
< Cache-Control: no-cache
< Content-Type: application/octet-stream
< Pragma: no-cache
< Server: Myserver
< Date: Sun, 29 Dec 2019 09:13:44 GMT
< Transfer-Encoding: chunked
<
Warning: Binary output can mess up your terminal. Use "--output -" to tell
Warning: curl to output it to your terminal anyway, or consider "--output
Warning: <FILE>" to save to a file.
* Failed writing body (0 != 14480)
* Failed reading the chunked-encoded stream
* Closing connection 0
问题似乎在这里,但我该如何解决呢?
好的:
* Failed writing body (0 != 2896)
* Closing connection 0
坏的:
* Failed writing body (0 != 14480)
* Failed reading the chunked-encoded stream
* Closing connection 0
还添加了一个源代码,例如:
func main() {
http.HandleFunc("/stream", func(w http.ResponseWriter, r *http.Request) {
resp, err := http.Get("http://example.com/stream/videostream")
if err != nil {
panic(err)
}
defer resp.Body.Close()
reader := bufio.NewReader(resp.Body)
buf := make([]byte, 1024)
for {
k, _ := reader.Read(buf)
if k == 0 {
break
}
w.Write(buf)
}
})
log.Fatal(http.ListenAndServe(":8080", nil))
}
我正在构建一个动态M3U播放列表并将.m3u8
放在每个链接上。 所有链接都是未知类型,所以我认为媒体播放器只会查看Content-Type并相应地处理媒体,但实际上他们也会查看 URL 结尾(无论 URL 是否包含.m3u8
)。
如果您将.m3u8
放在链接的.m3u8
,则将该链接的 Content-Type 设置为application/octet-stream
并提供实际的application/octet-stream
流 - 播放器将永远不会开始显示任何视频流。 解决方法-不要追加.m3u8
到URL,如果该URL不m3u8
格式的媒体。 没有m3u8
媒体播放器仍然可以播放视频。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.