golang gin框架中实现"Transfer-Encoding: chunked"方式的分块发送数据到浏览器端
2024-10-16 04:39:08
参考了这篇帖子:
https://golangtc.com/t/570b403eb09ecc66b90002d9
golang web如何发送小包的chunked数据
以下是代码:
r.GET("/test_stream", func(c *gin.Context){
w := c.Writer
header := w.Header()
header.Set("Transfer-Encoding", "chunked")
header.Set("Content-Type", "text/html")
w.WriteHeader(http.StatusOK)
w.Write([]byte(`
<html>
<body>
`))
w.(http.Flusher).Flush()
for i:=0 ;i<10; i++{
w.Write([]byte(fmt.Sprintf(`
<h1>%d</h1>
`,i)))
w.(http.Flusher).Flush()
time.Sleep(time.Duration(1) * time.Second)
}
w.Write([]byte(`
</body>
</html>
`))
w.(http.Flusher).Flush()
})
最新文章
- 【干货分享】流程DEMO-制度发文和干部任免
- web应用程序
- JQuery 筛选器
- 半平面交模板(BZOJ1007)
- Sprint第二个冲刺(第五天)
- 1. redis简介
- AcmeAir安装AI探针--SaaS版
- Memcached 缓存个体,对象,泛型,表
- Redis持久存储-AOF&RDB
- 聊聊RocksDB Compact
- Linux编程 18 安装软件程序(yum工具对软件包安装,删除,更新介绍)
- loadrunner&#160;场景设计-手工场景设计
- String系列-----AbstractStringBuilder
- callback源码分析——callbacks
- python 首次安装 报错
- nginx:在linux上进行nginx的安装
- 企点微服务网关演进之路 IT大咖说 - 大咖干货,不再错过
- openstack neutron中涉及的网络设备
- ida不错的插件记录
- 日记整理---->;2016-11-01
热门文章
- [C# Expression] 之基础概念
- 【LeetCode】1056. Confusing Number 解题报告(C++)
- 【LeetCode】115. Distinct Subsequences 解题报告(Python)
- 【LeetCode】753. Cracking the Safe 解题报告(Python)
- 【LeetCode】414. Third Maximum Number 解题报告(Python & C++)
- 【LeetCode】905. Sort Array By Parity 解题报告(Python)
- hdu-5569matrix(dp)
- codeforce-424C. Magic Formulas(数学)
- SOA 和微服务
- [object_detect]使用MobileNetSSD进行对象检测